Merge branch 'MDL-52928-master' of git://github.com/andrewnicols/moodle

This commit is contained in:
Dan Poltawski 2016-03-01 11:34:04 +08:00
commit c116a115d9
2 changed files with 64 additions and 11 deletions

View file

@ -764,7 +764,7 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) {
) messagesubset ON messagesubset.messageid = message.id
JOIN {user} otheruser ON (message.useridfrom = :userid4 AND message.useridto = otheruser.id)
OR (message.useridto = :userid5 AND message.useridfrom = otheruser.id)
LEFT JOIN {message_contacts} contact ON contact.userid = :userid3 AND contact.userid = otheruser.id
LEFT JOIN {message_contacts} contact ON contact.userid = :userid3 AND contact.contactid = otheruser.id
WHERE otheruser.deleted = 0 AND message.notification = 0
ORDER BY message.timecreated DESC";
$params = array(

View file

@ -383,13 +383,14 @@ class core_message_messagelib_testcase extends advanced_testcase {
*/
public function message_get_recent_conversations_provider() {
return array(
array(
// Test that conversations with multiple contacts is correctly ordered.
'Test that conversations with messages contacts is correctly ordered.' => array(
'users' => array(
'user1',
'user2',
'user3',
),
'contacts' => array(
),
'messages' => array(
array(
'from' => 'user1',
@ -465,11 +466,52 @@ class core_message_messagelib_testcase extends advanced_testcase {
),
),
),
array(
// Test conversations with a single user, where some messages are read and some are not.
'Test that users with contacts and messages to self work as expected' => array(
'users' => array(
'user1',
'user2',
'user3',
),
'contacts' => array(
'user1' => array(
'user2' => 0,
'user3' => 0,
),
'user2' => array(
'user3' => 0,
),
),
'messages' => array(
array(
'from' => 'user1',
'to' => 'user1',
'state' => 'unread',
'subject' => 'S1',
),
array(
'from' => 'user1',
'to' => 'user1',
'state' => 'unread',
'subject' => 'S2',
),
),
'expectations' => array(
'user1' => array(
// User1 has conversed most recently with user1. The most recent message is S2.
array(
'messageposition' => 0,
'with' => 'user1',
'subject' => 'S2',
),
),
),
),
'Test conversations with a single user, where some messages are read and some are not.' => array(
'users' => array(
'user1',
'user2',
),
'contacts' => array(
),
'messages' => array(
array(
@ -518,15 +560,16 @@ class core_message_messagelib_testcase extends advanced_testcase {
),
),
),
array(
// Test conversations with a single user, where some messages are read and some are not, and messages
// are out of order.
'Test conversations with a single user, where some messages are read and some are not, and messages ' .
'are out of order' => array(
// This can happen through a combination of factors including multi-master DB replication with messages
// read somehow (e.g. API).
'users' => array(
'user1',
'user2',
),
'contacts' => array(
),
'messages' => array(
array(
'from' => 'user1',
@ -584,7 +627,7 @@ class core_message_messagelib_testcase extends advanced_testcase {
* @param array $messagesdata The list of messages to create.
* @param array $expectations The list of expected outcomes.
*/
public function test_message_get_recent_conversations($usersdata, $messagesdata, $expectations) {
public function test_message_get_recent_conversations($usersdata, $contacts, $messagesdata, $expectations) {
global $DB;
// Create all of the users.
@ -593,6 +636,16 @@ class core_message_messagelib_testcase extends advanced_testcase {
$users[$username] = $this->getDataGenerator()->create_user(array('username' => $username));
}
foreach ($contacts as $username => $contact) {
foreach ($contact as $contactname => $blocked) {
$record = new stdClass();
$record->userid = $users[$username]->id;
$record->contactid = $users[$contactname]->id;
$record->blocked = $blocked;
$record->id = $DB->insert_record('message_contacts', $record);
}
}
$defaulttimecreated = time();
foreach ($messagesdata as $messagedata) {
$from = $users[$messagedata['from']];