/**
  * Test message_unblock_contact.
  */
 public function test_message_unblock_contact()
 {
     // Set this user as the admin.
     $this->setAdminUser();
     // Create a user to add to the admin's contact list.
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     // Add users to the admin's contact list.
     message_add_contact($user1->id);
     message_add_contact($user2->id, 1);
     // Add blocked contact.
     $this->assertEquals(1, message_count_blocked_users());
     // Unblock user.
     message_unblock_contact($user2->id);
     $this->assertEquals(0, message_count_blocked_users());
 }
示例#2
0
 /**
  * Test the message contact unblocked event.
  */
 public function test_message_contact_unblocked()
 {
     // Set this user as the admin.
     $this->setAdminUser();
     // Create a user to add to the admin's contact list.
     $user = $this->getDataGenerator()->create_user();
     // 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);
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\message_contact_unblocked', $event);
     $this->assertEquals(context_user::instance(2), $event->get_context());
     $expected = array(SITEID, 'message', 'unblock contact', 'index.php?user1=' . $user->id . '&user2=2', $user->id);
     $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());
 }