Commit cb18fd71 authored by David Monllaó's avatar David Monllaó
Browse files

MDL-37046 behat: Using moodle composer

parent d46340eb
......@@ -34,7 +34,6 @@ $string['installinfo'] = 'for installation and tests execution info';
$string['moreinfoin'] = 'More info in';
$string['newstepsinfo'] = 'for info about adding new steps definitions';
$string['newtestsinfo'] = 'for info about writting new tests';
$string['nobehatpath'] = 'Behat path not found, use \'behatpath\' setting to specify it';
$string['nomoodlesteps'] = 'Generic web application steps';
$string['nostepsdefinitions'] = 'There aren\'t steps definitions matching this filter';
$string['pluginname'] = 'Acceptance testing';
......@@ -45,4 +44,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, check moodle-acceptance-tests runs well on CLI and check your \'behatpath\' setting value is pointing to the right directory';
$string['wrongbehatsetup'] = 'Something is wrong with the setup, ensure you ran the composer installer and your /lib/behat/bin/behat file has execution permissions';
......@@ -78,7 +78,7 @@ class tool_behat {
}
$currentcwd = getcwd();
chdir($CFG->behatpath);
chdir($CFG->dirroot . '/lib/behat');
exec('bin/behat --config="' . self::get_behat_config_filepath() . '" ' . $filteroption, $steps, $code);
chdir($currentcwd);
......@@ -163,9 +163,9 @@ class tool_behat {
self::start_test_mode();
$server = self::start_test_server();
// Runs the tests switching the current working directory to CFG->behatpath.
// Runs the tests switching the current working directory to behat path.
$currentcwd = getcwd();
chdir($CFG->behatpath);
chdir($CFG->dirroot . '/lib/behat');
ob_start();
passthru('bin/behat --ansi --config="' . self::get_behat_config_filepath() .'" ' . $tagsoption . ' ' .$extra, $code);
$output = ob_get_contents();
......@@ -188,7 +188,7 @@ class tool_behat {
private static function update_config_file($component = '') {
global $CFG;
$behatpath = rtrim($CFG->behatpath, '/');
$behatpath = $CFG->dirroot . '/lib/behat';
// Not extra contexts when component is specified.
$loadbuiltincontexts = '0';
......@@ -202,6 +202,7 @@ class tool_behat {
features: ' . $behatpath . '/features
bootstrap: ' . $behatpath . '/features/bootstrap
context:
class: behat_init_context
parameters:
loadbuiltincontexts: ' . $loadbuiltincontexts . '
extensions:
......@@ -209,13 +210,7 @@ class tool_behat {
base_url: ' . $CFG->test_wwwroot . '
goutte: ~
selenium2: ~
Sanpi\Behatch\Extension:
contexts:
browser: ~
system: ~
json: ~
table: ~
' . $behatpath . '/vendor/moodlehq/behat-extension/init.php:
' . $CFG->dirroot . '/vendor/moodlehq/behat-extension/init.php:
';
// Gets all the components with features.
......@@ -329,15 +324,16 @@ class tool_behat {
/**
* Checks if behat is set up and working
*
* It checks the behatpath setting value and runs the
* behat help command to ensure it works as expected
* It checks behat dependencies have been installed and runs
* the behat help command to ensure it works as expected
*/
private static function check_behat_setup() {
global $CFG;
// Moodle setting.
if (empty($CFG->behatpath)) {
$msg = get_string('nobehatpath', 'tool_behat');
if (!is_dir($vendor = __DIR__ . '/../../../vendor')) {
$msg = get_string('wrongbehatsetup', 'tool_behat');
// With HTML.
$docslink = tool_behat::$docsurl;
......@@ -352,7 +348,7 @@ class tool_behat {
// Behat test command.
$currentcwd = getcwd();
chdir($CFG->behatpath);
chdir($CFG->dirroot . '/lib/behat');
exec('bin/behat --help', $output, $code);
chdir($currentcwd);
......
{
"repositories" : [
{
"type": "vcs",
"url": "https://github.com/moodlehq/moodle-behat-extension"
}
],
"require-dev": {
"phpunit/phpunit": "3.7.*",
"phpunit/dbUnit": "1.2.*"
"moodlehq/behat-extension": "1.0.3"
}
}
\ No newline at end of file
}
#!/usr/bin/env php
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mimics default bin/behat command to keep it in it's sandbox
*
* @package core
* @category behat
* @copyright 2012 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('BEHAT_PHP_BIN_PATH', getenv('PHP_PEAR_PHP_BIN') ?: '/usr/bin/env php');
define('BEHAT_BIN_PATH', __FILE__);
define('BEHAT_VERSION', 'DEV');
// vendor directory existence checked in tool_behat::check_behat_config().
$vendor = __DIR__.'/../../../vendor';
require($vendor.'/autoload.php');
$app = new Behat\Behat\Console\BehatApplication(BEHAT_VERSION);
$app->run();
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contexts initializer class
*
* @package core
* @category behat
* @copyright 2012 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use Behat\Behat\Context\BehatContext,
Behat\MinkExtension\Context\MinkContext,
Moodle\BehatExtension\Context\MoodleContext;
/**
* Loads main subcontexts
*
* Loading of moodle subcontexts is done by the Moodle extension
*
* Renamed from behat FeatureContext class according
* to Moodle coding styles conventions
*
* @package core
* @category behat
* @copyright 2012 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_init_context extends BehatContext {
/**
* Initializes subcontexts
*
* @param array $parameters context parameters (set them up through behat.yml)
*/
public function __construct(array $parameters) {
// Only load all subcontext if specified.
if ($parameters['loadbuiltincontexts']) {
$this->useContext('mink', new MinkContext($parameters));
}
$this->useContext('moodle', new MoodleContext($parameters));
}
}
......@@ -96,7 +96,7 @@ if (!isset($CFG->test_wwwroot)) {
}
// Switch to test site only when test environment is enabled.
if ((php_sapi_name() === 'cli-server' || defined('BEHAT_RUNNING')) &&
if ((php_sapi_name() === 'cli-server' || defined('BEHAT_RUNNING')) &&
file_exists($CFG->dataroot . '/behat/test_environment_enabled.txt')) {
$CFG->wwwroot = $CFG->test_wwwroot;
$CFG->passwordsaltmain = 'phpunit';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment