mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-37046_master' of git://github.com/dmonllao/moodle
This commit is contained in:
commit
68aaba6c84
22 changed files with 1673 additions and 8 deletions
182
admin/tool/behat/cli/util.php
Normal file
182
admin/tool/behat/cli/util.php
Normal file
|
@ -0,0 +1,182 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* CLI tool with utilities to manage Behat integration in Moodle
|
||||
*
|
||||
* All CLI utilities uses $CFG->behat_dataroot and $CFG->prefix_dataroot as
|
||||
* $CFG->dataroot and $CFG->prefix
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 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!.
|
||||
}
|
||||
|
||||
// Basic functions.
|
||||
require_once(__DIR__ . '/../../../../lib/clilib.php');
|
||||
require_once(__DIR__ . '/../../../../lib/behat/lib.php');
|
||||
|
||||
|
||||
// CLI options.
|
||||
list($options, $unrecognized) = cli_get_params(
|
||||
array(
|
||||
'help' => false,
|
||||
'install' => false,
|
||||
'drop' => false,
|
||||
'enable' => false,
|
||||
'disable' => false,
|
||||
),
|
||||
array(
|
||||
'h' => 'help'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// Checking util.php CLI script usage.
|
||||
$help = "
|
||||
Behat utilities to manage the test environment
|
||||
|
||||
Options:
|
||||
--install Installs the test environment for acceptance tests
|
||||
--drop Drops the database tables and the dataroot contents
|
||||
--enable Enables test environment and updates tests list
|
||||
--disable Disables test environment
|
||||
|
||||
-h, --help Print out this help
|
||||
|
||||
Example from Moodle root directory:
|
||||
\$ php admin/tool/behat/cli/util.php --enable
|
||||
|
||||
More info in http://docs.moodle.org/dev/Acceptance_testing#Running_tests
|
||||
";
|
||||
|
||||
if (!empty($options['help'])) {
|
||||
echo $help;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
// Checking $CFG->behat_* vars and values.
|
||||
define('BEHAT_UTIL', true);
|
||||
define('CLI_SCRIPT', true);
|
||||
define('ABORT_AFTER_CONFIG', true);
|
||||
define('NO_OUTPUT_BUFFERING', true);
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('log_errors', '1');
|
||||
|
||||
require_once(__DIR__ . '/../../../../config.php');
|
||||
|
||||
// CFG->behat_prefix must be set and with value different than CFG->prefix and phpunit_prefix.
|
||||
if (!isset($CFG->behat_prefix) ||
|
||||
(isset($CFG->behat_prefix) &&
|
||||
($CFG->behat_prefix == $CFG->prefix ||
|
||||
$CFG->behat_prefix == $CFG->phpunit_prefix))) {
|
||||
behat_error(BEHAT_EXITCODE_CONFIG,
|
||||
'Define $CFG->behat_prefix in config.php with a value different than $CFG->prefix and $CFG->phpunit_prefix');
|
||||
}
|
||||
|
||||
// CFG->behat_dataroot must be set and with value different than CFG->dataroot and phpunit_dataroot.
|
||||
if (!isset($CFG->behat_dataroot) ||
|
||||
(isset($CFG->behat_dataroot) &&
|
||||
($CFG->behat_dataroot == $CFG->dataroot ||
|
||||
$CFG->behat_dataroot == $CFG->phpunit_dataroot))) {
|
||||
behat_error(BEHAT_EXITCODE_CONFIG,
|
||||
'Define $CFG->behat_dataroot in config.php with a value different than $CFG->dataroot and $CFG->phpunit_dataroot');
|
||||
}
|
||||
|
||||
// Create behat_dataroot if it doesn't exists.
|
||||
if (!file_exists($CFG->behat_dataroot)) {
|
||||
if (!mkdir($CFG->behat_dataroot, $CFG->directorypermissions)) {
|
||||
behat_error(BEHAT_EXITCODE_PERMISSIONS, '$CFG->behat_dataroot directory can not be created');
|
||||
}
|
||||
}
|
||||
if (!is_dir($CFG->behat_dataroot) || !is_writable($CFG->behat_dataroot)) {
|
||||
behat_error(BEHAT_EXITCODE_PERMISSIONS, '$CFG->behat_dataroot directory has no permissions or is not a directory');
|
||||
}
|
||||
|
||||
// Check that the directory does not contains other things.
|
||||
if (!file_exists("$CFG->behat_dataroot/behattestdir.txt")) {
|
||||
if ($dh = opendir($CFG->behat_dataroot)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file === 'behat' or $file === '.' or $file === '..' or $file === '.DS_Store') {
|
||||
continue;
|
||||
}
|
||||
behat_error(BEHAT_EXITCODE_CONFIG, '$CFG->behat_dataroot directory is not empty, ensure this is the directory where you want to install behat test dataroot');
|
||||
}
|
||||
closedir($dh);
|
||||
unset($dh);
|
||||
unset($file);
|
||||
}
|
||||
|
||||
// Now we create dataroot directory structure for behat tests.
|
||||
testing_initdataroot($CFG->behat_dataroot, 'behat');
|
||||
}
|
||||
|
||||
// Overrides vars with behat-test ones.
|
||||
$vars = array('wwwroot', 'prefix', 'dataroot');
|
||||
foreach ($vars as $var) {
|
||||
$CFG->{$var} = $CFG->{'behat_' . $var};
|
||||
}
|
||||
|
||||
$CFG->noemailever = true;
|
||||
$CFG->passwordsaltmain = 'moodle';
|
||||
|
||||
// Continues setup.
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
require("$CFG->dirroot/lib/setup.php");
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/upgradelib.php');
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
require_once($CFG->libdir.'/pluginlib.php');
|
||||
require_once($CFG->libdir.'/installlib.php');
|
||||
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
|
||||
}
|
||||
|
||||
// Behat utilities.
|
||||
require_once($CFG->libdir . '/behat/classes/util.php');
|
||||
require_once($CFG->libdir . '/behat/classes/behat_command.php');
|
||||
|
||||
// Run command (only one per time).
|
||||
if ($options['install']) {
|
||||
behat_util::install_site();
|
||||
mtrace("Acceptance tests site installed");
|
||||
} else if ($options['drop']) {
|
||||
behat_util::drop_site();
|
||||
mtrace("Acceptance tests site dropped");
|
||||
} else if ($options['enable']) {
|
||||
behat_util::start_test_mode();
|
||||
$runtestscommand = behat_command::get_behat_command() . ' --config '
|
||||
. $CFG->behat_dataroot . DIRECTORY_SEPARATOR . 'behat' . DIRECTORY_SEPARATOR . 'behat.yml';
|
||||
mtrace("Acceptance tests environment enabled, to run the tests use:\n " . $runtestscommand);
|
||||
} else if ($options['disable']) {
|
||||
behat_util::stop_test_mode();
|
||||
mtrace("Acceptance tests environment disabled");
|
||||
} else {
|
||||
echo $help;
|
||||
}
|
||||
|
||||
exit(0);
|
55
admin/tool/behat/index.php
Normal file
55
admin/tool/behat/index.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Web interface to list and filter steps
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/behat/locallib.php');
|
||||
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
|
||||
|
||||
$filter = optional_param('filter', '', PARAM_ALPHANUMEXT);
|
||||
$type = optional_param('type', false, PARAM_ALPHAEXT);
|
||||
$component = optional_param('component', '', PARAM_ALPHAEXT);
|
||||
|
||||
admin_externalpage_setup('toolbehat');
|
||||
|
||||
// Getting available steps definitions from behat.
|
||||
$steps = tool_behat::stepsdefinitions($type, $component, $filter);
|
||||
|
||||
// Form.
|
||||
$componentswithsteps = array('' => get_string('allavailablesteps', 'tool_behat'));
|
||||
|
||||
// Complete the components list with the moodle steps definitions.
|
||||
$components = behat_config_manager::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);
|
||||
}
|
||||
}
|
||||
$form = new steps_definitions_form(null, array('components' => $componentswithsteps));
|
||||
|
||||
// Output contents.
|
||||
$renderer = $PAGE->get_renderer('tool_behat');
|
||||
echo $renderer->render_stepsdefinitions($steps, $form);
|
||||
|
40
admin/tool/behat/lang/en/tool_behat.php
Normal file
40
admin/tool/behat/lang/en/tool_behat.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Strings for tool_behat
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['allavailablesteps'] = 'All the available steps definitions';
|
||||
$string['giveninfo'] = 'Given. Processes to set up the environment';
|
||||
$string['installinfo'] = 'Read {$a} for installation and tests execution info';
|
||||
$string['moreinfoin'] = 'More info in {$a}';
|
||||
$string['newstepsinfo'] = 'Read {$a} for info about how to add new steps definitions';
|
||||
$string['newtestsinfo'] = 'Read {$a} for info about how to write new tests';
|
||||
$string['nostepsdefinitions'] = 'There aren\'t steps definitions matching this filters';
|
||||
$string['pluginname'] = 'Acceptance testing';
|
||||
$string['stepsdefinitionscomponent'] = 'Area';
|
||||
$string['stepsdefinitionscontains'] = 'Contains';
|
||||
$string['stepsdefinitionsfilters'] = 'Steps definitions';
|
||||
$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 vendor/bin/behat file has execution permissions';
|
84
admin/tool/behat/locallib.php
Normal file
84
admin/tool/behat/locallib.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Behat commands
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/behat/classes/behat_command.php');
|
||||
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/behat/steps_definitions_form.php');
|
||||
|
||||
/**
|
||||
* Behat commands manager
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_behat {
|
||||
|
||||
/**
|
||||
* Lists the available steps definitions
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $component
|
||||
* @param string $filter
|
||||
* @return string
|
||||
*/
|
||||
public static function stepsdefinitions($type, $component, $filter) {
|
||||
|
||||
// We don't require the test environment to be enabled to list the steps definitions
|
||||
// so test writers can more easily set up the environment.
|
||||
behat_command::check_behat_setup();
|
||||
|
||||
// The loaded steps depends on the component specified.
|
||||
behat_config_manager::update_config_file($component, false);
|
||||
|
||||
// The Moodle\BehatExtension\HelpPrinter\MoodleDefinitionsPrinter will parse this search format.
|
||||
if ($type) {
|
||||
$filter .= '&&' . $type;
|
||||
}
|
||||
|
||||
if ($filter) {
|
||||
$filteroption = ' -d "' . $filter . '"';
|
||||
} else {
|
||||
$filteroption = ' -di';
|
||||
}
|
||||
|
||||
// Get steps definitions from Behat.
|
||||
$options = ' --config="'.behat_config_manager::get_steps_list_config_filepath(). '" '.$filteroption;
|
||||
list($steps, $code) = behat_command::run($options);
|
||||
|
||||
if ($steps) {
|
||||
$stepshtml = implode('', $steps);
|
||||
}
|
||||
|
||||
if (empty($stepshtml)) {
|
||||
$stepshtml = get_string('nostepsdefinitions', 'tool_behat');
|
||||
}
|
||||
|
||||
return $stepshtml;
|
||||
}
|
||||
|
||||
}
|
92
admin/tool/behat/renderer.php
Normal file
92
admin/tool/behat/renderer.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Behat tool renderer
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/behat/classes/behat_command.php');
|
||||
|
||||
/**
|
||||
* Renderer for behat tool web features
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_behat_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Renders the list of available steps according to the submitted filters
|
||||
*
|
||||
* @param string $stepsdefinitions HTML from behat with the available steps
|
||||
* @param moodleform $form
|
||||
* @return string HTML code
|
||||
*/
|
||||
public function render_stepsdefinitions($stepsdefinitions, $form) {
|
||||
|
||||
$title = get_string('pluginname', 'tool_behat');
|
||||
|
||||
// Header.
|
||||
$html = $this->output->header();
|
||||
$html .= $this->output->heading($title);
|
||||
|
||||
// Info.
|
||||
$installurl = behat_command::DOCS_URL . '#Installation';
|
||||
$installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank'));
|
||||
$writetestsurl = behat_command::DOCS_URL . '#Writting_features';
|
||||
$writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank'));
|
||||
$writestepsurl = behat_command::DOCS_URL . '#Adding_steps_definitions';
|
||||
$writestepslink = html_writer::tag('a', $writestepsurl, array('href' => $writestepsurl, 'target' => '_blank'));
|
||||
$infos = array(
|
||||
get_string('installinfo', 'tool_behat', $installlink),
|
||||
get_string('newtestsinfo', 'tool_behat', $writetestslink),
|
||||
get_string('newstepsinfo', 'tool_behat', $writestepslink)
|
||||
);
|
||||
|
||||
// List of steps
|
||||
$html .= $this->output->box_start();
|
||||
$html .= html_writer::tag('h1', 'Info');
|
||||
$html .= html_writer::empty_tag('div');
|
||||
$html .= html_writer::empty_tag('ul');
|
||||
$html .= html_writer::empty_tag('li');
|
||||
$html .= implode(html_writer::end_tag('li') . html_writer::empty_tag('li'), $infos);
|
||||
$html .= html_writer::end_tag('li');
|
||||
$html .= html_writer::end_tag('ul');
|
||||
$html .= html_writer::end_tag('div');
|
||||
$html .= $this->output->box_end();
|
||||
|
||||
// Form.
|
||||
ob_start();
|
||||
$form->display();
|
||||
$html .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// Steps definitions.
|
||||
$html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
|
||||
|
||||
$html .= $this->output->footer();
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
31
admin/tool/behat/settings.php
Normal file
31
admin/tool/behat/settings.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Adds behat tests link in admin tree
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
if ($hassiteconfig) {
|
||||
$url = $CFG->wwwroot . '/' . $CFG->admin . '/tool/behat/index.php';
|
||||
$ADMIN->add('development', new admin_externalpage('toolbehat', get_string('pluginname', 'tool_behat'), $url));
|
||||
}
|
67
admin/tool/behat/steps_definitions_form.php
Normal file
67
admin/tool/behat/steps_definitions_form.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Steps definitions form
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
/**
|
||||
* Form to display the available steps definitions
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class steps_definitions_form extends moodleform {
|
||||
|
||||
/**
|
||||
* Form definition
|
||||
* @return void
|
||||
*/
|
||||
public function definition() {
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'filters', get_string('stepsdefinitionsfilters', 'tool_behat'));
|
||||
|
||||
$types = array(
|
||||
'' => get_string('allavailablesteps', 'tool_behat'),
|
||||
'given' => get_string('giveninfo', 'tool_behat'),
|
||||
'when' => get_string('wheninfo', 'tool_behat'),
|
||||
'then' => get_string('theninfo', 'tool_behat')
|
||||
);
|
||||
$mform->addElement('select', 'type', get_string('stepsdefinitionstype', 'tool_behat'), $types);
|
||||
|
||||
$mform->addElement(
|
||||
'select',
|
||||
'component',
|
||||
get_string('stepsdefinitionscomponent', 'tool_behat'),
|
||||
$this->_customdata['components']
|
||||
);
|
||||
|
||||
$mform->addElement('text', 'filter', get_string('stepsdefinitionscontains', 'tool_behat'));
|
||||
|
||||
$mform->addElement('submit', 'submit', get_string('viewsteps', 'tool_behat'));
|
||||
}
|
||||
}
|
5
admin/tool/behat/styles.css
Normal file
5
admin/tool/behat/styles.css
Normal file
|
@ -0,0 +1,5 @@
|
|||
.steps-definitions{border-style:solid;border-width:1px;border-color:#BBB;padding:5px;margin:auto;width:50%;}
|
||||
.steps-definitions .step{margin: 10px 0px 10px 0px;}
|
||||
.steps-definitions .stepdescription{color:#bf8c12;}
|
||||
.steps-definitions .steptype{color:#1467a6;margin-right: 5px;}
|
||||
.steps-definitions .stepregex{color:#060;}
|
175
admin/tool/behat/tests/tool_behat_test.php
Normal file
175
admin/tool/behat/tests/tool_behat_test.php
Normal file
|
@ -0,0 +1,175 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Unit tests for admin/tool/behat.
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin .'/tool/behat/locallib.php');
|
||||
require_once($CFG->libdir . '/behat/classes/util.php');
|
||||
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
|
||||
|
||||
/**
|
||||
* Allows access to internal methods without exposing them.
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class testable_behat_config_manager extends behat_config_manager {
|
||||
|
||||
/**
|
||||
* Allow access to protected method
|
||||
* @see parent::merge_config()
|
||||
* @param mixed $config
|
||||
* @param mixed $localconfig
|
||||
* @return mixed
|
||||
*/
|
||||
public static function merge_config($config, $localconfig) {
|
||||
return parent::merge_config($config, $localconfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow access to protected method
|
||||
* @see parent::get_config_file_contents()
|
||||
* @param string $prefix
|
||||
* @param array $features
|
||||
* @param array $stepsdefinitions
|
||||
* @return string
|
||||
*/
|
||||
public static function get_config_file_contents($features, $stepsdefinitions) {
|
||||
return parent::get_config_file_contents($features, $stepsdefinitions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool behat tests.
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_behat_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* behat_config_manager tests.
|
||||
*/
|
||||
public function test_merge_configs() {
|
||||
|
||||
// Simple default config.
|
||||
$array1 = array(
|
||||
'the' => 'same',
|
||||
'simple' => 'value',
|
||||
'array' => array(
|
||||
'one' => 'arrayvalue1',
|
||||
'two' => 'arrayvalue2'
|
||||
)
|
||||
);
|
||||
|
||||
// Simple override.
|
||||
$array2 = array(
|
||||
'simple' => 'OVERRIDDEN1',
|
||||
'array' => array(
|
||||
'one' => 'OVERRIDDEN2'
|
||||
),
|
||||
'newprofile' => array(
|
||||
'anotherlevel' => array(
|
||||
'andanotherone' => array(
|
||||
'list1',
|
||||
'list2'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$array = testable_behat_config_manager::merge_config($array1, $array2);
|
||||
|
||||
// Overriddes are applied.
|
||||
$this->assertEquals('OVERRIDDEN1', $array['simple']);
|
||||
$this->assertEquals('OVERRIDDEN2', $array['array']['one']);
|
||||
|
||||
// Other values are respected.
|
||||
$this->assertNotEmpty($array['array']['two']);
|
||||
|
||||
// Completely new nodes are added.
|
||||
$this->assertNotEmpty($array['newprofile']);
|
||||
$this->assertNotEmpty($array['newprofile']['anotherlevel']['andanotherone']);
|
||||
$this->assertEquals('list1', $array['newprofile']['anotherlevel']['andanotherone'][0]);
|
||||
$this->assertEquals('list2', $array['newprofile']['anotherlevel']['andanotherone'][1]);
|
||||
|
||||
// Complex override changing vectors to scalars and scalars to vectors.
|
||||
$array2 = array(
|
||||
'simple' => array(
|
||||
'simple' => 'should',
|
||||
'be' => 'overridden',
|
||||
'by' => 'this-array'
|
||||
),
|
||||
'array' => 'one'
|
||||
);
|
||||
|
||||
$array = testable_behat_config_manager::merge_config($array1, $array2);
|
||||
|
||||
// Overrides applied.
|
||||
$this->assertNotEmpty($array['simple']);
|
||||
$this->assertNotEmpty($array['array']);
|
||||
$this->assertTrue(is_array($array['simple']));
|
||||
$this->assertFalse(is_array($array['array']));
|
||||
|
||||
// Other values are maintained.
|
||||
$this->assertEquals('same', $array['the']);
|
||||
}
|
||||
|
||||
/**
|
||||
* behat_config_manager tests.
|
||||
*/
|
||||
public function test_config_file_contents() {
|
||||
global $CFG;
|
||||
|
||||
// To avoid user value at config.php level.
|
||||
unset($CFG->behat_config);
|
||||
|
||||
// List.
|
||||
$features = array(
|
||||
'feature1',
|
||||
'feature2',
|
||||
'feature3'
|
||||
);
|
||||
|
||||
// Associative array.
|
||||
$stepsdefinitions = array(
|
||||
'micarro' => '/me/lo/robaron',
|
||||
'anoche' => '/cuando/yo/dormia'
|
||||
);
|
||||
|
||||
$contents = testable_behat_config_manager::get_config_file_contents($features, $stepsdefinitions);
|
||||
|
||||
$this->assertContains('features: ' . $CFG->dirroot . '/lib/behat/features', $contents);
|
||||
$this->assertContains('micarro: /me/lo/robaron', $contents);
|
||||
$this->assertContains('base_url: \'' . $CFG->behat_wwwroot . '\'', $contents);
|
||||
$this->assertContains('class: behat_init_context', $contents);
|
||||
$this->assertContains('- feature1', $contents);
|
||||
$this->assertContains('- feature3', $contents);
|
||||
}
|
||||
|
||||
}
|
||||
|
29
admin/tool/behat/version.php
Normal file
29
admin/tool/behat/version.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* tool_behat version info
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2012120700;
|
||||
$plugin->requires = 2012120300; // Requires Moodle 2.5.
|
||||
$plugin->component = 'tool_behat';
|
Loading…
Add table
Add a link
Reference in a new issue