diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index a83b66398368a..d140667ac0e91 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * CLI script + * CLI tests runner * * @package tool_behat * @copyright 2012 David Monllaó @@ -28,13 +28,13 @@ require_once($CFG->libdir . '/clilib.php'); require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/behat/locallib.php'); -// now get cli options +// CLI options. list($options, $unrecognized) = cli_get_params( array( 'help' => false, 'runtests' => false, 'tags' => false, - 'extra' => false, + 'extra' => '', 'with-javascript' => false, 'testenvironment' => false ), @@ -57,7 +57,7 @@ Example from Moodle root directory: \$ php admin/tool/behat/cli/util.php --runtests --tags=\"tool_behat\" -More info in http://docs.moodle.org/dev/Acceptance_testing#Usage +More info in http://docs.moodle.org/dev/Acceptance_testing#Running_tests "; if (!empty($options['help'])) { diff --git a/admin/tool/behat/index.php b/admin/tool/behat/index.php index 31653c42a19fa..f2da7e193c902 100644 --- a/admin/tool/behat/index.php +++ b/admin/tool/behat/index.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Behat web runner + * Web interface to list and filter steps * * @package tool_behat * @copyright 2012 David Monllaó @@ -40,9 +40,12 @@ '' => get_string('allavailablesteps', 'tool_behat'), 'nomoodle' => get_string('nomoodlesteps', 'tool_behat'), ); + +// Complete the components list with the moodle steps definitions. $components = tool_behat::get_components_steps_definitions(); if ($components) { foreach ($components as $component => $filepath) { + // TODO Use a class static attribute instead of the class name. $componentswithsteps[$component] = 'Moodle ' . substr($component, 6); } } diff --git a/admin/tool/behat/lang/en/tool_behat.php b/admin/tool/behat/lang/en/tool_behat.php index 4d1784a3af77e..3d732f9c6d599 100644 --- a/admin/tool/behat/lang/en/tool_behat.php +++ b/admin/tool/behat/lang/en/tool_behat.php @@ -22,12 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['actionnotsupported'] = 'Action not supported'; $string['allavailablesteps'] = 'All the available steps'; -$string['commandinfo'] = 'Info'; -$string['commandruntests'] = 'Run tests'; -$string['commandstepsdefinitions'] = 'Steps definitions list'; -$string['commandswitchenvironment'] = 'Switch environment'; $string['finished'] = 'Process finished'; $string['giveninfo'] = 'Given. Processes to set up the environment'; $string['installinfo'] = 'for installation and tests execution info'; @@ -37,6 +32,7 @@ $string['nomoodlesteps'] = 'Generic web application steps'; $string['nostepsdefinitions'] = 'There aren\'t steps definitions matching this filter'; $string['pluginname'] = 'Acceptance testing'; +$string['phpunitenvproblem'] = 'PHPUnit environment problem'; $string['stepsdefinitionscomponent'] = 'Area'; $string['stepsdefinitionscontains'] = 'Contains'; $string['stepsdefinitionsfilters'] = 'Steps definitions'; @@ -44,4 +40,4 @@ $string['theninfo'] = 'Then. Checkings to ensure the outcomes are the expected ones'; $string['viewsteps'] = 'Filter'; $string['wheninfo'] = 'When. Actions that provokes an event'; -$string['wrongbehatsetup'] = 'Something is wrong with the setup, ensure you ran the composer installer and your /lib/behat/bin/behat file has execution permissions'; +$string['wrongbehatsetup'] = 'Something is wrong with the setup, ensure you ran the composer installer and /lib/behat/bin/behat file has execution permissions'; diff --git a/admin/tool/behat/locallib.php b/admin/tool/behat/locallib.php index ea9f51296746b..f784b3b44a3fa 100644 --- a/admin/tool/behat/locallib.php +++ b/admin/tool/behat/locallib.php @@ -49,6 +49,7 @@ class tool_behat { */ private static $steps_types = array('given', 'when', 'then'); + /** @var string Docu url */ public static $docsurl = 'http://docs.moodle.org/dev/Acceptance_testing'; /** @@ -67,6 +68,7 @@ public static function stepsdefinitions($type, $component, $filter) { // The loaded steps depends on the component specified. self::update_config_file($component); + // The Moodle\BehatExtension\HelpPrinter\MoodleDefinitionsPrinter will parse this search format. if ($type) { $filter .= '&&' . $type; } @@ -118,13 +120,14 @@ public static function switchenvironment($testenvironment = false) { /** * Runs the acceptance tests * - * It starts test mode and runs the built-in php - * CLI server and stops it all then it's done + * It starts test mode and runs the built-in PHP + * erver and stops it all then it's done * + * @param boolean $withjavascript Include tests with javascript * @param string $tags Restricts the executed tests to the ones that matches the tags * @param string $extra Extra CLI behat options */ - public static function runtests($withjavascript = false, $tags = false, $extra = false) { + public static function runtests($withjavascript = false, $tags = false, $extra = '') { global $CFG; // Checks that the behat reference is properly set up. @@ -133,30 +136,27 @@ public static function runtests($withjavascript = false, $tags = false, $extra = // Check that PHPUnit test environment is correctly set up. self::test_environment_problem(); + // Updates all the Moodle features and steps definitions. self::update_config_file(); @set_time_limit(0); // No javascript by default. if (!$withjavascript && strstr($tags, 'javascript') == false) { - $jsstr = '~javascript'; + $jsstr = '~@javascript'; } // Adding javascript option to --tags. $tagsoption = ''; if ($tags) { if (!empty($jsstr)) { - $tags .= ',' . $jsstr; + $tags .= '&&' . $jsstr; } - $tagsoption = ' --tags ' . $tags; + $tagsoption = " --tags '" . $tags . "'"; // No javascript by default. } else if (!empty($jsstr)) { - $tagsoption = ' --tags ' . $jsstr; - } - - if (!$extra) { - $extra = ''; + $tagsoption = " --tags '" . $jsstr . "'"; } // Starts built-in server and inits test mode. @@ -196,7 +196,8 @@ private static function update_config_file($component = '') { $loadbuiltincontexts = '1'; } - // Basic behat dependencies. + // Behat config file specifing the main context class, + // the required Behat extensions and Moodle test wwwroot. $contents = 'default: paths: features: ' . $behatpath . '/features @@ -246,7 +247,6 @@ class: behat_init_context } - /** * Gets the list of Moodle steps definitions * @@ -309,15 +309,12 @@ private static function clean_path($path) { private static function test_environment_problem() { global $CFG; - // phpunit --diag returns nothing if the test environment is set up correctly. - $currentcwd = getcwd(); - chdir($CFG->dirroot . '/' . $CFG->admin . '/tool/phpunit/cli'); - exec("php util.php --diag", $output, $code); - chdir($currentcwd); + // PHPUnit --diag returns nothing if the test environment is set up correctly. + exec('php ' . $CFG->dirroot . '/' . $CFG->admin . '/tool/phpunit/cli/util.php --diag', $output, $code); // If something is not ready stop execution and display the CLI command output. if ($code != 0) { - notice(implode(' ', $output)); + notice(get_string('phpunitenvproblem', 'tool_behat') . ': ' . implode(' ', $output)); } } @@ -336,11 +333,9 @@ private static function check_behat_setup() { $msg = get_string('wrongbehatsetup', 'tool_behat'); // With HTML. - $docslink = tool_behat::$docsurl; + $docslink = tool_behat::$docsurl . '#Installation'; if (!CLI_SCRIPT) { $docslink = html_writer::tag('a', $docslink, array('href' => $docslink, 'target' => '_blank')); - $systempathsurl = $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=systempaths'; - $msg .= ' (' . html_writer::tag('a', get_string('systempaths', 'admin'), array('href' => $systempathsurl)) . ')'; } $msg .= '. ' . get_string('moreinfoin', 'tool_behat') . ' ' . $docslink; notice($msg); @@ -360,12 +355,10 @@ private static function check_behat_setup() { /** * Enables test mode * - * Stores a file in dataroot/behat to - * allow Moodle to switch to the test - * database and dataroot before the initial setup + * Stores a file in dataroot/behat to allow Moodle to switch + * to the test environment when using cli-server * * @throws file_exception - * @return array */ private static function start_test_mode() { global $CFG; @@ -413,6 +406,7 @@ private static function start_test_server() { /** * Disables test mode + * @throws file_exception */ private static function stop_test_mode() { @@ -451,12 +445,12 @@ private static function stop_test_server($process, $pipes) { /** * Checks whether test environment is enabled or disabled * - * It does not return if the current script is running - * in test environment {@see tool_behat::is_test_environment_running()} + * To check is the current script is running in the test + * environment {@see tool_behat::is_test_environment_running()} * * @return bool */ - private static function is_test_mode_enabled() { + public static function is_test_mode_enabled() { $testenvfile = self::get_test_filepath(); if (file_exists($testenvfile)) { @@ -473,7 +467,7 @@ private static function is_test_mode_enabled() { private static function is_test_environment_running() { global $CFG; - if (!empty($CFG->originaldataroot) && php_sapi_name() === 'cli-server') { + if (!empty($CFG->originaldataroot) || defined('BEHAT_RUNNING')) { return true; } diff --git a/admin/tool/behat/renderer.php b/admin/tool/behat/renderer.php index 6bba742b25733..5bd98c02f2520 100644 --- a/admin/tool/behat/renderer.php +++ b/admin/tool/behat/renderer.php @@ -22,9 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; /** * Renderer for behat tool web features diff --git a/admin/tool/behat/settings.php b/admin/tool/behat/settings.php index 5e1982b0ac534..8939cdd84d9ae 100644 --- a/admin/tool/behat/settings.php +++ b/admin/tool/behat/settings.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * PHPunit integration + * Adds behat tests link in admin tree * * @package tool_behat * @copyright 2012 David Monllaó diff --git a/admin/tool/behat/steps_definitions_form.php b/admin/tool/behat/steps_definitions_form.php index c7c0d772de53d..8a993e72c9a48 100644 --- a/admin/tool/behat/steps_definitions_form.php +++ b/admin/tool/behat/steps_definitions_form.php @@ -22,8 +22,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once($CFG->libdir.'/formslib.php'); +defined('MOODLE_INTERNAL') || die(); +require_once($CFG->libdir.'/formslib.php'); /** * Form to display the available steps definitions @@ -39,7 +40,7 @@ class steps_definitions_form extends moodleform { */ function definition() { - $mform =& $this->_form; + $mform = $this->_form; $mform->addElement('header', 'filters', get_string('stepsdefinitionsfilters', 'tool_behat')); diff --git a/admin/tool/behat/styles.css b/admin/tool/behat/styles.css index 5cb0815277d94..9f9bb963915da 100644 --- a/admin/tool/behat/styles.css +++ b/admin/tool/behat/styles.css @@ -1,7 +1,5 @@ -#region-main-box #behat .summary { position: relative;} -#page-admin-tool-behat-index{padding-top: 0px;} div#steps-definitions{border-style:solid;border-width:1px;border-color:#BBB;padding:5px;margin:auto;width:50%;} div#steps-definitions .step{margin: 10px 0px 10px 0px;} div#steps-definitions .stepdescription{color:#bf8c12;} div#steps-definitions .steptype{color:#1467a6;margin-right: 5px;} -div#steps-definitions .stepregex{color:#060;} \ No newline at end of file +div#steps-definitions .stepregex{color:#060;} diff --git a/admin/tool/behat/version.php b/admin/tool/behat/version.php index 5c592c0ba915e..7d7e0368efb1d 100644 --- a/admin/tool/behat/version.php +++ b/admin/tool/behat/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2012110400; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2012061700; // Requires this Moodle version -$plugin->component = 'tool_behat'; // Full name of the plugin (used for diagnostics) +$plugin->version = 2012120700; +$plugin->requires = 2012120300; // Requires Moodle 2.5 +$plugin->component = 'tool_behat'; diff --git a/config-dist.php b/config-dist.php index cb1aa0d25d5fb..edfffcd7c6b5a 100644 --- a/config-dist.php +++ b/config-dist.php @@ -536,11 +536,18 @@ // 'otherplugin' => array('mysetting' => 'myvalue', 'thesetting' => 'thevalue')); // //========================================================================= -// 9. PHPUNIT SUPPORT +// 10. PHPUNIT SUPPORT //========================================================================= // $CFG->phpunit_prefix = 'phpu_'; // $CFG->phpunit_dataroot = '/home/example/phpu_moodledata'; // $CFG->phpunit_directorypermissions = 02777; // optional +// +//========================================================================= +// 11. BEHAT SUPPORT +//========================================================================= +// Behat uses http://localhost:8000 as default URL to run +// the acceptance tests, you can override this value +// $CFG->test_wwwroot = ''; //========================================================================= // ALL DONE! To continue installation, visit your main page with a browser diff --git a/lib/setup.php b/lib/setup.php index 6aa94b7799e13..687a8691e9484 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -95,7 +95,8 @@ $CFG->test_wwwroot = 'http://localhost:8000'; } -// Switch to test site only when test environment is enabled. +// 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;