Skip to content

Commit

Permalink
MDL-36941 core_message: removed unit test that will always fail
Browse files Browse the repository at this point in the history
We are changing how the API behaves so the old tables will never
be populated. This unit test is testing a deprecated function
which we will not be refactoring to use the new table structure.
  • Loading branch information
mdjnelson committed Mar 23, 2018
1 parent a63f982 commit ee14412
Showing 1 changed file with 0 additions and 312 deletions.
312 changes: 0 additions & 312 deletions message/tests/messagelib_test.php
Expand Up @@ -355,316 +355,4 @@ public function test_message_search_users() {
$this->assertCount(1, message_search_users(0, 'user1'));
$this->assertCount(2, message_search_users(0, 'user'));
}

/**
* The data provider for message_get_recent_conversations.
*
* This provides sets of data to for testing.
* @return array
*/
public function message_get_recent_conversations_provider() {
return array(
'Test that conversations with messages contacts is correctly ordered.' => array(
'users' => array(
'user1',
'user2',
'user3',
),
'contacts' => array(
),
'messages' => array(
array(
'from' => 'user1',
'to' => 'user2',
'state' => 'unread',
'subject' => 'S1',
),
array(
'from' => 'user2',
'to' => 'user1',
'state' => 'unread',
'subject' => 'S2',
),
array(
'from' => 'user1',
'to' => 'user2',
'state' => 'unread',
'timecreated' => 0,
'subject' => 'S3',
),
array(
'from' => 'user1',
'to' => 'user3',
'state' => 'read',
'timemodifier' => 1,
'subject' => 'S4',
),
array(
'from' => 'user3',
'to' => 'user1',
'state' => 'read',
'timemodifier' => 1,
'subject' => 'S5',
),
array(
'from' => 'user1',
'to' => 'user3',
'state' => 'read',
'timecreated' => 0,
'subject' => 'S6',
),
),
'expectations' => array(
'user1' => array(
// User1 has conversed most recently with user3. The most recent message is M5.
array(
'messageposition' => 0,
'with' => 'user3',
'subject' => 'S5',
),
// User1 has also conversed with user2. The most recent message is S2.
array(
'messageposition' => 1,
'with' => 'user2',
'subject' => 'S2',
),
),
'user2' => array(
// User2 has only conversed with user1. Their most recent shared message was S2.
array(
'messageposition' => 0,
'with' => 'user1',
'subject' => 'S2',
),
),
'user3' => array(
// User3 has only conversed with user1. Their most recent shared message was S5.
array(
'messageposition' => 0,
'with' => 'user1',
'subject' => 'S5',
),
),
),
),
'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(
'from' => 'user1',
'to' => 'user2',
'state' => 'read',
'subject' => 'S1',
),
array(
'from' => 'user2',
'to' => 'user1',
'state' => 'read',
'subject' => 'S2',
),
array(
'from' => 'user1',
'to' => 'user2',
'state' => 'unread',
'timemodifier' => 1,
'subject' => 'S3',
),
array(
'from' => 'user1',
'to' => 'user2',
'state' => 'unread',
'timemodifier' => 1,
'subject' => 'S4',
),
),
'expectations' => array(
// The most recent message between user1 and user2 was S4.
'user1' => array(
array(
'messageposition' => 0,
'with' => 'user2',
'subject' => 'S4',
),
),
'user2' => array(
// The most recent message between user1 and user2 was S4.
array(
'messageposition' => 0,
'with' => 'user1',
'subject' => 'S4',
),
),
),
),
'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',
'to' => 'user2',
'state' => 'read',
'subject' => 'S1',
'timemodifier' => 1,
),
array(
'from' => 'user2',
'to' => 'user1',
'state' => 'read',
'subject' => 'S2',
'timemodifier' => 2,
),
array(
'from' => 'user1',
'to' => 'user2',
'state' => 'unread',
'subject' => 'S3',
),
array(
'from' => 'user1',
'to' => 'user2',
'state' => 'unread',
'subject' => 'S4',
),
),
'expectations' => array(
// The most recent message between user1 and user2 was S2, even though later IDs have not been read.
'user1' => array(
array(
'messageposition' => 0,
'with' => 'user2',
'subject' => 'S2',
),
),
'user2' => array(
array(
'messageposition' => 0,
'with' => 'user1',
'subject' => 'S2',
),
),
),
),
);
}

/**
* Test message_get_recent_conversations with a mixture of messages.
*
* @dataProvider message_get_recent_conversations_provider
* @param array $usersdata The list of users to create for this test.
* @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, $contacts, $messagesdata, $expectations) {
global $DB;

// Create all of the users.
$users = array();
foreach ($usersdata as $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();
foreach ($messagesdata as $messagedata) {
$from = $users[$messagedata['from']];
$to = $users[$messagedata['to']];
$subject = $messagedata['subject'];

if (isset($messagedata['state']) && $messagedata['state'] == 'unread') {
$table = 'message';
$messageid = $this->send_fake_message($from, $to, $subject);
} else {
// If there is no state, or the state is not 'unread', assume the message is read.
$table = 'message_read';
$messageid = message_post_message($from, $to, $subject, FORMAT_PLAIN);
}

$updatemessage = new stdClass();
$updatemessage->id = $messageid;
if (isset($messagedata['timecreated'])) {
$updatemessage->timecreated = $messagedata['timecreated'];
} else if (isset($messagedata['timemodifier'])) {
$updatemessage->timecreated = $defaulttimecreated + $messagedata['timemodifier'];
} else {
$updatemessage->timecreated = $defaulttimecreated;
}
$DB->update_record($table, $updatemessage);
}

foreach ($expectations as $username => $data) {
// Get the recent conversations for the specified user.
$user = $users[$username];
$conversations = message_get_recent_conversations($user);
$this->assertDebuggingCalled();
foreach ($data as $expectation) {
$otheruser = $users[$expectation['with']];
$conversation = $conversations[$expectation['messageposition']];
$this->assertEquals($otheruser->id, $conversation->id);
$this->assertEquals($expectation['subject'], $conversation->smallmessage);
}
}
}
}

0 comments on commit ee14412

Please sign in to comment.