MDL-63168 core_message: added unit test

This commit is contained in:
Mark Nelson 2019-01-23 12:58:35 +08:00
parent 7ef5409b1b
commit 05aa320bd2

View File

@ -324,6 +324,37 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
$this->assertEquals(FORMAT_MOODLE, $notification->fullmessageformat);
}
/**
* Test migrating a legacy message that a user sent to themselves then deleted.
*/
public function test_migrating_message_deleted_message_sent_to_self() {
global $DB;
// Create user to test with.
$user1 = $this->getDataGenerator()->create_user();
$m1 = $this->create_legacy_message_or_notification($user1->id, $user1->id, null, false, null, null);
// Let's delete the message for the 'user to' and 'user from' which in this case is the same user.
$messageupdate = new stdClass();
$messageupdate->id = $m1;
$messageupdate->timeuserfromdeleted = time();
$messageupdate->timeusertodeleted = time();
$DB->update_record('message', $messageupdate);
// Now, let's execute the task for the user.
$task = new \core_message\task\migrate_message_data();
$task->set_custom_data(
[
'userid' => $user1->id
]
);
$task->execute();
$this->assertEquals(0, $DB->count_records('message'));
$this->assertEquals(1, $DB->count_records('message_user_actions'));
}
/**
* Creates a legacy message or notification to be used for testing.
*