diff --git a/admin/tool/behat/lang/en/tool_behat.php b/admin/tool/behat/lang/en/tool_behat.php index 50ca24fa39ab1..1c723f3a39e7f 100644 --- a/admin/tool/behat/lang/en/tool_behat.php +++ b/admin/tool/behat/lang/en/tool_behat.php @@ -42,4 +42,4 @@ $string['viewsteps'] = 'Filter'; $string['wheninfo'] = 'When. Actions that provokes an event'; $string['wrongphpversion'] = 'PHP 5.4.0 or higher is required to run acceptance tests'; -$string['wrongbehatsetup'] = 'Something is wrong with the setup, ensure you ran the composer installer and /lib/behat/bin/behat file has execution permissions'; +$string['wrongbehatsetup'] = 'Something is wrong with the setup, ensure you ran the composer installer and vendor/bin/behat file has execution permissions'; diff --git a/admin/tool/behat/locallib.php b/admin/tool/behat/locallib.php index 4cab159302c73..07e135fdfdd37 100644 --- a/admin/tool/behat/locallib.php +++ b/admin/tool/behat/locallib.php @@ -194,7 +194,7 @@ protected static function get_config_file_contents($prefix, $features, $stepsdef ), 'extensions' => array( 'Behat\MinkExtension\Extension' => array( - 'base_url' => $CFG->test_wwwroot, + 'base_url' => $CFG->behat_wwwroot, 'goutte' => null, 'selenium2' => null ), @@ -207,8 +207,8 @@ protected static function get_config_file_contents($prefix, $features, $stepsdef ); // In case user defined overrides respect them over our default ones. - if (!empty($CFG->behatconfig)) { - $config = self::merge_config($config, $CFG->behatconfig); + if (!empty($CFG->behat_config)) { + $config = self::merge_config($config, $CFG->behat_config); } return Symfony\Component\Yaml\Yaml::dump($config, 10, 2); @@ -288,7 +288,7 @@ public static function get_components_steps_definitions() { } /** - * Checks if $CFG->test_wwwroot is available + * Checks if $CFG->behat_wwwroot is available * * @return boolean */ @@ -296,7 +296,7 @@ public static function is_server_running() { global $CFG; $request = new curl(); - $request->get($CFG->test_wwwroot); + $request->get($CFG->behat_wwwroot); return (true && !$request->get_errno()); } @@ -347,7 +347,8 @@ protected static function test_environment_problem() { protected static function check_behat_setup($checkphp = false) { global $CFG; - if ($checkphp && version_compare(PHP_VERSION, '5.4.0', '<')) { + // We don't check the PHP version if $CFG->behat_switchcompletely has been enabled. + if (empty($CFG->behat_switchcompletely) && $checkphp && version_compare(PHP_VERSION, '5.4.0', '<')) { throw new Exception(get_string('wrongphpversion', 'tool_behat')); } @@ -384,7 +385,7 @@ protected static function check_behat_setup($checkphp = false) { * features and steps definitions. * * Stores a file in dataroot/behat to allow Moodle to switch - * to the test environment when using cli-server + * to the test environment when using cli-server (or $CFG->behat_switchcompletely) * * @throws file_exception */ @@ -407,7 +408,7 @@ protected static function start_test_mode() { $behatdir = self::get_behat_dir(); - $contents = '$CFG->test_wwwroot, $CFG->phpunit_prefix and $CFG->phpunit_dataroot' . + $contents = '$CFG->behat_wwwroot, $CFG->phpunit_prefix and $CFG->phpunit_dataroot' . ' are currently used as $CFG->wwwroot, $CFG->prefix and $CFG->dataroot'; $filepath = $behatdir . '/test_environment_enabled.txt'; if (!file_put_contents($filepath, $contents)) { diff --git a/admin/tool/behat/tests/tool_behat_test.php b/admin/tool/behat/tests/tool_behat_test.php index 5dc0530672b9c..bdc406e61b02d 100644 --- a/admin/tool/behat/tests/tool_behat_test.php +++ b/admin/tool/behat/tests/tool_behat_test.php @@ -155,7 +155,7 @@ public function test_merge_configs() { public function test_config_file_contents() { global $CFG; - unset($CFG->behatconfig); + unset($CFG->behat_config); // List. $features = array( @@ -174,7 +174,7 @@ public function test_config_file_contents() { $this->assertContains('features: /i/am/a/prefix/lib/behat/features', $contents); $this->assertContains('micarro: /me/lo/robaron', $contents); - $this->assertContains('base_url: \'' . $CFG->test_wwwroot . '\'', $contents); + $this->assertContains('base_url: \'' . $CFG->behat_wwwroot . '\'', $contents); $this->assertContains('class: behat_init_context', $contents); $this->assertContains('- feature1', $contents); $this->assertContains('- feature3', $contents); diff --git a/config-dist.php b/config-dist.php index c0e3090e102d8..aac3a62a2af16 100644 --- a/config-dist.php +++ b/config-dist.php @@ -548,15 +548,15 @@ // Behat uses http://localhost:8000 as default URL to run // the acceptance tests, you can override this value. // Example: -// $CFG->test_wwwroot = 'http://192.168.1.250:8000'; +// $CFG->behat_wwwroot = 'http://192.168.1.250:8000'; // // You can override default Moodle configuration for Behat and add your own // params; here you can add more profiles, use different Mink drivers than Selenium... -// This params will be merged with the default Moodle behat.yml, giving priority -// to the ones specified here. The array format is a YAML following the behat +// This params would be merged with the default Moodle behat.yml, giving priority +// to the ones specified here. The array format is YAML, following the behat // params hierarchy. More info: http://docs.behat.org/guides/7.config.html // Example: -// $CFG->behatconfig = array( +// $CFG->behat_config = array( // 'default' => array( // 'formatter' => array( // 'name' => 'pretty', @@ -568,6 +568,16 @@ // ) // ); // +// You can completely switch to test environment when "php admin/tool/behatcli/util --enable", +// this means that all the site accesses will be routed to the test environment instead of +// the regular one, so NEVER USE THIS SETTING IN PRODUCTION SITES. This setting is useful +// when working with cloud CI (continous integration) servers which requires public sites to run the +// tests, or in testing/development installations when you are developing in a pre-PHP 5.4 server. +// Note that with this setting enabled $CFG->behat_wwwroot is ignored and $CFG->behat_wwwroot +// value will be the regular $CFG->wwwroot value. +// Example: +// $CFG->behat_switchcompletely = true; +// //========================================================================= // ALL DONE! To continue installation, visit your main page with a browser diff --git a/lib/setup.php b/lib/setup.php index 687a8691e9484..279d0add6ee60 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -90,16 +90,24 @@ exit(1); } -// Default URL for acceptance testing. -if (!isset($CFG->test_wwwroot)) { - $CFG->test_wwwroot = 'http://localhost:8000'; -} - -// Switch to test site only when test environment is enabled: Both when the -// acceptance tests are running and when Behat is requiring moodle codebase. -if ((php_sapi_name() === 'cli-server' || defined('BEHAT_RUNNING')) && - file_exists($CFG->dataroot . '/behat/test_environment_enabled.txt')) { - $CFG->wwwroot = $CFG->test_wwwroot; +// Ignore $CFG->behat_wwwroot and use the same wwwroot in case test env. is enabled. +if (isset($CFG->behat_switchcompletely)) { + $CFG->behat_wwwroot = $CFG->wwwroot; + +// Default URL for acceptance testing, only accessible from localhost. +} else if (!isset($CFG->behat_wwwroot)) { + $CFG->behat_wwwroot = 'http://localhost:8000'; +} + +// Test environment is requested if: Behat is running, if we are accessing though cli-server +// or if $CFG->behat_switchcompletely has been set (maintains CLI scripts behaviour). +$testenvironmentrequested = (isset($CFG->behat_switchcompletely) && php_sapi_name() !== 'cli') || + php_sapi_name() === 'cli-server' || + defined('BEHAT_RUNNING'); +// Only switch to test environment if it has been enabled. +$testenvironmentenabled = file_exists($CFG->dataroot . '/behat/test_environment_enabled.txt'); +if ($testenvironmentenabled && $testenvironmentrequested) { + $CFG->wwwroot = $CFG->behat_wwwroot; $CFG->passwordsaltmain = 'phpunit'; $CFG->originaldataroot = $CFG->dataroot; $CFG->prefix = $CFG->phpunit_prefix;