From ac41f878da58ad9cf48df5660414718424ec604a Mon Sep 17 00:00:00 2001 From: David Monllao Date: Tue, 19 Feb 2013 17:58:58 +0800 Subject: [PATCH] MDL-38007 behat: Adding new script using util.php --- admin/tool/behat/cli/init.php | 98 +++++++++++++++++++++++++++++++++++ admin/tool/behat/cli/util.php | 5 ++ 2 files changed, 103 insertions(+) create mode 100644 admin/tool/behat/cli/init.php diff --git a/admin/tool/behat/cli/init.php b/admin/tool/behat/cli/init.php new file mode 100644 index 00000000000..8162b0ef20e --- /dev/null +++ b/admin/tool/behat/cli/init.php @@ -0,0 +1,98 @@ +. + +/** + * CLI script to set up all the behat test environment. + * + * @package tool_behat + * @copyright 2013 David Monllaó + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +if (isset($_SERVER['REMOTE_ADDR'])) { + die(); // No access from web! +} + +// Is not really necessary but adding it as is a CLI_SCRIPT. +define('CLI_SCRIPT', true); + +// Basic functions. +require_once(__DIR__ . '/../../../../lib/clilib.php'); +require_once(__DIR__ . '/../../../../lib/behat/lib.php'); + +// Changing the cwd to admin/tool/behat/cli. +chdir(__DIR__); +$output = null; +exec("php util.php --diag", $output, $code); +if ($code == 0) { + echo "Behat test environment already installed\n"; + +} else if ($code == BEHAT_EXITCODE_INSTALL) { + // Behat and dependencies are installed and we need to install the test site. + passthru("php util.php --install", $code); + if ($code != 0) { + exit($code); + } + +} else if ($code == BEHAT_EXITCODE_REINSTALL) { + // Test site data is outdated. + passthru("php util.php --drop", $code); + if ($code != 0) { + exit($code); + } + + passthru("php util.php --install", $code); + if ($code != 0) { + exit($code); + } + +} else if ($code == BEHAT_EXITCODE_COMPOSER) { + // Missing Behat dependencies. + + // Changing to moodle dirroot to run composer related commands at project level. + chdir(__DIR__ . '/../../../..'); + if (!file_exists(__DIR__ . '/../../../../composer.phar')) { + passthru("curl http://getcomposer.org/install | php", $code); + if ($code != 0) { + exit($code); + } + } + + passthru("php composer.phar install --dev", $code); + if ($code != 0) { + exit($code); + } + + // Returning to admin/tool/behat/cli. + chdir(__DIR__); + passthru("php util.php --install", $code); + if ($code != 0) { + exit($code); + } + +} else { + // Generic error, we just output it. + echo implode("\n", $output)."\n"; + exit($code); +} + +// Enable editing mode according to config.php vars. +passthru("php util.php --enable", $code); +if ($code != 0) { + exit($code); +} + +exit(0); diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index 8cba36702b1..e4e3d6e4738 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -43,6 +43,7 @@ list($options, $unrecognized) = cli_get_params( 'drop' => false, 'enable' => false, 'disable' => false, + 'diag' => false ), array( 'h' => 'help' @@ -59,6 +60,7 @@ Options: --drop Drops the database tables and the dataroot contents --enable Enables test environment and updates tests list --disable Disables test environment +--diag Get behat test environment status code -h, --help Print out this help @@ -183,6 +185,9 @@ if ($options['install']) { } else if ($options['disable']) { behat_util::stop_test_mode(); mtrace("Acceptance tests environment disabled"); +} else if ($options['diag']) { + $code = behat_util::get_behat_status(); + exit($code); } else { echo $help; }