diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index b28f4fcb6b0..5c24cf8c05d 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -142,6 +142,9 @@ foreach ($vars as $var) { $CFG->{$var} = $CFG->{'behat_' . $var}; } +// Clean $CFG extra values before performing any action. +behat_clean_init_config(); + $CFG->noemailever = true; $CFG->passwordsaltmain = 'moodle'; diff --git a/lib/behat/lib.php b/lib/behat/lib.php index e35b0e6192c..42ed4418ffd 100644 --- a/lib/behat/lib.php +++ b/lib/behat/lib.php @@ -141,3 +141,29 @@ function behat_error_handler($errno, $errstr, $errfile, $errline, $errcontext) { // Also use the internal error handler so we keep the usual behaviour. return false; } + +/** + * Restrict the config.php settings allowed. + * + * When running the behat features the config.php + * settings should not affect the results. + * + * @return void + */ +function behat_clean_init_config() { + global $CFG; + + $allowed = array_flip(array( + 'wwwroot', 'dataroot', 'dirroot', 'admin', 'directorypermissions', 'filepermissions', + 'dbtype', 'dblibrary', 'dbhost', 'dbname', 'dbuser', 'dbpass', 'prefix', 'dboptions', + 'proxyhost', 'proxyport', 'proxytype', 'proxyuser', 'proxypassword', 'proxybypass' + )); + + // Also allowing behat_ prefixed attributes. + foreach ($CFG as $key => $value) { + if (!isset($allowed[$key]) && strpos($key, 'behat_') !== 0) { + unset($CFG->{$key}); + } + } + +} diff --git a/lib/setup.php b/lib/setup.php index 0b9cbd2f40a..c776a891623 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -131,6 +131,10 @@ if (!defined('BEHAT_SITE_RUNNING') && !empty($CFG->behat_dataroot) && // actions like reset the site or use data generators. define('BEHAT_SITE_RUNNING', true); + // Clean extra config.php settings. + require_once(__DIR__ . '/../lib/behat/lib.php'); + behat_clean_init_config(); + $CFG->wwwroot = $CFG->behat_wwwroot; $CFG->passwordsaltmain = 'moodle'; $CFG->prefix = $CFG->behat_prefix;