/** * Validate that mappings are applied during the user set update create action */ public function test_mapping_applied_during_userset_update() { global $CFG, $DB; require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php'; require_once $CFG->dirroot . '/local/elisprogram/accesslib.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/userset.class.php'; $this->init_mapping(); $customfieldid = $this->create_custom_field(CONTEXT_ELIS_USERSET); // Clear the cached custom field list. $usersettoclearcustomfieldlist = new userset(); $usersettoclearcustomfieldlist->reset_custom_field_list(); $parentuserset = new userset(array('name' => 'parentusersetname')); $parentuserset->save(); $userset = new userset(array('name' => 'testusersetname')); $userset->save(); // Run the program create action. $record = new stdClass(); $record->customaction = 'update'; $record->customcontext = 'cluster'; $record->customname = 'testusersetname'; $record->customdisplay = 'updatedtestusersetdisplay'; $record->customparent = 'parentusersetname'; $record->customtestfieldshortname = '1'; $this->run_pmentity_import((array) $record); // Validation. $data = array('name' => 'testusersetname', 'display' => 'updatedtestusersetdisplay', 'parent' => $parentuserset->id); $this->assertTrue($DB->record_exists(userset::TABLE, $data)); $instance = \local_elisprogram\context\userset::instance($userset->id); $this->assertTrue($DB->record_exists(field_data_int::TABLE, array('fieldid' => $customfieldid, 'contextid' => $instance->id, 'data' => 1))); }
/** * Create a test userset. * @return userset The test userset. */ public function create_userset(field $field = null) { $usrset = new userset(); $usrset->reset_custom_field_list(); $usrset->name = 'Test User Set For Field' . str_replace('.', '', microtime(true)); $usrset->parent = '0'; if (!empty($field)) { $fieldvar = 'field_' . $field->shortname; $usrset->{$fieldvar} = 'test field data'; } $usrset->save(); return $usrset; }
/** * Validate that the "find_userset_folders" method respect site files * capabilities assigned at the system level * @uses $USER, $DB * @param string $capability The site files capabilility to assign to the test user * @param boolean $createonly The "create only" flag, as needed by the method * @param array $names The expected set of userset names that should be returned * @dataProvider userset_folders_provider */ public function test_find_userset_folders_respects_site_files($capability, $createonly, $names) { if (!class_exists('elispm')) { $this->markTestSkipped('local_elisprogram needed for test'); return false; } $this->resetAfterTest(true); $this->setup_test_data_xml(); global $DB, $USER; require_once(elis::lib('data/customfield.class.php')); require_once(elispm::lib('data/userset.class.php')); require_once(elispm::file('plugins/usetclassify/usersetclassification.class.php')); require_once(elispm::file('accesslib.php')); // Make sure the test user is not mistaken for a site admin or guest set_config('siteadmins', ''); set_config('siteguest', ''); $classification = new usersetclassification(array( 'shortname' => 'testclassification' )); $classification->param_elis_files_shared_folder = 1; $classification->save(); $userset = new userset(array( 'name' => 'testusersetname' )); $userset->save(); $userset->reset_custom_field_list(); $userset->load(); $userset->field__elis_userset_classification = 'testclassification'; $userset->save(); $this->setUser(100); // Assign the "site files" role to the test user $roleid = $this->assign_role_capability($capability); $systemcontext = context_system::instance(); role_assign($roleid, $USER->id, $systemcontext->id); // Assign the "view userset content" role to the test user $usersetcontext = \local_elisprogram\context\userset::instance($userset->id); $roleid = $this->assign_role_capability('repository/elisfiles:viewusersetcontent', 100); role_assign($roleid, $USER->id, $usersetcontext->id); // Obtain the set of userset folders $elisfiles = repository_factory::factory(); $folders = array(); $elisfiles->find_userset_folders($folders, $createonly); // Validate that the method returned the right number of folders $this->assertEquals(count($names), count($folders)); // Validate the specific names foreach ($names as $i => $name) { $this->assertEquals($name, $folders[$i]['name']); } }