Пример #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));
 }
Пример #2
0
 /**
  * Test that the get_filter_options function does not include the guest roles.
  */
 public function test_get_filter_options_no_guest_roles()
 {
     create_role('Test Role', 'testrole', 'This is a test role', 'guest');
     $allroles = role_get_names(null, ROLENAME_ALIAS);
     $options = \tool_usertours\local\filter\role::get_filter_options();
     foreach ($allroles as $role) {
         $hasrole = isset($options[$role->shortname]);
         if ($role->archetype === 'guest') {
             $this->assertFalse($hasrole);
         } else {
             $this->assertTrue($hasrole);
         }
     }
 }