MDL-63097 phpunit: decouple user lastping and session start in tests
Previously the test was assuming that the user last ping, when accessing to a chat should match the first (enter) system message sent to the chat. And that's ok 99% of times but, if seconds advance between the creation of the chat_users record and the chat_messages one, then they don't match. So now, the assumption is not used anymore and the expectation is the timestamp of that first (enter) system message, explicitly.
This commit is contained in:
@@ -169,8 +169,14 @@ class mod_chat_lib_testcase extends advanced_testcase {
|
||||
$chatsid = chat_login_user($chat->id, 'ajax', 0, $course);
|
||||
$chatuser = $DB->get_record('chat_users', ['sid' => $chatsid]);
|
||||
|
||||
// This is when the session starts (when the user enters the chat).
|
||||
$sessionstart = $chatuser->lastping;
|
||||
// Get the messages for this chat session.
|
||||
$messages = chat_get_session_messages($chat->id, false, 0, 0, 'timestamp DESC');
|
||||
|
||||
// We should have just 1 system (enter) messages.
|
||||
$this->assertCount(1, $messages);
|
||||
|
||||
// This is when the session starts (when the first message - enter - has been sent).
|
||||
$sessionstart = reset($messages)->timestamp;
|
||||
|
||||
// Send some messages.
|
||||
chat_send_chatmessage($chatuser, 'hello!');
|
||||
|
||||
Reference in New Issue
Block a user