/** * Install function for this plugin * * @return boolean true Returns true to satisfy install procedure */ function xmldb_elisprogram_usetclassify_install() { global $CFG, $DB; require_once elispm::lib('setup.php'); require_once elis::lib('data/customfield.class.php'); require_once elispm::file('plugins/usetclassify/usersetclassification.class.php'); // Migrate component. $oldcmp = 'pmplugins_userset_classification'; $newcmp = 'elisprogram_usetclassify'; $upgradestepfuncname = 'elisprogram_usetclassify_pre26upgradesteps'; $tablechanges = array('crlm_cluster_classification' => 'elisprogram_usetclassify'); $migrator = new \local_eliscore\install\migration\migrator($oldcmp, $newcmp, $upgradestepfuncname, $tablechanges); if ($migrator->old_component_installed() === true) { $migrator->migrate(); } $field = new field(); $field->shortname = USERSET_CLASSIFICATION_FIELD; $field->name = get_string('classification_field_name', 'elisprogram_usetclassify'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('classification_category_name', 'elisprogram_usetclassify'); $field = field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USERSET, $category); // make sure we're set as owner if (!isset($field->owners['userset_classifications'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'userset_classifications'; $owner->save(); } // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = 'moodle/user:update'; $owner->param_control = 'menu'; $owner->param_options_source = 'userset_classifications'; $owner->param_help_file = 'elisprogram_usetclassify/cluster_classification'; $owner->save(); } // make sure we have a default value set if (!field_data::get_for_context_and_field(NULL, $field)) { field_data::set_for_context_and_field(NULL, $field, 'regular'); } $regclassify = $DB->get_record(usersetclassification::TABLE, array('shortname' => 'regular')); if (empty($regclassify)) { $default = new usersetclassification(); $default->shortname = 'regular'; $default->name = get_string('cluster', 'local_elisprogram'); $default->param_autoenrol_curricula = 1; $default->param_autoenrol_tracks = 1; $default->save(); } return true; }
/** * 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']); } }