Merge branch 'w51_MDL-43213_m27_simplebehat' of https://github.com/skodak/moodle

This commit is contained in:
Sam Hemelryk
2013-12-18 10:30:30 +13:00
9 changed files with 161 additions and 235 deletions
+39 -78
View File
@@ -59,6 +59,45 @@ if (!isset($CFG)) {
// it can not be anything else, there is no point in having this in config.php
$CFG->dirroot = dirname(dirname(__FILE__));
if (defined('BEHAT_SITE_RUNNING')) {
// We already switched to behat test site previously.
} else if (!empty($CFG->behat_wwwroot) or !empty($CFG->behat_dataroot) or !empty($CFG->behat_prefix)) {
// The behat is configured on this server, we need to find out if this is the behat test
// site based on the URL used for access.
require_once(__DIR__ . '/../lib/behat/lib.php');
if (behat_is_test_site()) {
// Checking the integrity of the provided $CFG->behat_* vars and the
// selected wwwroot to prevent conflicts with production and phpunit environments.
behat_check_config_vars();
if (!defined('BEHAT_UTIL') and !defined('BEHAT_TEST')) {
// Somebody tries to access test site directly, tell them if not enabled.
if (!file_exists($CFG->behat_dataroot . '/behat/test_environment_enabled.txt')) {
behat_error(BEHAT_EXITCODE_CONFIG, 'Behat is configured but not enabled on this test site.');
}
}
// Constant used to inform that the behat test site is being used,
// this includes all the processes executed by the behat CLI command like
// the site reset, the steps executed by the browser drivers when simulating
// a user session and a real session when browsing manually to $CFG->behat_wwwroot
// like the browser driver does automatically.
// Different from BEHAT_TEST as only this last one can perform CLI
// actions like reset the site or use data generators.
define('BEHAT_SITE_RUNNING', true);
// Clean extra config.php settings.
behat_clean_init_config();
// Now we can begin switching $CFG->X for $CFG->behat_X.
$CFG->wwwroot = $CFG->behat_wwwroot;
$CFG->passwordsaltmain = 'moodle';
$CFG->prefix = $CFG->behat_prefix;
$CFG->dataroot = $CFG->behat_dataroot;
}
}
// Normalise dataroot - we do not want any symbolic links, trailing / or any other weirdness there
if (!isset($CFG->dataroot)) {
if (isset($_SERVER['REMOTE_ADDR'])) {
@@ -91,84 +130,6 @@ if (!isset($CFG->wwwroot) or $CFG->wwwroot === 'http://example.com/moodle') {
exit(1);
}
// Test environment is requested if:
// * If $CFG->behat_switchcompletely has been set (maintains CLI scripts behaviour, which ATM is only preventive).
// * If we are accessing though the built-in web server (cli-server).
// * Behat is running (constant set hooking the behat init process before requiring config.php).
// * If $CFG->behat_wwwroot has been set and the hostname/port match what the page was requested with.
// Test environment is enabled if:
// * User has previously enabled through admin/tool/behat/cli/util.php --enable or admin/tool/behat/cli/init.php
// Both are required to switch to test mode
if (!defined('BEHAT_SITE_RUNNING') && !empty($CFG->behat_dataroot) &&
!empty($CFG->behat_prefix) && file_exists($CFG->behat_dataroot)) {
// Only included if behat_* are set, it is not likely to be a production site.
require_once(__DIR__ . '/../lib/behat/lib.php');
$defaultbehatwwwroot = behat_get_wwwroot();
if (!empty($CFG->behat_switchcompletely) && php_sapi_name() !== 'cli') {
// Switch completely uses the production wwwroot as the test site URL.
$behatwwwroot = $defaultbehatwwwroot;
} elseif (php_sapi_name() === 'cli-server') {
// If we are using the built-in server we use the provided $CFG->behat_wwwroot
// value or the default one if $CFG->behat_wwwroot is not set, only if it matches
// the requested URL.
if (behat_is_requested_url($defaultbehatwwwroot)) {
$behatwwwroot = $defaultbehatwwwroot;
}
} elseif (defined('BEHAT_TEST')) {
// This is when moodle codebase runs through vendor/bin/behat, we "are not supposed"
// to need a wwwroot, but before using the production one we should set something else
// as an alternative.
$behatwwwroot = $defaultbehatwwwroot;
} elseif (!empty($CFG->behat_wwwroot) && !empty($_SERVER['HTTP_HOST'])) {
// If $CFG->behat_wwwroot was set and matches the requested URL we
// use $CFG->behat_wwwroot as our wwwroot.
if (behat_is_requested_url($CFG->behat_wwwroot)) {
$behatwwwroot = $CFG->behat_wwwroot;
}
}
// If we found a proper behatwwwroot then we consider the behat test as requested.
$testenvironmentrequested = !empty($behatwwwroot);
// Only switch to test environment if it has been enabled.
$CFG->behat_dataroot = realpath($CFG->behat_dataroot);
$testenvironmentenabled = file_exists($CFG->behat_dataroot . '/behat/test_environment_enabled.txt');
if ($testenvironmentenabled && $testenvironmentrequested) {
// Now we know which one will be our behat wwwroot.
$CFG->behat_wwwroot = $behatwwwroot;
// Checking the integrity of the provided $CFG->behat_* vars and the
// selected wwwroot to prevent conflicts with production and phpunit environments.
behat_check_config_vars();
// Constant used to inform that the behat test site is being used,
// this includes all the processes executed by the behat CLI command like
// the site reset, the steps executed by the browser drivers when simulating
// a user session and a real session when browsing manually to $CFG->behat_wwwroot
// like the browser driver does automatically.
// Different from BEHAT_TEST as only this last one can perform CLI
// actions like reset the site or use data generators.
define('BEHAT_SITE_RUNNING', true);
// Clean extra config.php settings.
behat_clean_init_config();
// Now we can begin switching $CFG->X for $CFG->behat_X.
$CFG->wwwroot = $CFG->behat_wwwroot;
$CFG->passwordsaltmain = 'moodle';
$CFG->prefix = $CFG->behat_prefix;
$CFG->dataroot = $CFG->behat_dataroot;
}
}
// Make sure there is some database table prefix.
if (!isset($CFG->prefix)) {
$CFG->prefix = '';