MDL-58953 user: additional test case for user_can_view_profile()
authorJake Dallimore <jake@moodle.com>
Tue, 29 Aug 2017 02:39:11 +0000 (10:39 +0800)
committerDavid Monllao <davidm@moodle.com>
Thu, 7 Sep 2017 08:53:34 +0000 (10:53 +0200)
user/tests/userlib_test.php

index dc4b69d..a5a6862 100644 (file)
@@ -531,6 +531,11 @@ class core_userliblib_testcase extends advanced_testcase {
         $this->getDataGenerator()->enrol_user($user4->id, $course3->id);
         $this->getDataGenerator()->enrol_user($user5->id, $course3->id);
 
+        // User 3 should not be able to see user 1, either by passing their own course (course 2) or user 1's course (course 1).
+        $this->setUser($user3);
+        $this->assertFalse(user_can_view_profile($user1, $course2));
+        $this->assertFalse(user_can_view_profile($user1, $course1));
+
         // Remove capability moodle/user:viewdetails in course 2.
         assign_capability('moodle/user:viewdetails', CAP_PROHIBIT, $studentrole->id, $coursecontext);
         $coursecontext->mark_dirty();