Merge branch 'MDL-63884-master-fix' of https://github.com/snake/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2018-11-09 11:19:02 +01:00
3 changed files with 27 additions and 2 deletions
+4 -1
View File
@@ -450,7 +450,10 @@ class api {
$extrafields[$convid]['subname'] = format_string($courseinfo[$groupid]->courseshortname);
// Imageurl.
$extrafields[$convid]['imageurl'] = get_group_picture_url($group, $group->courseid, true)->out(false);
$extrafields[$convid]['imageurl'] = '';
if ($url = get_group_picture_url($group, $group->courseid, true)) {
$extrafields[$convid]['imageurl'] = $url->out(false);
}
}
}
}
+4
View File
@@ -540,6 +540,10 @@ class helper {
// Transform new data format back into the old format, just for BC during the deprecation life cycle.
$tmp = [];
foreach ($conversations as $id => $conv) {
// Only individual conversations were supported in legacy messaging.
if ($conv->type != \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
continue;
}
$data = new \stdClass();
// The logic for the 'other user' is as follows:
// If a conversation is of type 'individual', the other user is always the member who is not the current user.
+19 -1
View File
@@ -1335,7 +1335,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
$course1 = $this->getDataGenerator()->create_course();
// Create a group with a linked conversation.
// Create a group with a linked conversation and a valid image.
$this->setAdminUser();
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);
@@ -1350,11 +1350,29 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user2->id));
// Verify the group with the image works as expected.
$conversations = \core_message\api::get_conversations($user1->id);
$this->assertEquals(2, $conversations[0]->membercount);
$this->assertEquals($course1->shortname, $conversations[0]->subname);
$groupimageurl = get_group_picture_url($group1, $group1->courseid, true);
$this->assertEquals($groupimageurl, $conversations[0]->imageurl);
// Create a group with a linked conversation and without any image.
$group2 = $this->getDataGenerator()->create_group([
'courseid' => $course1->id,
'enablemessaging' => 1,
]);
// Add users to group2.
$this->getDataGenerator()->create_group_member(array('groupid' => $group2->id, 'userid' => $user2->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group2->id, 'userid' => $user3->id));
// Verify the group without any image works as expected too.
$conversations = \core_message\api::get_conversations($user3->id);
$this->assertEquals(2, $conversations[0]->membercount);
$this->assertEquals($course1->shortname, $conversations[0]->subname);
$groupimageurl = get_group_picture_url($group2, $group2->courseid, true);
$this->assertEquals($groupimageurl, $conversations[0]->imageurl);
}
/**