예제 #1
0
    /**
     * Validate that the given user name is converted to the provided user id.
     * @dataProvider folder_to_userid_provider
     * @param string $foldername The name of the ELIS Files folder
     * @param mixed $expecteduserid The userid the method should return (or false if no valid user exists)
     * @param string $adminusername The config value to use for the admin username setting
     */
    public function test_method_returns_correct_userid($foldername, $expecteduserid, $adminusername) {
        $this->resetAfterTest(true);
        $this->setup_test_data_xml();

        // Set up the configured admin username
        set_config('admin_username', $adminusername, 'elisfiles');
        set_config('mnethostid', 1);
        elis::$config = new elis_config();

        // Validate method output
        $userid = elis_files_folder_to_userid($foldername);
        $this->assertEquals($expecteduserid, $userid);
    }
 /**
  * Validate that the enrolment count excludes inactive users when the site is not configured to show inactive users
  */
 public function test_usercountexcludesinactivewhenexcludinginactive()
 {
     require_once elispm::lib('lib.php');
     // Set up all the data needed for the listing.
     $this->load_csv_data();
     // Disable showing of inactive users.
     pm_set_config('legacy_show_inactive_users', 0);
     elis::$config = new elis_config();
     // Obtain the listing.
     $listing = track_assignment_get_listing(1);
     // Validate the number of rows.
     $count = 0;
     foreach ($listing as $entity) {
         $count++;
         // Validate the aggregated count in the first row.
         $this->assertEquals(1, $entity->enrolments);
     }
     unset($listing);
     $this->assertEquals(1, $count);
 }
 /**
  * Validate that the listing respects paging
  */
 public function test_availableusersrespectspaging()
 {
     $this->load_csv_data();
     $this->assign_track_enrol_permissions();
     set_config('siteguest', '');
     set_config('siteadmins', '');
     pm_set_config('legacy_show_inactive_users', 0);
     elis::$config = new elis_config();
     $usersrecset = usertrack::get_available_users(1, 'lastname', 'ASC', '', '', 0, 1);
     $users = array();
     foreach ($usersrecset as $key => $user) {
         $users[$key] = $user;
     }
     unset($usersrecset);
     // Validate that only one record is picked up when paging with page size 1.
     $this->assertEquals(1, count($users));
 }
예제 #4
0
 /**
  * Validate that our method does not auto-assign idnumber for a particular user when the parameter and setting are disabled.
  *
  * @dataProvider dataprovider_autoassignidnumber
  * @param array An array containing users with their required information
  */
 public function test_autoassignidnumberdisabledwhensettingandparameterdisabledwhenuseridprovided($users)
 {
     global $DB;
     // NOTE: this test does not specifically depend on the userid parameter but is a valuable sanity check.
     // Make sure the config is not enabling the functionality.
     set_config('auto_assign_user_idnumber', 0, 'local_elisprogram');
     elis::$config = new elis_config();
     foreach ($users as $i => $user) {
         // Set up the provided users.
         $users[$i]['id'] = $DB->insert_record('user', (object) $user);
     }
     // Call the migration method.
     pm_migrate_moodle_users(false, 0, $users[0]['id']);
     // Count the number of users.
     $this->assertEquals(0, $DB->count_records_select('user', 'username = idnumber'));
 }
예제 #5
0
 /**
  * Validate that My Moodle redirection works when it's supposed to
  */
 public function test_myoodleredirectreturnstruewhensettingenabled()
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     // Set up our test user.
     $user = new stdClass();
     $user->username = "******";
     $userid = user_create_user($user);
     $USER = $DB->get_record('user', array('id' => $userid));
     // Enable functionality.
     pm_set_config('mymoodle_redirect', 1);
     elis::$config = new elis_config();
     // Validation.
     $result = pm_mymoodle_redirect();
     $this->assertTrue($result);
 }
