From 554820dd52933e23eef49768449e696f67a75c76 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Tue, 16 Oct 2012 17:32:16 +0800 Subject: [PATCH] MDL-37046 behat: Moving installation instructions to MDocs --- admin/tool/behat/cli/util.php | 5 +++ admin/tool/behat/lang/en/tool_behat.php | 1 - admin/tool/behat/locallib.php | 52 ++++++++----------------- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index 3b5112b975e..1c2f0dd5af2 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -51,6 +51,7 @@ Ensure the user who executes the action has permissions over behat installation Options: --stepsdefinitions Displays the available steps definitions (accepts --filter=\"\" option to restrict the list to the matching definitions) --runtests Runs the tests (accepts --tags=\"\" option to execute only the matching tests and --extra=\"\" to specify extra behat options) +--testenvironment Switches between the real and the test environment (accepts value 'enable' or 'disable', for example --testenvironment=\"enable\" -h, --help Print out this help @@ -90,6 +91,10 @@ switch ($action) { case 'runtests': tool_behat::runtests($options['tags'], $options['extra']); break; + + case 'testenvironment': + tool_behat::switchenvironment($options['testenvironment']); + break; } diff --git a/admin/tool/behat/lang/en/tool_behat.php b/admin/tool/behat/lang/en/tool_behat.php index d19bda32e77..7af0c124b5d 100644 --- a/admin/tool/behat/lang/en/tool_behat.php +++ b/admin/tool/behat/lang/en/tool_behat.php @@ -23,7 +23,6 @@ */ $string['actionnotsupported'] = 'Action not supported'; -$string['buildconfigfileinfo'] = 'Update the list of available acceptance tests'; $string['commandinfo'] = 'Info'; $string['commandruntests'] = 'Run tests'; $string['commandstepsdefinitions'] = 'Steps definitions list'; diff --git a/admin/tool/behat/locallib.php b/admin/tool/behat/locallib.php index 9c953cff3a2..7bd00fe365e 100644 --- a/admin/tool/behat/locallib.php +++ b/admin/tool/behat/locallib.php @@ -44,10 +44,13 @@ class tool_behat { $html = self::get_header(); $html .= self::get_info(); - $html .= self::get_build_config_file_form(); $html .= self::get_switch_environment_form(); - $html .= self::get_steps_definitions_form(); - $html .= self::get_run_tests_form(); + + if (!self::is_test_environment_running()) { + $html .= self::get_steps_definitions_form(); + $html .= self::get_run_tests_form(); + } + $html .= self::get_footer(); echo $html; @@ -128,7 +131,9 @@ class tool_behat { self::disable_test_environment(); } - redirect(get_login_url()); + if (!CLI_SCRIPT) { + redirect(get_login_url()); + } } /** @@ -267,6 +272,7 @@ class tool_behat { * @throws file_exception */ private static function enable_test_environment() { + global $CFG; if (self::is_test_environment_enabled()) { debugging('Test environment was already enabled'); @@ -283,7 +289,7 @@ class tool_behat { if (!file_put_contents($filepath, $contents)) { throw new file_exception('cannotcreatefile', $filepath); } - + chmod($filepath, $CFG->directorypermissions); } /** @@ -310,7 +316,7 @@ class tool_behat { * * @return bool */ - public static function is_test_environment_enabled() { + private static function is_test_environment_enabled() { $testenvfile = self::get_test_filepath(); if (file_exists($testenvfile)) { @@ -324,7 +330,7 @@ class tool_behat { * Returns true if Moodle is currently running with the test database and dataroot * @return bool */ - public static function is_test_environment_running() { + private static function is_test_environment_running() { global $CFG; if (!empty($CFG->originaldataroot)) { @@ -439,17 +445,11 @@ class tool_behat { private static function get_info() { global $OUTPUT; - $html = $OUTPUT->box_start(); - $html .= html_writer::tag('h1', 'Info'); - $info = 'This tool makes use of the phpunit test environment, during the automatic acceptance tests execution the site uses the test database and dataroot directories so this tool IS NOT intended to be used in production sites.'; - $html .= html_writer::tag('div', $info); + $url = 'http://docs.moodle.org/dev/Behat_integration#Installation'; - $html .= html_writer::tag('h1', 'Installation'); - $installinstructions = '1.- Follow the PHPUnit installation instructions to set up the testing environment $CFG->wwwroot/admin/tool/phpunit/index.php
'; - $installinstructions .= '2.- Follow the moodle-acceptance-test installation instructions https://github.com/dmonllao/behat-moodle
'; - $installinstructions .= '3.- Set up the \'config_file_path\' param in /MOODLE-ACCEPTANCE-TEST/ROOT/PATH/behat.yml pointing to $CFG->dataroot/behat/config.yml (for example /YOUR/MOODLEDATA/PATH/behat/config.yml)
'; - $installinstructions .= '4.- Set up $CFG->behatpath in your config.php with the path of your moodle-acceptance-test installation (for example /MOODLE-ACCEPTANCE-TEST/ROOT/PATH)
'; - $html .= html_writer::tag('div', $installinstructions); + $html = $OUTPUT->box_start(); + $html .= html_writer::tag('h1', 'Installation info'); + $html .= html_writer::tag('div', 'Follow ' . $url . ' instructions'); $html .= $OUTPUT->box_end(); return $html; @@ -478,24 +478,6 @@ class tool_behat { return $html; } - /** - * Returns a button to execute the build config file form - * @return string - */ - private static function get_build_config_file_form() { - global $OUTPUT, $CFG; - - $params = array('action' => 'buildconfigfile', 'sesskey' => sesskey()); - $url = new moodle_url('/' . $CFG->admin . '/tool/behat/index.php', $params); - - $html = $OUTPUT->box_start(); - $html .= '

' . get_string('buildconfigfileinfo', 'tool_behat') . '

'; - $html .= $OUTPUT->single_button($url, get_string('commandbuildconfigfile', 'tool_behat')); - $html .= $OUTPUT->box_end(); - - return $html; - } - /** * Returns the steps definitions form * @param string $filter To filter the steps definitions list by keyword