Skip to content

Commit

Permalink
MDL-64047 core_message: test get_contact_requests() with blocked users
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Nov 27, 2018
1 parent e492a55 commit e4088b7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions message/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4729,6 +4729,24 @@ public function test_get_contact_requests() {
$this->assertObjectHasAttribute('iscontact', $request);
}

/**
* Test the get_contact_requests() function when the user has blocked the sender of the request.
*/
public function test_get_contact_requests_blocked_sender() {
$user1 = self::getDataGenerator()->create_user();
$user2 = self::getDataGenerator()->create_user();

// User1 blocks User2.
\core_message\api::block_user($user1->id, $user2->id);

// User2 tries to add User1 as a contact.
\core_message\api::create_contact_request($user2->id, $user1->id);

// Verify we don't see the contact request from the blocked user User2 in the requests for User1.
$requests = \core_message\api::get_contact_requests($user1->id);
$this->assertEmpty($requests);
}

/**
* Test getting contact requests when there are none.
*/
Expand Down
22 changes: 22 additions & 0 deletions message/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,28 @@ public function test_get_contact_requests() {
$this->assertArrayHasKey('iscontact', $request);
}

/**
* Test the get_contact_requests() function when the user has blocked the sender of the request.
*/
public function test_get_contact_requests_blocked_sender() {
$this->resetAfterTest();
$user1 = self::getDataGenerator()->create_user();
$user2 = self::getDataGenerator()->create_user();

// User1 blocks User2.
\core_message\api::block_user($user1->id, $user2->id);

// User2 tries to add User1 as a contact.
\core_message\api::create_contact_request($user2->id, $user1->id);

// Verify we don't see the contact request from the blocked user User2 in the requests for User1.
$this->setUser($user1);
$requests = core_message_external::get_contact_requests($user1->id);
$requests = external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);

$this->assertCount(0, $requests);
}

/**
* Test getting contact requests when there are none.
*/
Expand Down

0 comments on commit e4088b7

Please sign in to comment.