Merge branch 'MDL-66836-master' of https://github.com/sammarshallou/moodle

This commit is contained in:
Sara Arjona 2019-10-14 12:26:49 +02:00
commit ef2f26b8b1
2 changed files with 26 additions and 0 deletions

View File

@ -345,6 +345,23 @@ class behat_util extends testing_util {
return behat_command::get_parent_behat_dir() . '/test_environment_enabled.txt';
}
/**
* Removes config settings that were added to the main $CFG config within the Behat CLI
* run.
*
* Database storage is already handled by reset_database and existing config values will
* be reset automatically by initialise_cfg(), so we only need to remove added ones.
*/
public static function remove_added_config() {
global $CFG;
if (!empty($CFG->behat_cli_added_config)) {
foreach ($CFG->behat_cli_added_config as $key => $value) {
unset($CFG->{$key});
}
unset($CFG->behat_cli_added_config);
}
}
/**
* Reset contents of all database tables to initial values, reset caches, etc.
*/
@ -375,6 +392,7 @@ class behat_util extends testing_util {
// 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.
self::remove_added_config();
initialise_cfg();
}

View File

@ -1405,6 +1405,14 @@ function set_config($name, $value, $plugin=null) {
$config->value = $value;
$DB->insert_record('config', $config, false);
}
// When setting config during a Behat test (in the CLI script, not in the web browser
// requests), remember which ones are set so that we can clear them later.
if (defined('BEHAT_TEST')) {
if (!property_exists($CFG, 'behat_cli_added_config')) {
$CFG->behat_cli_added_config = [];
}
$CFG->behat_cli_added_config[$name] = true;
}
}
if ($name === 'siteidentifier') {
cache_helper::update_site_identifier($value);