/** * Test case for custom context classes */ public function costcenter_custom_contexts_setup() { global $CFG; static $customcontexts = array( 27 => 'context_costcenter' ); // save any existing custom contexts $existingcustomcontexts = get_config(null, 'custom_context_classes'); set_config('custom_context_classes', serialize($customcontexts)); initialise_cfg(); context_helper::reset_levels(); $alllevels = context_helper::get_all_levels(); /// $this->assertEquals($alllevels[11], 'context_costcenter'); // clean-up & restore any custom contexts //set_config('custom_context_classes', ($existingcustomcontexts === false) ? null : $existingcustomcontexts); // initialise_cfg(); // context_helper::reset_levels(); // $alllevels = context_helper::get_all_levels(); // print_object($alllevels); }
/** * Load global $CFG; * @internal * @static * @return void */ public static function initialise_cfg() { global $DB; $dbhash = false; try { $dbhash = $DB->get_field('config', 'value', array('name' => 'phpunittest')); } catch (Exception $e) { // not installed yet initialise_cfg(); return; } if ($dbhash !== core_component::get_all_versions_hash()) { // do not set CFG - the only way forward is to drop and reinstall return; } // standard CFG init initialise_cfg(); }
// Messagelib functions require_once $CFG->libdir . '/modinfolib.php'; // Cached information on course-module instances // make sure PHP is not severly misconfigured setup_validate_php_configuration(); // Connect to the database setup_DB(); // Disable errors for now - needed for installation when debug enabled in config.php if (isset($CFG->debug)) { $originalconfigdebug = $CFG->debug; unset($CFG->debug); } else { $originalconfigdebug = -1; } // Load up any configuration from the config table initialise_cfg(); // Verify upgrade is not running unless we are in a script that needs to execute in any case if (!defined('NO_UPGRADE_CHECK') and isset($CFG->upgraderunning)) { if ($CFG->upgraderunning < time()) { unset_config('upgraderunning'); } else { print_error('upgraderunning'); } } // Turn on SQL logging if required if (!empty($CFG->logsql)) { $DB->set_logging(true); } // Prevent warnings from roles when upgrading with debug on if (isset($CFG->debug)) { $originaldatabasedebug = $CFG->debug;
/** * 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(); }
function costcenter_custom_contexts_setup() { global $CFG; static $customcontexts = array( 27 => 'context_costcenter' ); // save any existing custom contexts $existingcustomcontexts = get_config(null, 'custom_context_classes'); set_config('custom_context_classes', serialize($customcontexts)); initialise_cfg(); context_helper::reset_levels(); $alllevels = context_helper::get_all_levels(); }
/** * Test case for custom context classes */ public function test_customcontexts() { global $CFG; static $customcontexts = array(11 => 'context_bogus1', 12 => 'context_bogus2', 13 => 'context_bogus3'); // save any existing custom contexts $existingcustomcontexts = get_config(null, 'custom_context_classes'); set_config('custom_context_classes', serialize($customcontexts)); initialise_cfg(); context_helper::reset_levels(); $alllevels = context_helper::get_all_levels(); $this->assertEquals($alllevels[11], 'context_bogus1'); $this->assertEquals($alllevels[12], 'context_bogus2'); $this->assertEquals($alllevels[13], 'context_bogus3'); // clean-up & restore any custom contexts set_config('custom_context_classes', $existingcustomcontexts === false ? null : $existingcustomcontexts); initialise_cfg(); context_helper::reset_levels(); }