Merge branch 'MDL-51673-master' of git://github.com/junpataleta/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 19 Oct 2015 05:38:53 +0000 (13:38 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 19 Oct 2015 05:38:53 +0000 (13:38 +0800)
message/lib.php
message/tests/events_test.php

index 09c834f..d384496 100644 (file)
@@ -1038,7 +1038,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);
 
index cd92c44..5a6843d 100644 (file)
@@ -119,6 +119,15 @@ class core_message_events_testcase extends advanced_testcase {
         $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);
@@ -147,6 +156,11 @@ class core_message_events_testcase extends advanced_testcase {
         // 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);
@@ -160,6 +174,19 @@ class core_message_events_testcase extends advanced_testcase {
         $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());
     }
 
     /**