예제 #6
0
 /**
  * Validating that enrolling a user in a track instance triggers the enrolment
  * notification
  */
 public function test_track_enrolment_sends_class_enrolment_notification()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/curriculum.class.php');
     require_once elispm::lib('data/track.class.php');
     require_once elispm::lib('data/user.class.php');
     // Configuration.
     set_config('popup_provider_elis_program_notify_pm_permitted', 1, 'message');
     set_config('email_provider_elis_program_notify_pm_permitted', 1, 'message');
     set_config('notify_trackenrol_user', 1, 'local_elisprogram');
     $message = '%%userenrolname%% has been enrolled in the track %%trackname%%.';
     set_config('notify_trackenrol_message', $message, 'local_elisprogram');
     // Force refreshing of configuration.
     elis::$config = new elis_config();
     $this->setAdminUser();
     unset_config('noemailever');
     // Setup.
     $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA'));
     $user->save();
     $program = new curriculum(array('idnumber' => 'testprogramidnumber'));
     $program->save();
     $track = new track(array('curid' => $program->id, 'idnumber' => 'testtrackidnumber', 'name' => 'testtrackname'));
     $track->save();
     // Run the enrolment create action.
     $record = new stdClass();
     $record->context = 'track_testtrackidnumber';
     $record->user_username = '******';
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $sink = $this->redirectEmails();
     $importplugin->track_enrolment_create($record, 'bogus', 'testtrackidnumber');
     $this->assertEquals(1, count($sink->get_messages()));
     $sink->close();
     // Validation.
     $mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
     $expectedmessage = "{$user->firstname} {$user->lastname} has been enrolled in the track {$track->name}.";
     $like = $DB->sql_like('fullmessagehtml', ':message');
     $select = "useridto = :userid\n                   AND {$like}";
     $this->assertTrue($DB->record_exists_select('message', $select, array('userid' => $mdluserid, 'message' => "{$expectedmessage}%")));
 }
예제 #7
0
 /**
  * Validate that counting the number of role assignments on a particular
  * cluster for a particular role respects special userset permissions
  */
 public function test_clusterrolepagecountroleusersrespectsusersetpermissions()
 {
     global $CFG, $USER, $DB;
     require_once elispm::lib('data/clusterassignment.class.php');
     require_once elispm::lib('data/user.class.php');
     require_once elispm::lib('data/userset.class.php');
     accesslib_clear_all_caches(true);
     // Create a user record so that Moodle and PM ids don't match by fluke.
     set_config('auto_assign_user_idnumber', 0, 'local_elisprogram');
     elis::$config = new elis_config();
     create_user_record('bogususer', 'Bogususer!0');
     // Create our test userset.
     $userset = new userset(array('name' => 'testuserset'));
     $userset->save();
     // The user who is assigned to the user set.
     $assigneduser = new user(array('idnumber' => 'assigned', 'username' => 'assigned', 'firstname' => 'assigned', 'lastname' => 'assigned', 'email' => '*****@*****.**', 'country' => 'CA'));
     $assigneduser->save();
     // Userset assignment.
     $clusterassignment = new clusterassignment(array('clusterid' => $userset->id, 'userid' => $assigneduser->id));
     $clusterassignment->save();
     // User who is potentially assigning the userset member a new role within the userset.
     $assigninguser = new user(array('idnumber' => 'assigning', 'username' => 'assigning', 'firstname' => 'assigning', 'lastname' => 'assigning', 'email' => '*****@*****.**', 'country' => 'CA'));
     $assigninguser->save();
     // Need the system context for role assignments.
     $systemcontext = context_system::instance();
     // Set up the role that allows a user to assign roles but only to userset members.
     $permissionsroleid = create_role('permissionsrole', 'permissionsrole', 'permissionsrole');
     // Enable the appropriate capabilities.
     assign_capability('moodle/role:assign', CAP_ALLOW, $permissionsroleid, $systemcontext->id);
     assign_capability('local/elisprogram:userset_role_assign_userset_users', CAP_ALLOW, $permissionsroleid, $systemcontext->id);
     // Perform the role assignment.
     $moodleuserid = $DB->get_field('user', 'id', array('username' => 'assigning'));
     role_assign($permissionsroleid, $moodleuserid, $systemcontext->id);
     // Imitate the user assigned the role which allows for further role assignments only on userset members.
     $USER = $DB->get_record('user', array('id' => $moodleuserid));
     // Test role for potential assignment to userset members.
     $roleid = create_role('targetrole', 'targetrole', 'targetrole');
     // Assign the both users to the userset role.
     $contextclass = \local_eliscore\context\helper::get_class_for_level(CONTEXT_ELIS_USERSET);
     $usersetcontext = $contextclass::instance($userset->id);
     role_assign($roleid, $moodleuserid, $usersetcontext->id);
     $moodleuserid = $DB->get_field('user', 'id', array('username' => 'assigned'));
     role_assign($roleid, $moodleuserid, $usersetcontext->id);
     // Obtain the count of assigned users.
     $page = new cluster_rolepage(array('id' => $userset->id));
     $count = $page->count_role_users($roleid, $usersetcontext);
     // List should only contain the userset member.
     $this->assertEquals(1, $count);
 }
