mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-39478 behat: New constant to detect when the test site is running
Also removing an unused var and method.
This commit is contained in:
parent
081bfdc5ff
commit
cfcbc34a61
@ -250,7 +250,6 @@ class behat_util extends testing_util {
|
||||
* To check is the current script is running in the test
|
||||
* environment
|
||||
*
|
||||
* @see tool_behat::is_using_test_environment()
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_test_mode_enabled() {
|
||||
@ -263,20 +262,6 @@ class behat_util extends testing_util {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Moodle is currently running with the test database and dataroot
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_using_test_environment() {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($CFG->originaldataroot)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the file which specifies if test environment is enabled
|
||||
* @return string
|
||||
|
@ -1128,7 +1128,7 @@ function session_set_user($user) {
|
||||
}
|
||||
sesskey(); // init session key
|
||||
|
||||
if (PHPUNIT_TEST || defined('BEHAT_RUNNING')) {
|
||||
if (PHPUNIT_TEST || defined('BEHAT_TEST')) {
|
||||
// phpunit tests use reversed reference
|
||||
global $USER;
|
||||
$USER = $_SESSION['USER'];
|
||||
|
@ -113,16 +113,25 @@ if (!empty($CFG->behat_dataroot) && !empty($CFG->behat_prefix) && file_exists($C
|
||||
|
||||
$switchcompletely = !empty($CFG->behat_switchcompletely) && php_sapi_name() !== 'cli';
|
||||
$builtinserver = php_sapi_name() === 'cli-server';
|
||||
$behatrunning = defined('BEHAT_RUNNING');
|
||||
$behatrunning = defined('BEHAT_TEST');
|
||||
$testenvironmentrequested = $switchcompletely || $builtinserver || $behatrunning;
|
||||
|
||||
// Only switch to test environment if it has been enabled.
|
||||
$testenvironmentenabled = file_exists($CFG->behat_dataroot . '/behat/test_environment_enabled.txt');
|
||||
|
||||
if ($testenvironmentenabled && $testenvironmentrequested) {
|
||||
|
||||
// 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);
|
||||
|
||||
$CFG->wwwroot = $CFG->behat_wwwroot;
|
||||
$CFG->passwordsaltmain = 'moodle';
|
||||
$CFG->originaldataroot = $CFG->dataroot;
|
||||
$CFG->prefix = $CFG->behat_prefix;
|
||||
$CFG->dataroot = $CFG->behat_dataroot;
|
||||
}
|
||||
@ -455,8 +464,9 @@ if (!PHPUNIT_TEST or PHPUNIT_UTIL) {
|
||||
set_error_handler('default_error_handler', E_ALL | E_STRICT);
|
||||
}
|
||||
|
||||
// Acceptance tests needs special output to capture the errors.
|
||||
if (!empty($CFG->originaldataroot) && !defined('BEHAT_RUNNING')) {
|
||||
// Acceptance tests needs special output to capture the errors,
|
||||
// but not necessary for behat CLI command.
|
||||
if (defined('BEHAT_SITE_RUNNING') && !defined('BEHAT_TEST')) {
|
||||
require_once(__DIR__ . '/behat/lib.php');
|
||||
set_error_handler('behat_error_handler', E_ALL | E_STRICT);
|
||||
}
|
||||
|
@ -65,11 +65,14 @@ class behat_hooks extends behat_base {
|
||||
public static function before_suite($event) {
|
||||
global $CFG;
|
||||
|
||||
// To work with behat_dataroot and behat_prefix instead of the regular environment.
|
||||
define('BEHAT_RUNNING', 1);
|
||||
// Defined only when the behat CLI command is running, the moodle init setup process will
|
||||
// read this value and switch to $CFG->behat_dataroot and $CFG->behat_prefix instead of
|
||||
// the normal site.
|
||||
define('BEHAT_TEST', 1);
|
||||
|
||||
define('CLI_SCRIPT', 1);
|
||||
|
||||
// With BEHAT_RUNNING we will be using $CFG->behat_* instead of $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.
|
||||
// With BEHAT_TEST we will be using $CFG->behat_* instead of $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
|
||||
// Now that we are MOODLE_INTERNAL.
|
||||
@ -109,11 +112,11 @@ class behat_hooks extends behat_base {
|
||||
global $DB, $SESSION, $CFG;
|
||||
|
||||
// As many checks as we can.
|
||||
if (!defined('BEHAT_RUNNING') ||
|
||||
if (!defined('BEHAT_TEST') ||
|
||||
!defined('BEHAT_SITE_RUNNING') ||
|
||||
php_sapi_name() != 'cli' ||
|
||||
!behat_util::is_test_mode_enabled() ||
|
||||
!behat_util::is_test_site() ||
|
||||
!isset($CFG->originaldataroot)) {
|
||||
!behat_util::is_test_site()) {
|
||||
throw new coding_exception('Behat only can modify the test database and the test dataroot!');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user