/** * Checks if the recipient is allowing messages from users that aren't a * contact. If not then it checks to make sure the sender is in the * recipient's contacts. * * @deprecated since Moodle 3.2 * @param object $recipient User object. * @param object $sender User object. * @return bool true if $sender is blocked, false otherwise. */ function message_is_user_non_contact_blocked($recipient, $sender = null) { debugging('message_is_user_non_contact_blocked() is deprecated and is no longer used, please use \\core_message\\api::is_user_non_contact_blocked() instead.', DEBUG_DEVELOPER); return \core_message\api::is_user_non_contact_blocked($recipient, $sender); }
/** * Tests that when blocking messages from non-contacts is enabled that * non-contacts trying to send a message return false. */ public function test_is_user_non_contact_blocked() { // Create some users. $user1 = self::getDataGenerator()->create_user(); $user2 = self::getDataGenerator()->create_user(); // Set as the first user. $this->setUser($user1); // User hasn't sent their preference to block non-contacts, so should return false. $this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2)); // Set the second user's preference to not receive messages from non-contacts. set_user_preference('message_blocknoncontacts', 1, $user2->id); // Check that the return result is now true. $this->assertTrue(\core_message\api::is_user_non_contact_blocked($user2)); // Add the first user as a contact for the second user. message_add_contact($user1->id, 0, $user2->id); // Check that the return result is now false. $this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2)); }