当前位置: 首页>>代码示例>>PHP>>正文


PHP accesslib_clear_all_caches函数代码示例

本文整理汇总了PHP中accesslib_clear_all_caches函数的典型用法代码示例。如果您正苦于以下问题:PHP accesslib_clear_all_caches函数的具体用法?PHP accesslib_clear_all_caches怎么用?PHP accesslib_clear_all_caches使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了accesslib_clear_all_caches函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: reset_all_data

 /**
  * Reset contents of all database tables to initial values, reset caches, etc.
  *
  * Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
  *
  * @static
  * @param bool $detectchanges
  *      true  - changes in global state and database are reported as errors
  *      false - no errors reported
  *      null  - only critical problems are reported as errors
  * @return void
  */
 public static function reset_all_data($detectchanges = false)
 {
     global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
     // Stop any message redirection.
     phpunit_util::stop_message_redirection();
     // Stop any message redirection.
     phpunit_util::stop_phpmailer_redirection();
     // Stop any message redirection.
     phpunit_util::stop_event_redirection();
     // We used to call gc_collect_cycles here to ensure desctructors were called between tests.
     // This accounted for 25% of the total time running phpunit - so we removed it.
     // Show any unhandled debugging messages, the runbare() could already reset it.
     self::display_debugging_messages();
     self::reset_debugging();
     // reset global $DB in case somebody mocked it
     $DB = self::get_global_backup('DB');
     if ($DB->is_transaction_started()) {
         // we can not reset inside transaction
         $DB->force_transaction_rollback();
     }
     $resetdb = self::reset_database();
     $warnings = array();
     if ($detectchanges === true) {
         if ($resetdb) {
             $warnings[] = 'Warning: unexpected database modification, resetting DB state';
         }
         $oldcfg = self::get_global_backup('CFG');
         $oldsite = self::get_global_backup('SITE');
         foreach ($CFG as $k => $v) {
             if (!property_exists($oldcfg, $k)) {
                 $warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
             } else {
                 if ($oldcfg->{$k} !== $CFG->{$k}) {
                     $warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
                 }
             }
             unset($oldcfg->{$k});
         }
         if ($oldcfg) {
             foreach ($oldcfg as $k => $v) {
                 $warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
             }
         }
         if ($USER->id != 0) {
             $warnings[] = 'Warning: unexpected change of $USER';
         }
         if ($COURSE->id != $oldsite->id) {
             $warnings[] = 'Warning: unexpected change of $COURSE';
         }
     }
     if (ini_get('max_execution_time') != 0) {
         // This is special warning for all resets because we do not want any
         // libraries to mess with timeouts unintentionally.
         // Our PHPUnit integration is not supposed to change it either.
         if ($detectchanges !== false) {
             $warnings[] = 'Warning: max_execution_time was changed to ' . ini_get('max_execution_time');
         }
         set_time_limit(0);
     }
     // restore original globals
     $_SERVER = self::get_global_backup('_SERVER');
     $CFG = self::get_global_backup('CFG');
     $SITE = self::get_global_backup('SITE');
     $_GET = array();
     $_POST = array();
     $_FILES = array();
     $_REQUEST = array();
     $COURSE = $SITE;
     // reinitialise following globals
     $OUTPUT = new bootstrap_renderer();
     $PAGE = new moodle_page();
     $FULLME = null;
     $ME = null;
     $SCRIPT = null;
     // Empty sessison and set fresh new not-logged-in user.
     \core\session\manager::init_empty_session();
     // reset all static caches
     \core\event\manager::phpunit_reset();
     accesslib_clear_all_caches(true);
     get_string_manager()->reset_caches(true);
     reset_text_filters_cache(true);
     events_get_handlers('reset');
     core_text::reset_caches();
     get_message_processors(false, true);
     filter_manager::reset_caches();
     // Reset internal users.
     core_user::reset_internal_users();
     //TODO MDL-25290: add more resets here and probably refactor them to new core function
//.........这里部分代码省略.........
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:101,代码来源:util.php

示例2: test_mymoodleredirectreturnsfalseforadmin

 /**
  * Validate that redirection from My Moodle does not happen for admins
  */
 public function test_mymoodleredirectreturnsfalseforadmin()
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     // Make sure we're not a guest.
     set_config('siteguest', '');
     // Obtain the system context.
     $syscontext = context_system::instance();
     // Set up the current user global.
     $user = new stdClass();
     $user->username = "testuser";
     $userid = user_create_user($user);
     $USER = $DB->get_record('user', array('id' => $userid));
     // Enable functionaltiy.
     pm_set_config('mymoodle_redirect', 1);
     elis::$config = new elis_config();
     // Give the admin sufficient permissions.
     $roleid = create_role('adminrole', 'adminrole', 'adminrole');
     assign_capability('moodle/site:config', CAP_ALLOW, $roleid, $syscontext->id);
     role_assign($roleid, $USER->id, $syscontext->id);
     // Validate that redirection does not happen for admins.
     $result = pm_mymoodle_redirect();
     // Clear out cached permissions data so we don't affect other tests.
     accesslib_clear_all_caches(true);
     $this->assertFalse($result);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:29,代码来源:programsettings_test.php

示例3: test_coursepermissions

 /**
  * Test for correct assignment of course permissions
  */
 public function test_coursepermissions()
 {
     global $DB, $CFG, $USER;
     accesslib_clear_all_caches(true);
     set_config('siteguest', '');
     set_config('siteadmins', '');
     $this->assertFalse($this->has_program_create_capability());
     $this->assertFalse($this->has_associate_and_manage_capability());
     $this->assertFalse($this->has_program_view_capability());
     $syscontext = context_system::instance();
     $assigninguser = new user(array('idnumber' => 'testuserid', 'username' => 'testuser', 'firstname' => 'testuser', 'lastname' => 'testuser', 'email' => 'testuser@testuserdomain.com', 'country' => 'CA'));
     $assigninguser->save();
     $roleid = create_role('userrole', 'userrole', 'userrole');
     $usr = $DB->get_record('user', array('username' => 'testuser'));
     $this->setUser($usr);
     $USER = $usr;
     assign_capability('local/elisprogram:associate', CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability('local/elisprogram:manage', CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability('local/elisprogram:program_create', CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability('local/elisprogram:program_enrol', CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability('local/elisprogram:program_view', CAP_ALLOW, $roleid, $syscontext->id);
     role_assign($roleid, $usr->id, $syscontext->id);
     $this->assertTrue($this->has_program_create_capability());
     $this->assertTrue($this->has_associate_and_manage_capability());
     $this->assertTrue($this->has_program_view_capability());
     $this->setUser(null);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:30,代码来源:permissions_test.php

示例4: test_get_userset_subsets

 /**
  * Tests deepsight_datatable_usersetuser_base::get_userset_subsets
  * @dataProvider dataprovider_get_userset_subsets
  * @param int $parentuserset The ID of a userset to pass to the function as the parent userset ID.
  * @param bool $includeparent Whether to include the parent ID in the return array.
  * @param array $expectedresults The expected return value.
  */
 public function test_get_userset_subsets($parentuserset, $includeparent, $expectedresults)
 {
     $dataset = $this->createCsvDataSet(array(user::TABLE => elispm::file('tests/fixtures/deepsight_user.csv'), userset::TABLE => elispm::file('tests/fixtures/deepsight_usersetwithsubsets.csv')));
     $this->loadDataSet($dataset);
     accesslib_clear_all_caches(true);
     // Set up contexts.
     for ($i = 1; $i <= 6; $i++) {
         $ctx = \local_elisprogram\context\userset::instance($i);
     }
     accesslib_clear_all_caches(true);
     $actualresults = deepsight_datatable_standard::get_userset_subsets($parentuserset, $includeparent);
     $this->assertEquals($expectedresults, array_keys($actualresults));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:20,代码来源:deepsight_datatable_test.php

示例5: test_block_elisadmin_load_menu_children_course

 /**
  * Test block_elisadmin_load_menu_children_course function.
  */
 public function test_block_elisadmin_load_menu_children_course()
 {
     global $DB, $USER;
     accesslib_clear_all_caches(true);
     // Create test user - ensure the returned user is NOT a site admin. if they are, our capability restrictions won't work.
     $testuser = new user();
     $testuser->username = 'testELIS4093';
     $testuser->idnumber = 'testELIS4093';
     $testuser->firstname = 'testELIS4093';
     $testuser->lastname = 'testELIS4093';
     $testuser->email = 'testELIS4093@example.com';
     $testuser->country = 'CA';
     $testuser->save();
     $testmuser = $testuser->get_moodleuser();
     // Create role with cap: 'local/elisprogram:class_view'.
     $testrole = new stdClass();
     $testrole->name = 'ELIS Class View';
     $testrole->shortname = '_test_ELIS_4093';
     $testrole->description = 'ELIS Class View';
     $testrole->archetype = '';
     $testrole->id = create_role($testrole->name, $testrole->shortname, $testrole->description, $testrole->archetype);
     // Ensure our new role is assignable to ELIS class contexts.
     set_role_contextlevels($testrole->id, array(CONTEXT_ELIS_CLASS));
     // Ensure the role has our required capability assigned.
     $sitecontext = context_system::instance();
     assign_capability('local/elisprogram:class_view', CAP_ALLOW, $testrole->id, $sitecontext->id, true);
     $sitecontext->mark_dirty();
     // Create ELIS Course Description.
     $testcrs = new course(array('name' => 'CD-ELIS-4093', 'idnumber' => 'CDELIS4093', 'syllabus' => ''));
     $testcrs->save();
     $testcrs->load();
     // Create three(3) Class Instances for Course Descrption.
     $testcls1 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.1'));
     $testcls1->save();
     $testcls1->load();
     $testcls2 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.2'));
     $testcls2->save();
     $testcls2->load();
     $testcls3 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.3'));
     $testcls3->save();
     $testcls3->load();
     // Assign testuser new role in one Class Instance.
     $context = \local_elisprogram\context\pmclass::instance($testcls2->id);
     role_assign($testrole->id, $testmuser->id, $context->id);
     // Switch to testuser.
     $USER = $testmuser;
     $this->setUser($testmuser);
     $items = block_elisadmin_load_menu_children_course($testcrs->id, 0, 0, 5, '');
     $this->assertEquals(1, count($items));
     $this->assertTrue($items[0]->name == 'pmclass_2');
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:54,代码来源:block_elisadmin_test.php

示例6: setUp

 /**
  * Do setup before each test.
  */
 protected function setUp()
 {
     global $DB;
     parent::setUp();
     // Ensure that the editing teacher role has a specific capapbility enabled.
     $role = $DB->get_record('role', array('shortname' => 'editingteacher'));
     accesslib_clear_all_caches(true);
     $syscontext = context_system::instance();
     assign_capability('local/elisprogram:userset_enrol_userset_user', CAP_ALLOW, $role->id, $syscontext, true);
     $syscontext->mark_dirty();
     // Initialise testing data.
     $this->initprogram();
     $this->inittrack($this->tprogramid);
     $this->initcourse();
     $this->initclass($this->tcourseid);
     $this->inituser();
     $this->inituserset();
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:21,代码来源:fakecontexthierarchy_test.php

示例7: reset_all_data

 /**
  * Reset contents of all database tables to initial values, reset caches, etc.
  *
  * Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
  *
  * @static
  * @param bool $logchanges log changes in global state and database in error log
  * @return void
  */
 public static function reset_all_data($logchanges = false)
 {
     global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
     // Stop any message redirection.
     phpunit_util::stop_message_redirection();
     // Release memory and indirectly call destroy() methods to release resource handles, etc.
     gc_collect_cycles();
     // Show any unhandled debugging messages, the runbare() could already reset it.
     self::display_debugging_messages();
     self::reset_debugging();
     // reset global $DB in case somebody mocked it
     $DB = self::get_global_backup('DB');
     if ($DB->is_transaction_started()) {
         // we can not reset inside transaction
         $DB->force_transaction_rollback();
     }
     $resetdb = self::reset_database();
     $warnings = array();
     if ($logchanges) {
         if ($resetdb) {
             $warnings[] = 'Warning: unexpected database modification, resetting DB state';
         }
         $oldcfg = self::get_global_backup('CFG');
         $oldsite = self::get_global_backup('SITE');
         foreach ($CFG as $k => $v) {
             if (!property_exists($oldcfg, $k)) {
                 $warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
             } else {
                 if ($oldcfg->{$k} !== $CFG->{$k}) {
                     $warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
                 }
             }
             unset($oldcfg->{$k});
         }
         if ($oldcfg) {
             foreach ($oldcfg as $k => $v) {
                 $warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
             }
         }
         if ($USER->id != 0) {
             $warnings[] = 'Warning: unexpected change of $USER';
         }
         if ($COURSE->id != $oldsite->id) {
             $warnings[] = 'Warning: unexpected change of $COURSE';
         }
     }
     // restore original globals
     $_SERVER = self::get_global_backup('_SERVER');
     $CFG = self::get_global_backup('CFG');
     $SITE = self::get_global_backup('SITE');
     $COURSE = $SITE;
     // reinitialise following globals
     $OUTPUT = new bootstrap_renderer();
     $PAGE = new moodle_page();
     $FULLME = null;
     $ME = null;
     $SCRIPT = null;
     $SESSION = new stdClass();
     $_SESSION['SESSION'] =& $SESSION;
     // set fresh new not-logged-in user
     $user = new stdClass();
     $user->id = 0;
     $user->mnethostid = $CFG->mnet_localhost_id;
     session_set_user($user);
     // reset all static caches
     accesslib_clear_all_caches(true);
     get_string_manager()->reset_caches(true);
     reset_text_filters_cache(true);
     events_get_handlers('reset');
     textlib::reset_caches();
     if (class_exists('repository')) {
         repository::reset_caches();
     }
     filter_manager::reset_caches();
     //TODO MDL-25290: add more resets here and probably refactor them to new core function
     // Reset course and module caches.
     if (class_exists('format_base')) {
         // If file containing class is not loaded, there is no cache there anyway.
         format_base::reset_course_cache(0);
     }
     get_fast_modinfo(0, 0, true);
     // Reset other singletons.
     if (class_exists('plugin_manager')) {
         plugin_manager::reset_caches(true);
     }
     if (class_exists('available_update_checker')) {
         available_update_checker::reset_caches(true);
     }
     if (class_exists('available_update_deployer')) {
         available_update_deployer::reset_caches(true);
     }
//.........这里部分代码省略.........
开发者ID:Burick,项目名称:moodle,代码行数:101,代码来源:util.php

示例8: test_available_table_obeys_perms

 /**
  * 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;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:44,代码来源:deepsight_datatable_instructor_test.php

示例9: test_available_permissions_associate

 /**
  * Test available table only shows classes that the assigner has the local/elisprogram::associate permission on.
  * @dataProvider dataprovider_available_permissions_associate
  * @param array $contextstoassign An array of information specifying the contexts to assign the associate permission on.
  *                                This is formatted like array('system' => true, 'class' => array(1, 2, 3))
  * @param int $tabletrackid The ID of the track we're going to manage.
  * @param array $expectedresults The expected page of results.
  * @param int $expectedtotal The expected number of total results.
  */
 public function test_available_permissions_associate($contextstoassign, $tabletrackid, $expectedresults, $expectedtotal)
 {
     global $USER, $DB, $CFG;
     $userbackup = $USER;
     // Set up permissions.
     $USER = $this->setup_permissions_test();
     // We're not interested in the class > course > program > track requirement for this test, so assign all courses to all
     // programs.
     foreach (array(5, 6, 7) as $programid) {
         foreach (array(100, 101, 102) as $courseid) {
             $association = new curriculumcourse(array('curriculumid' => $programid, 'courseid' => $courseid));
             $association->save();
         }
     }
     // Set up capabilities.
     foreach ($contextstoassign as $contexttype => $ids) {
         if ($contexttype === 'system') {
             $this->give_permission_for_context($USER->id, 'local/elisprogram:associate', context_system::instance());
         } else {
             foreach ($ids as $contextinstanceid) {
                 switch ($contexttype) {
                     case 'class':
                         $context = \local_elisprogram\context\pmclass::instance($contextinstanceid);
                         break;
                 }
                 $this->give_permission_for_context($USER->id, 'local/elisprogram:associate', $context);
             }
         }
     }
     accesslib_clear_all_caches(true);
     // Construct test table.
     $table = new deepsight_datatable_trackclass_available_mock($DB, 'test', 'http://localhost', 'testuniqid');
     $table->set_trackid($tabletrackid);
     // Perform test.
     $actualresults = $table->get_search_results(array(), array(), 0, 20);
     // Verify result.
     $this->assert_search_results($expectedresults, $expectedtotal, $actualresults);
     // Restore user.
     $USER = $userbackup;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:49,代码来源:deepsight_datatable_trackclass_test.php

示例10: reset_all_data

    /**
     * Reset contents of all database tables to initial values, reset caches, etc.
     *
     * Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
     *
     * @static
     * @param bool $logchanges log changes in global state and database in error log
     * @return void
     */
    public static function reset_all_data($logchanges = false) {
        global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION, $GROUPLIB_CACHE;

        // Release memory and indirectly call destroy() methods to release resource handles, etc.
        gc_collect_cycles();

        // reset global $DB in case somebody mocked it
        $DB = self::get_global_backup('DB');

        if ($DB->is_transaction_started()) {
            // we can not reset inside transaction
            $DB->force_transaction_rollback();
        }

        $resetdb = self::reset_database();
        $warnings = array();

        if ($logchanges) {
            if ($resetdb) {
                $warnings[] = 'Warning: unexpected database modification, resetting DB state';
            }

            $oldcfg = self::get_global_backup('CFG');
            $oldsite = self::get_global_backup('SITE');
            foreach($CFG as $k=>$v) {
                if (!property_exists($oldcfg, $k)) {
                    $warnings[] = 'Warning: unexpected new $CFG->'.$k.' value';
                } else if ($oldcfg->$k !== $CFG->$k) {
                    $warnings[] = 'Warning: unexpected change of $CFG->'.$k.' value';
                }
                unset($oldcfg->$k);

            }
            if ($oldcfg) {
                foreach($oldcfg as $k=>$v) {
                    $warnings[] = 'Warning: unexpected removal of $CFG->'.$k;
                }
            }

            if ($USER->id != 0) {
                $warnings[] = 'Warning: unexpected change of $USER';
            }

            if ($COURSE->id != $oldsite->id) {
                $warnings[] = 'Warning: unexpected change of $COURSE';
            }

        }

        if (ini_get('max_execution_time') != 0) {
            // This is special warning for all resets because we do not want any
            // libraries to mess with timeouts unintentionally.
            // Our PHPUnit integration is not supposed to change it either.

            // TODO: MDL-38912 uncomment and fix all + somehow resolve timeouts in failed tests.
            //$warnings[] = 'Warning: max_execution_time was changed.';
            set_time_limit(0);
        }

        // restore original globals
        $_SERVER = self::get_global_backup('_SERVER');
        $CFG = self::get_global_backup('CFG');
        $SITE = self::get_global_backup('SITE');
        $COURSE = $SITE;

        // reinitialise following globals
        $OUTPUT = new bootstrap_renderer();
        $PAGE = new moodle_page();
        $FULLME = null;
        $ME = null;
        $SCRIPT = null;
        $SESSION = new stdClass();
        $_SESSION['SESSION'] =& $SESSION;

        // set fresh new not-logged-in user
        $user = new stdClass();
        $user->id = 0;
        $user->mnethostid = $CFG->mnet_localhost_id;
        session_set_user($user);

        // reset all static caches
        accesslib_clear_all_caches(true);
        get_string_manager()->reset_caches();
        events_get_handlers('reset');
        textlib::reset_caches();
        if (class_exists('repository')) {
            repository::reset_caches();
        }
        $GROUPLIB_CACHE = null;
        //TODO MDL-25290: add more resets here and probably refactor them to new core function

//.........这里部分代码省略.........
开发者ID:ncsu-delta,项目名称:moodle,代码行数:101,代码来源:util.php

示例11: reset_all_data

 /**
  * Reset contents of all database tables to initial values, reset caches, etc.
  */
 public static function reset_all_data()
 {
     // Reset database.
     self::reset_database();
     // Purge dataroot directory.
     self::reset_dataroot();
     // Reset all static caches.
     accesslib_clear_all_caches(true);
     // Reset the nasty strings list used during the last test.
     nasty_strings::reset_used_strings();
     filter_manager::reset_caches();
     // Reset course and module caches.
     if (class_exists('format_base')) {
         // If file containing class is not loaded, there is no cache there anyway.
         format_base::reset_course_cache(0);
     }
     get_fast_modinfo(0, 0, true);
     // Inform data generator.
     self::get_data_generator()->reset();
     // Initialise $CFG with default values. This is needed for behat cli process, so we don't have modified
     // $CFG values from the old run. @see set_config.
     initialise_cfg();
 }
开发者ID:janeklb,项目名称:moodle,代码行数:26,代码来源:util.php

示例12: test_everything_in_accesslib


//.........这里部分代码省略.........
        }
        $this->assertEquals(context_inspection::test_context_cache_size(), count($records));
        unset($records);
        unset($columns);

        context_helper::reset_caches();
        context_helper::preload_course($SITE->id);
        $this->assertEquals(7, context_inspection::test_context_cache_size()); // depends on number of default blocks

        // ====== assign_capability(), unassign_capability() ====================

        $rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
        $this->assertFalse($rc);
        assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $allroles['teacher'], $frontpagecontext->id);
        $rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
        $this->assertEquals($rc->permission, CAP_ALLOW);
        assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext->id);
        $rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
        $this->assertEquals($rc->permission, CAP_ALLOW);
        assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext, true);
        $rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
        $this->assertEquals($rc->permission, CAP_PREVENT);

        assign_capability('moodle/site:accessallgroups', CAP_INHERIT, $allroles['teacher'], $frontpagecontext);
        $rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
        $this->assertFalse($rc);
        assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $allroles['teacher'], $frontpagecontext);
        unassign_capability('moodle/site:accessallgroups', $allroles['teacher'], $frontpagecontext, true);
        $rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
        $this->assertFalse($rc);
        unassign_capability('moodle/site:accessallgroups', $allroles['teacher'], $frontpagecontext->id, true);
        unset($rc);

        accesslib_clear_all_caches(false); // must be done after assign_capability()


        // ======= role_assign(), role_unassign(), role_unassign_all() ==============

        $context = context_course::instance($testcourses[1]);
        $this->assertEquals($DB->count_records('role_assignments', array('contextid'=>$context->id)), 0);
        role_assign($allroles['teacher'], $testusers[1], $context->id);
        role_assign($allroles['teacher'], $testusers[2], $context->id);
        role_assign($allroles['manager'], $testusers[1], $context->id);
        $this->assertEquals($DB->count_records('role_assignments', array('contextid'=>$context->id)), 3);
        role_unassign($allroles['teacher'], $testusers[1], $context->id);
        $this->assertEquals($DB->count_records('role_assignments', array('contextid'=>$context->id)), 2);
        role_unassign_all(array('contextid'=>$context->id));
        $this->assertEquals($DB->count_records('role_assignments', array('contextid'=>$context->id)), 0);
        unset($context);

        accesslib_clear_all_caches(false); // just in case


        // ====== has_capability(), get_users_by_capability(), role_switch(), reload_all_capabilities() and friends ========================

        $adminid = get_admin()->id;
        $guestid = $CFG->siteguest;

        // Enrol some users into some courses
        $course1 = $DB->get_record('course', array('id'=>$testcourses[22]), '*', MUST_EXIST);
        $course2 = $DB->get_record('course', array('id'=>$testcourses[7]), '*', MUST_EXIST);
        $cms = $DB->get_records('course_modules', array('course'=>$course1->id), 'id');
        $cm1 = reset($cms);
        $blocks = $DB->get_records('block_instances', array('parentcontextid'=>context_module::instance($cm1->id)->id), 'id');
        $block1 = reset($blocks);
        $instance1 = $DB->get_record('enrol', array('enrol'=>'manual', 'courseid'=>$course1->id));
开发者ID:numbas,项目名称:moodle,代码行数:67,代码来源:accesslib_test.php

示例13: reset_all_data

 /**
  * Reset contents of all database tables to initial values, reset caches, etc.
  */
 public static function reset_all_data()
 {
     // Reset database.
     self::reset_database();
     // Purge dataroot directory.
     self::reset_dataroot();
     // Reset all static caches.
     accesslib_clear_all_caches(true);
     // Reset the nasty strings list used during the last test.
     nasty_strings::reset_used_strings();
     filter_manager::reset_caches();
     // Reset course and module caches.
     if (class_exists('format_base')) {
         // If file containing class is not loaded, there is no cache there anyway.
         format_base::reset_course_cache(0);
     }
     get_fast_modinfo(0, 0, true);
     // Inform data generator.
     self::get_data_generator()->reset();
 }
开发者ID:reconnectmedia,项目名称:moodle,代码行数:23,代码来源:util.php

示例14: test_gradesyncwithduplicateclassenrolmentrecords

 /**
  * Validate that even with duplicate enrolment records, the grade synchronisation still runs correctly and can synchronise
  * data for unique enrolments.
  */
 public function test_gradesyncwithduplicateclassenrolmentrecords()
 {
     global $DB, $CFG;
     $dataset = $this->createCsvDataSet(array('context' => \elispm::file('tests/fixtures/gsync_context.csv'), 'course' => \elispm::file('tests/fixtures/gsync_mdl_course.csv'), 'grade_grades' => \elispm::file('tests/fixtures/gsync_grade_grades.csv'), 'grade_items' => \elispm::file('tests/fixtures/gsync_grade_items.csv'), 'role_assignments' => \elispm::file('tests/fixtures/gsync_role_assignments.csv'), 'user' => \elispm::file('tests/fixtures/gsync_mdl_user.csv'), 'user_enrolments' => \elispm::file('tests/fixtures/gsync_user_enrolments.csv'), 'enrol' => \elispm::file('tests/fixtures/gsync_enrol.csv'), \pmclass::TABLE => \elispm::file('tests/fixtures/gsync_class.csv'), \student::TABLE => \elispm::file('tests/fixtures/gsync_class_enrolment.csv'), \classmoodlecourse::TABLE => \elispm::file('tests/fixtures/gsync_class_moodle.csv'), \course::TABLE => \elispm::file('tests/fixtures/gsync_course.csv'), \user::TABLE => \elispm::file('tests/fixtures/gsync_user.csv'), \usermoodle::TABLE => \elispm::file('tests/fixtures/gsync_user_moodle.csv')));
     $this->loadDataSet($dataset);
     // We need to reset the context cache.
     accesslib_clear_all_caches(true);
     // Make our role a "student" role.
     set_config('gradebookroles', 1);
     // Force synchronisation of grade data from Moodle to ELIS.
     $sync = new \local_elisprogram\moodle\synchronize();
     $sync->synchronize_moodle_class_grades();
     $params = array('classid' => 1, 'userid' => 120, 'grade' => 75.0);
     $this->assertTrue($DB->record_exists(\student::TABLE, $params));
     $params['userid'] = 100;
     $params['grade'] = 77.0;
     $params['completestatusid'] = STUSTATUS_PASSED;
     $this->assertTrue($DB->record_exists(\student::TABLE, $params));
     $params['userid'] = 130;
     $params['grade'] = 82.0;
     $this->assertTrue($DB->record_exists(\student::TABLE, $params));
     $params['userid'] = 110;
     $params['grade'] = 88.0;
     $this->assertTrue($DB->record_exists(\student::TABLE, $params));
     $params['userid'] = 110;
     $params['completestatusid'] = STUSTATUS_NOTCOMPLETE;
     $params['grade'] = 0.0;
     $this->assertTrue($DB->record_exists(\student::TABLE, $params));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:33,代码来源:synchronizemoodleclassgrades_test.php

示例15: test_clusterrolepagecountroleusersrespectsusersetpermissions

 /**
  * 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' => 'assigned@assigned.com', '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' => 'assigning@assigning.com', '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);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:53,代码来源:roles_test.php


注:本文中的accesslib_clear_all_caches函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。