mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-52928-master' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
c116a115d9
2 changed files with 64 additions and 11 deletions
|
@ -764,7 +764,7 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) {
|
||||||
) messagesubset ON messagesubset.messageid = message.id
|
) messagesubset ON messagesubset.messageid = message.id
|
||||||
JOIN {user} otheruser ON (message.useridfrom = :userid4 AND message.useridto = otheruser.id)
|
JOIN {user} otheruser ON (message.useridfrom = :userid4 AND message.useridto = otheruser.id)
|
||||||
OR (message.useridto = :userid5 AND message.useridfrom = 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
|
WHERE otheruser.deleted = 0 AND message.notification = 0
|
||||||
ORDER BY message.timecreated DESC";
|
ORDER BY message.timecreated DESC";
|
||||||
$params = array(
|
$params = array(
|
||||||
|
|
|
@ -383,13 +383,14 @@ class core_message_messagelib_testcase extends advanced_testcase {
|
||||||
*/
|
*/
|
||||||
public function message_get_recent_conversations_provider() {
|
public function message_get_recent_conversations_provider() {
|
||||||
return array(
|
return array(
|
||||||
array(
|
'Test that conversations with messages contacts is correctly ordered.' => array(
|
||||||
// Test that conversations with multiple contacts is correctly ordered.
|
|
||||||
'users' => array(
|
'users' => array(
|
||||||
'user1',
|
'user1',
|
||||||
'user2',
|
'user2',
|
||||||
'user3',
|
'user3',
|
||||||
),
|
),
|
||||||
|
'contacts' => array(
|
||||||
|
),
|
||||||
'messages' => array(
|
'messages' => array(
|
||||||
array(
|
array(
|
||||||
'from' => 'user1',
|
'from' => 'user1',
|
||||||
|
@ -465,11 +466,52 @@ class core_message_messagelib_testcase extends advanced_testcase {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
array(
|
'Test that users with contacts and messages to self work as expected' => array(
|
||||||
// Test conversations with a single user, where some messages are read and some are not.
|
|
||||||
'users' => array(
|
'users' => array(
|
||||||
'user1',
|
'user1',
|
||||||
'user2',
|
'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(
|
'messages' => array(
|
||||||
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 ' .
|
||||||
// Test conversations with a single user, where some messages are read and some are not, and messages
|
'are out of order' => array(
|
||||||
// are out of order.
|
// This can happen through a combination of factors including multi-master DB replication with messages
|
||||||
// This can happen through a combination of factors including multi-master DB replication with messages
|
// read somehow (e.g. API).
|
||||||
// read somehow (e.g. API).
|
|
||||||
'users' => array(
|
'users' => array(
|
||||||
'user1',
|
'user1',
|
||||||
'user2',
|
'user2',
|
||||||
),
|
),
|
||||||
|
'contacts' => array(
|
||||||
|
),
|
||||||
'messages' => array(
|
'messages' => array(
|
||||||
array(
|
array(
|
||||||
'from' => 'user1',
|
'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 $messagesdata The list of messages to create.
|
||||||
* @param array $expectations The list of expected outcomes.
|
* @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;
|
global $DB;
|
||||||
|
|
||||||
// Create all of the users.
|
// 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));
|
$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();
|
$defaulttimecreated = time();
|
||||||
foreach ($messagesdata as $messagedata) {
|
foreach ($messagesdata as $messagedata) {
|
||||||
$from = $users[$messagedata['from']];
|
$from = $users[$messagedata['from']];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue