/**
  * Test perms.
  * @dataProvider dataprovider_available_table_obeys_perms
  * @param array $associations An array of arrays of parameters to construct student associations.
  * @param int $tableclassid The ID of the class we're managing.
  * @param array $expectedresults The expected page of results.
  */
 public function test_available_table_obeys_perms($perms, $classtracks, $trackclusters, $userclusters, $tableclassid, $expectedresults)
 {
     global $USER, $DB, $CFG;
     $userbackup = $USER;
     // Set up permissions.
     $USER = $this->setup_permissions_test();
     // Set up permissions.
     foreach ($perms as $perm => $contexts) {
         foreach ($contexts as $level => $ids) {
             if ($level === 'system') {
                 $this->give_permission_for_context($USER->id, $perm, context_system::instance());
             } else {
                 foreach ($ids as $id) {
                     $ctxclass = '\\local_elisprogram\\context\\' . $level;
                     $ctx = $ctxclass::instance($id);
                     $this->give_permission_for_context($USER->id, $perm, $ctx);
                 }
             }
         }
     }
     pmclasspage::$contexts = array();
     accesslib_clear_all_caches(true);
     // Create associations.
     $assocarrays = array('classtracks' => 'trackassignment', 'trackclusters' => 'clustertrack', 'userclusters' => 'clusterassignment');
     foreach ($assocarrays as $arrayname => $assocclass) {
         foreach (${$arrayname} as $association) {
             $association = new $assocclass($association);
             $association->save();
         }
     }
     $table = new deepsight_datatable_instructor_available_mock($DB, 'test', 'http://localhost', 'testuniqid');
     $table->set_classid($tableclassid);
     $actualresults = $table->get_search_results(array(), array(), 0, 20);
     $this->assert_search_results($expectedresults, count($expectedresults), $actualresults);
     // Restore user.
     $USER = $userbackup;
 }