Exemplo n.º 1
0
 /**
  * Tests the filter_users function.
  */
 public function test_filter_users()
 {
     $info = new \core_availability\mock_info();
     $checker = new capability_checker($info->get_context());
     // Don't need to create real users in database, just use these ids.
     $users = array(1 => null, 2 => null, 3 => null);
     // Test basic tree with one condition that doesn't filter.
     $structure = tree::get_root_json(array(self::mock(array())));
     $tree = new tree($structure);
     $result = $tree->filter_user_list($users, false, $info, $checker);
     ksort($result);
     $this->assertEquals(array(1, 2, 3), array_keys($result));
     // Now a tree with one condition that filters.
     $structure = tree::get_root_json(array(self::mock(array('filter' => array(2, 3)))));
     $tree = new tree($structure);
     $result = $tree->filter_user_list($users, false, $info, $checker);
     ksort($result);
     $this->assertEquals(array(2, 3), array_keys($result));
     // Tree with two conditions that both filter (|).
     $structure = tree::get_root_json(array(self::mock(array('filter' => array(3))), self::mock(array('filter' => array(1)))), tree::OP_OR);
     $tree = new tree($structure);
     $result = $tree->filter_user_list($users, false, $info, $checker);
     ksort($result);
     $this->assertEquals(array(1, 3), array_keys($result));
     // Tree with two condition that both filter (&).
     $structure = tree::get_root_json(array(self::mock(array('filter' => array(2, 3))), self::mock(array('filter' => array(1, 2)))));
     $tree = new tree($structure);
     $result = $tree->filter_user_list($users, false, $info, $checker);
     ksort($result);
     $this->assertEquals(array(2), array_keys($result));
     // Tree with child tree with NOT condition.
     $structure = tree::get_root_json(array(tree::get_nested_json(array(self::mock(array('filter' => array(1)))), tree::OP_NOT_AND)));
     $tree = new tree($structure);
     $result = $tree->filter_user_list($users, false, $info, $checker);
     ksort($result);
     $this->assertEquals(array(2, 3), array_keys($result));
 }