Skip to content

Commit

Permalink
Merge branch 'MDL-51673-28' of git://github.com/junpataleta/moodle in…
Browse files Browse the repository at this point in the history
…to MOODLE_28_STABLE
  • Loading branch information
andrewnicols committed Oct 19, 2015
2 parents e1f8a35 + 61ba945 commit 2ed5192
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion message/lib.php
Expand Up @@ -988,7 +988,7 @@ function message_add_contact($contactid, $blocked=0) {
// Check if a record already exists as we may be changing blocking status.
if (($contact = $DB->get_record('message_contacts', array('userid' => $USER->id, 'contactid' => $contactid))) !== false) {
// Check if blocking status has been changed.
if ($contact->blocked !== $blocked) {
if ($contact->blocked != $blocked) {
$contact->blocked = $blocked;
$DB->update_record('message_contacts', $contact);

Expand Down
27 changes: 27 additions & 0 deletions message/tests/events_test.php
Expand Up @@ -119,6 +119,15 @@ public function test_message_contact_blocked() {
$url = new moodle_url('/message/index.php', array('user1' => $event->userid, 'user2' => $event->relateduserid));
$this->assertEquals($url, $event->get_url());

// Make sure that the contact blocked event is not triggered again.
$sink->clear();
message_block_contact($user->id);
$events = $sink->get_events();
$event = reset($events);
$this->assertEmpty($event);
// Make sure that we still have 1 blocked user.
$this->assertEquals(1, message_count_blocked_users());

// Now blocking a user that is not a contact.
$sink->clear();
message_block_contact($user2->id);
Expand Down Expand Up @@ -147,6 +156,11 @@ public function test_message_contact_unblocked() {
// Add the user to the admin's contact list.
message_add_contact($user->id);

// Block the user.
message_block_contact($user->id);
// Make sure that we have 1 blocked user.
$this->assertEquals(1, message_count_blocked_users());

// Trigger and capture the event when unblocking a contact.
$sink = $this->redirectEvents();
message_unblock_contact($user->id);
Expand All @@ -160,6 +174,19 @@ public function test_message_contact_unblocked() {
$this->assertEventLegacyLogData($expected, $event);
$url = new moodle_url('/message/index.php', array('user1' => $event->userid, 'user2' => $event->relateduserid));
$this->assertEquals($url, $event->get_url());

// Make sure that we have no blocked users.
$this->assertEmpty(message_count_blocked_users());

// Make sure that the contact unblocked event is not triggered again.
$sink->clear();
message_unblock_contact($user->id);
$events = $sink->get_events();
$event = reset($events);
$this->assertEmpty($event);

// Make sure that we still have no blocked users.
$this->assertEmpty(message_count_blocked_users());
}

/**
Expand Down

0 comments on commit 2ed5192

Please sign in to comment.