예제 #8
0
파일: setup.php 프로젝트: jamesmcq/elis
    {
        global $DB;
        if (!isset($this->configs[$name])) {
            $config = new stdClass();
            // load the defaults
            if (file_exists(elis::plugin_file($name, 'defaults.php'))) {
                $defaults = array();
                include elis::plugin_file($name, 'defaults.php');
                foreach ($defaults as $key => $value) {
                    $config->{$key} = $value;
                }
            }
            $configrecs = $DB->get_recordset('config_plugins', array('plugin' => $name));
            foreach ($configrecs as $rec) {
                $key = $rec->name;
                $config->{$key} = $rec->value;
            }
            unset($configrecs);
            $this->configs[$name] = $config;
        }
        return $this->configs[$name];
    }
}
global $CFG;
elis::$basedir = "{$CFG->dirroot}/local";
elis::$libdir = elis::file('eliscore/lib');
elis::$config = new elis_config();
$plugin = new stdClass();
require elis::file('eliscore/version.php');
elis::$version = $plugin->version;
elis::$release = $plugin->release;
예제 #9
0
 /**
  * Load ELIS config data before every test.
  * (otherwise config setting changes are lost when loading csv data during group testing)
  */
 protected function setUp()
 {
     parent::setUp();
     elis::$config = new elis_config();
 }
예제 #10
0
 /**
  * Validate that default values are correctly set on user creation
  */
 public function test_version1importsetsdefaultsonusercreate()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/eliscore/lib/setup.php';
     set_config('forcetimezone', 99);
     // Make sure we are not auto-assigning idnumbers.
     set_config('auto_assign_user_idnumber', 0, 'local_elisprogram');
     elis::$config = new elis_config();
     $this->run_core_user_import(array());
     $select = "username = :username AND\n                   mnethostid = :mnethostid AND\n                   auth = :auth AND\n                   maildigest = :maildigest AND\n                   autosubscribe = :autosubscribe AND\n                   trackforums = :trackforums AND\n                   timezone = :timezone AND\n                   theme = :theme AND\n                   lang = :lang AND\n                   {$DB->sql_compare_text('description')} = :description AND\n                   idnumber = :idnumber AND\n                   institution = :institution AND\n                   department = :department";
     $params = array('username' => 'rlipusername', 'mnethostid' => $CFG->mnet_localhost_id, 'auth' => 'manual', 'maildigest' => 0, 'autosubscribe' => 1, 'trackforums' => 0, 'timezone' => 99, 'theme' => '', 'lang' => $CFG->lang, 'description' => '', 'idnumber' => '', 'institution' => '', 'department' => '');
     $exists = $DB->record_exists_select('user', $select, $params);
     $this->assertEquals($exists, true);
 }