Permalink
Browse files

MDL-41592 behat: Allow alt wwwroot to be set for acceptance testing

To set add $CFG->behat_wwwroot = 'http://alturl'; in your config.php
  • Loading branch information...
1 parent ea04def commit 64c51196378b9bd83c9313b0a15bd896d49bab83 @srynot4sale srynot4sale committed with dmonllao Sep 4, 2013
Showing with 24 additions and 19 deletions.
  1. +2 −2 config-dist.php
  2. +1 −1 lib/behat/classes/behat_command.php
  3. +21 −16 lib/setup.php
View
@@ -589,8 +589,8 @@
// $CFG->behat_prefix = 'bht_';
// $CFG->behat_dataroot = '/home/example/bht_moodledata';
//
-// Behat uses http://localhost:8000 as default URL to run
-// the acceptance tests, you can override this value.
+// To set a seperate wwwroot for Behat to use, set it below.
+// This is set automatically elsewhere when using PHP's built in webserver.
// Example:
// $CFG->behat_wwwroot = 'http://192.168.1.250:8000';
//
@@ -108,7 +108,7 @@ public static function behat_setup_problem($checkphp = false) {
// We don't check the PHP version if $CFG->behat_switchcompletely has been enabled.
// Here we are in CLI.
- if (empty($CFG->behat_switchcompletely) && $checkphp && version_compare(PHP_VERSION, '5.4.0', '<')) {
+ if (empty($CFG->behat_switchcompletely) && empty($CFG->behat_wwwroot) && $checkphp && version_compare(PHP_VERSION, '5.4.0', '<')) {
behat_error(BEHAT_EXITCODE_REQUIREMENT, 'PHP 5.4 is required. See config-dist.php for possible alternatives');
}
View
@@ -91,20 +91,11 @@
exit(1);
}
-// Ignore $CFG->behat_wwwroot and use the same wwwroot.
-if (!empty($CFG->behat_switchcompletely)) {
- $CFG->behat_wwwroot = $CFG->wwwroot;
-
-} else if (empty($CFG->behat_wwwroot)) {
- // Default URL for acceptance testing, only accessible from localhost.
- $CFG->behat_wwwroot = 'http://localhost:8000';
-}
-
-
// Test environment is requested if:
-// * Behat is running (constant set hooking the behat init process before requiring config.php).
-// * If we are accessing though the built-in web server (cli-server).
// * 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.
// Both are required to switch to test mode
@@ -113,10 +104,24 @@
$CFG->behat_dataroot = realpath($CFG->behat_dataroot);
- $switchcompletely = !empty($CFG->behat_switchcompletely) && php_sapi_name() !== 'cli';
- $builtinserver = php_sapi_name() === 'cli-server';
- $behatrunning = defined('BEHAT_TEST');
- $testenvironmentrequested = $switchcompletely || $builtinserver || $behatrunning;
+ if (!empty($CFG->behat_switchcompletely) && php_sapi_name() !== 'cli') {
+ $behatswitchcompletely = true;
+ $CFG->behat_wwwroot = $CFG->wwwroot;
+
+ } elseif (php_sapi_name() === 'cli-server') {
+ $behatbuiltinserver = true;
+ $CFG->behat_wwwroot = 'http://localhost:'.$_SERVER['SERVER_PORT'];
+
+ } elseif (defined('BEHAT_TEST')) {
+ $behatrunning = true;
+
+ } elseif (!empty($CFG->behat_wwwroot) && !empty($_SERVER['HTTP_HOST'])) {
+ $behaturl = parse_url($CFG->behat_wwwroot.'/');
+ $behaturl['port'] = isset($behaturl['port']) ? $behaturl['port'] : 80;
+ $behataltwww = ($behaturl['host'] == $_SERVER['HTTP_HOST']) && ($behaturl['port'] == $_SERVER['SERVER_PORT']);
+ }
+
+ $testenvironmentrequested = !empty($behatswitchcompletely) || !empty($behatbuiltinserver) || !empty($behatrunning) || !empty($behataltwww);
// Only switch to test environment if it has been enabled.
$testenvironmentenabled = file_exists($CFG->behat_dataroot . '/behat/test_environment_enabled.txt');

0 comments on commit 64c5119

Please sign in to comment.