Example #1
0
 /**
  * Test the filter_matches function when one user has multiple roles.
  */
 public function test_filter_matches_multiple_role_one_user()
 {
     $context = \context_course::instance($this->course->id);
     $roles = [$this->roles['student']];
     $this->getDataGenerator()->enrol_user($this->student->id, $this->course->id, $this->roles['teacher']);
     // Note: No need to persist this tour.
     $tour = new \tool_usertours\tour();
     $tour->set_filter_values('role', $roles);
     // Note: The role filter does not use the context.
     foreach ($this->testroles as $role) {
         $this->setUser($this->{$role});
         if ($role === 'student') {
             $this->assertTrue(\tool_usertours\local\filter\role::filter_matches($tour, $context));
         } else {
             $this->assertFalse(\tool_usertours\local\filter\role::filter_matches($tour, $context));
         }
     }
     // The admin should always be able to view too.
     $this->setAdminUser();
     $this->assertTrue(\tool_usertours\local\filter\role::filter_matches($tour, $context));
 }
Example #2
0
 /**
  * Test the filter_matches function when an admin user has multiple roles.
  */
 public function test_filter_matches_multiple_role_admin_user()
 {
     global $USER;
     $context = \context_course::instance($this->course->id);
     $roles = [\tool_usertours\local\filter\role::ROLE_SITEADMIN];
     $this->setAdminUser();
     $this->getDataGenerator()->enrol_user($USER->id, $this->course->id, $this->roles['student']);
     // Note: No need to persist this tour.
     $tour = new \tool_usertours\tour();
     $tour->set_filter_values('role', $roles);
     // The admin can view this one because it's only aimed at them.
     $this->assertTrue(\tool_usertours\local\filter\role::filter_matches($tour, $context));
 }