MDL-69411 core_message: Fix return structure for empty result set
Passing a timefrom higher than last message timecreated needs to return a formatted response so it does not break ws.
This commit is contained in:
@@ -7249,6 +7249,47 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
$this->assertNotEquals($mid1, $convmessages2['messages'][0]->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test retrieving conversation messages by providing a timefrom higher than last message timecreated. It should return no
|
||||
* messages but keep the return structure to not break when called from the ws.
|
||||
*/
|
||||
public function test_get_conversation_messages_timefrom_higher_than_last_timecreated() {
|
||||
// Create some users.
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
$user3 = self::getDataGenerator()->create_user();
|
||||
$user4 = self::getDataGenerator()->create_user();
|
||||
|
||||
// Create group conversation.
|
||||
$conversation = \core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
|
||||
[$user1->id, $user2->id, $user3->id, $user4->id]
|
||||
);
|
||||
|
||||
// The person doing the search.
|
||||
$this->setUser($user1);
|
||||
|
||||
// Send some messages back and forth.
|
||||
$time = 1;
|
||||
testhelper::send_fake_message_to_conversation($user1, $conversation->id, 'Message 1', $time + 1);
|
||||
testhelper::send_fake_message_to_conversation($user2, $conversation->id, 'Message 2', $time + 2);
|
||||
testhelper::send_fake_message_to_conversation($user1, $conversation->id, 'Message 3', $time + 3);
|
||||
testhelper::send_fake_message_to_conversation($user3, $conversation->id, 'Message 4', $time + 4);
|
||||
|
||||
// Retrieve the messages from $time + 5, which should return no messages.
|
||||
$convmessages = \core_message\api::get_conversation_messages($user1->id, $conversation->id, 0, 0, '', $time + 5);
|
||||
|
||||
// Confirm the conversation id is correct.
|
||||
$this->assertEquals($conversation->id, $convmessages['id']);
|
||||
|
||||
// Confirm the message data is correct.
|
||||
$messages = $convmessages['messages'];
|
||||
$this->assertEquals(0, count($messages));
|
||||
|
||||
// Confirm that members key is present.
|
||||
$this->assertArrayHasKey('members', $convmessages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to seed the database with initial state with data.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user