mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-37046 behat: Requires Moodle 2.5
Also more code comments and general cleanup
This commit is contained in:
parent
fbb5243491
commit
a09534f4fc
@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* CLI script
|
||||
* CLI tests runner
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
@ -28,13 +28,13 @@ require(__DIR__ . '/../../../../config.php');
|
||||
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 @@ Options:
|
||||
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'])) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Behat web runner
|
||||
* Web interface to list and filter steps
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
@ -40,9 +40,12 @@ $componentswithsteps = array(
|
||||
'' => 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);
|
||||
}
|
||||
}
|
||||
|
@ -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['newtestsinfo'] = 'for info about writting new tests';
|
||||
$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['stepsdefinitionstype'] = 'Type';
|
||||
$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';
|
||||
|
@ -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 @@ class tool_behat {
|
||||
// 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 @@ class tool_behat {
|
||||
/**
|
||||
* 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 @@ class tool_behat {
|
||||
// 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 @@ class tool_behat {
|
||||
$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 tool_behat {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list of Moodle steps definitions
|
||||
*
|
||||
@ -309,15 +309,12 @@ class tool_behat {
|
||||
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 @@ class tool_behat {
|
||||
$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 @@ class tool_behat {
|
||||
/**
|
||||
* 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 @@ class tool_behat {
|
||||
|
||||
/**
|
||||
* Disables test mode
|
||||
* @throws file_exception
|
||||
*/
|
||||
private static function stop_test_mode() {
|
||||
|
||||
@ -451,12 +445,12 @@ class tool_behat {
|
||||
/**
|
||||
* 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 @@ class tool_behat {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* PHPunit integration
|
||||
* Adds behat tests link in admin tree
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
|
@ -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'));
|
||||
|
||||
|
@ -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;}
|
||||
div#steps-definitions .stepregex{color:#060;}
|
||||
|
@ -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';
|
||||
|
@ -536,11 +536,18 @@ $CFG->admin = 'admin';
|
||||
// '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
|
||||
|
@ -95,7 +95,8 @@ if (!isset($CFG->test_wwwroot)) {
|
||||
$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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user