Merge branch 'MDL-57967_master' of git://github.com/markn86/moodle
This commit is contained in:
@@ -417,7 +417,8 @@ class api {
|
||||
$userfields = \user_picture::fields('', array('lastaccess'));
|
||||
$userssql = "SELECT $userfields
|
||||
FROM {user}
|
||||
WHERE id $useridsql";
|
||||
WHERE id $useridsql
|
||||
AND deleted = 0";
|
||||
$otherusers = $DB->get_records_sql($userssql, $usersparams);
|
||||
|
||||
// Similar to the above use case, we need to pull the contact information and again this has
|
||||
@@ -478,6 +479,11 @@ class api {
|
||||
$conversation->$prop = ($otheruser) ? $otheruser->$prop : null;
|
||||
}
|
||||
|
||||
// Do not process a conversation with a deleted user.
|
||||
if (empty($conversation->id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add the contact's information, if we have one.
|
||||
$conversation->blocked = ($contact) ? $contact->blocked : null;
|
||||
|
||||
|
||||
@@ -462,6 +462,41 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
$this->assertCount(0, $conversations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests retrieving conversations when a conversation contains a deleted user.
|
||||
*/
|
||||
public function test_get_conversations_with_deleted_user() {
|
||||
// Create some users.
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
$user3 = self::getDataGenerator()->create_user();
|
||||
|
||||
// Send some messages back and forth, have some different conversations with different users.
|
||||
$time = 1;
|
||||
$this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
|
||||
$this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
|
||||
$this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
|
||||
$this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
|
||||
|
||||
$this->send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
|
||||
$this->send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
|
||||
$this->send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
|
||||
$this->send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
|
||||
|
||||
// Delete the second user.
|
||||
delete_user($user2);
|
||||
|
||||
// Retrieve the conversations.
|
||||
$conversations = \core_message\api::get_conversations($user1->id);
|
||||
|
||||
// We should only have one conversation because the other user was deleted.
|
||||
$this->assertCount(1, $conversations);
|
||||
|
||||
// Confirm the conversation is from the non-deleted user.
|
||||
$conversation = reset($conversations);
|
||||
$this->assertEquals($user3->id, $conversation->userid);
|
||||
}
|
||||
|
||||
/**
|
||||
* The data provider for get_conversations_mixed.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user