/** * Tests searching users in course as another user. */ public function test_messagearea_search_users_in_course_as_other_user() { $this->resetAfterTest(true); // The person doing the search for another user. $this->setAdminUser(); // Create some users. $user1 = new stdClass(); $user1->firstname = 'User'; $user1->lastname = 'One'; $user1 = self::getDataGenerator()->create_user($user1); $user2 = new stdClass(); $user2->firstname = 'User'; $user2->lastname = 'Two'; $user2 = self::getDataGenerator()->create_user($user2); $user3 = new stdClass(); $user3->firstname = 'User'; $user3->lastname = 'Three'; $user3 = self::getDataGenerator()->create_user($user3); // Create a course. $course1 = new stdClass(); $course1->fullname = 'Course'; $course1->shortname = 'One'; $course1 = $this->getDataGenerator()->create_course(); // Enrol the user we are doing the search for and one user in the course. $this->getDataGenerator()->enrol_user($user1->id, $course1->id); $this->getDataGenerator()->enrol_user($user2->id, $course1->id); // Perform a search. $result = core_message_external::data_for_messagearea_search_users_in_course($user1->id, $course1->id, 'User'); // We need to execute the return values cleaning process to simulate the web service server. $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_in_course_returns(), $result); // Check that we got the user enrolled, and that the user we are performing the search on behalf of was not returned. $users = $result['contacts']; $this->assertCount(1, $users); $user = $users[0]; $this->assertEquals($user2->id, $user['userid']); $this->assertEquals(fullname($user2), $user['fullname']); $this->assertFalse($user['ismessaging']); $this->assertFalse($user['sentfromcurrentuser']); $this->assertNull($user['lastmessage']); $this->assertNull($user['messageid']); $this->assertFalse($user['isonline']); $this->assertFalse($user['isread']); $this->assertFalse($user['isblocked']); $this->assertNull($user['unreadcount']); }