From 6ed9356daf3afa1a2dfcd36a07913da01e6eb0d1 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Fri, 10 Aug 2018 02:20:10 +0200 Subject: [PATCH] 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. --- mod/chat/tests/lib_test.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mod/chat/tests/lib_test.php b/mod/chat/tests/lib_test.php index b233af18aa8..fda8b4a5de1 100644 --- a/mod/chat/tests/lib_test.php +++ b/mod/chat/tests/lib_test.php @@ -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!');