first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
define("tool_behat/steps",["exports","core/ajax","core/templates","core/pending"],(function(_exports,_ajax,_templates,_pending){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* Enhancements for the step definitions page.
*
* @module tool_behat/steps
* @copyright 2022 Catalyst IT EU
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_ajax=_interopRequireDefault(_ajax),_templates=_interopRequireDefault(_templates),_pending=_interopRequireDefault(_pending);_exports.init=()=>{document.addEventListener("change",(async e=>{const entityElement=e.target.closest(".entities"),stepElement=e.target.closest(".stepcontent");if(!entityElement||!stepElement)return;const pendingPromise=new _pending.default("tool_behat/steps:change"),entityData=await(entityType=e.target.value,_ajax.default.call([{methodname:"tool_behat_get_entity_generator",args:{entitytype:entityType}}])[0]);var entityType;const{html:html,js:js}=await(entityData=>{var _entityData$required;return null!==(_entityData$required=entityData.required)&&void 0!==_entityData$required&&_entityData$required.length?_templates.default.renderForPromise("tool_behat/steprequiredfields",{fields:entityData.required}):Promise.resolve({html:"",js:""})})(entityData),stepRequiredFields=stepElement.querySelector(".steprequiredfields");stepRequiredFields?await _templates.default.replaceNode(stepRequiredFields,html,js):await _templates.default.appendNodeContents(stepElement,html,js),pendingPromise.resolve()}))}}));
//# sourceMappingURL=steps.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"steps.min.js","sources":["../src/steps.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\nimport Ajax from 'core/ajax';\nimport Templates from 'core/templates';\nimport PendingJS from 'core/pending';\n\n/**\n * Enhancements for the step definitions page.\n *\n * @module tool_behat/steps\n * @copyright 2022 Catalyst IT EU\n * @author Mark Johnson <mark.johnson@catalyst-eu.net>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Call the get_entity_generator web service function\n *\n * Takes the name of an entity generator and returns an object containing a list of the required fields.\n *\n * @param {String} entityType\n * @returns {Promise}\n */\nconst getGeneratorEntities = (entityType) => Ajax.call([{\n methodname: 'tool_behat_get_entity_generator',\n args: {entitytype: entityType}\n}])[0];\n\n/**\n * Render HTML for required fields\n *\n * Takes the entity data returned from getGeneratorEntities and renders the HTML to display the required fields.\n *\n * @param {String} entityData\n * @return {Promise}\n */\nconst getRequiredFieldsContent = (entityData) => {\n if (!entityData.required?.length) {\n return Promise.resolve({\n html: '',\n js: ''\n });\n }\n return Templates.renderForPromise('tool_behat/steprequiredfields', {fields: entityData.required});\n};\n\nexport const init = () => {\n // When an entity is selected in the \"the following exist\" step, fetch and display the required fields.\n document.addEventListener('change', async(e) => {\n const entityElement = e.target.closest('.entities');\n const stepElement = e.target.closest('.stepcontent');\n if (!entityElement || !stepElement) {\n return;\n }\n\n const pendingPromise = new PendingJS('tool_behat/steps:change');\n\n const entityData = await getGeneratorEntities(e.target.value);\n const {html, js} = await getRequiredFieldsContent(entityData);\n\n const stepRequiredFields = stepElement.querySelector('.steprequiredfields');\n if (stepRequiredFields) {\n await Templates.replaceNode(stepRequiredFields, html, js);\n } else {\n await Templates.appendNodeContents(stepElement, html, js);\n }\n pendingPromise.resolve();\n });\n};\n"],"names":["document","addEventListener","async","entityElement","e","target","closest","stepElement","pendingPromise","PendingJS","entityData","entityType","value","Ajax","call","methodname","args","entitytype","html","js","required","_entityData$required","length","Templates","renderForPromise","fields","Promise","resolve","getRequiredFieldsContent","stepRequiredFields","querySelector","replaceNode","appendNodeContents"],"mappings":";;;;;;;;4NA2DoB,KAEhBA,SAASC,iBAAiB,UAAUC,MAAAA,UAC1BC,cAAgBC,EAAEC,OAAOC,QAAQ,aACjCC,YAAcH,EAAEC,OAAOC,QAAQ,oBAChCH,gBAAkBI,yBAIjBC,eAAiB,IAAIC,iBAAU,2BAE/BC,iBAlCgBC,WAkCwBP,EAAEC,OAAOO,MAlClBC,cAAKC,KAAK,CAAC,CACpDC,WAAY,kCACZC,KAAM,CAACC,WAAYN,eACnB,IAH0BA,IAAAA,iBAmChBO,KAACA,KAADC,GAAOA,SAtBaT,CAAAA,0EACzBA,WAAWU,0CAAXC,qBAAqBC,OAMnBC,mBAAUC,iBAAiB,gCAAiC,CAACC,OAAQf,WAAWU,WAL5EM,QAAQC,QAAQ,CACnBT,KAAM,GACNC,GAAI,MAkBiBS,CAAyBlB,YAE5CmB,mBAAqBtB,YAAYuB,cAAc,uBACjDD,yBACMN,mBAAUQ,YAAYF,mBAAoBX,KAAMC,UAEhDI,mBAAUS,mBAAmBzB,YAAaW,KAAMC,IAE1DX,eAAemB"}
+82
View File
@@ -0,0 +1,82 @@
// 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/>.
import Ajax from 'core/ajax';
import Templates from 'core/templates';
import PendingJS from 'core/pending';
/**
* Enhancements for the step definitions page.
*
* @module tool_behat/steps
* @copyright 2022 Catalyst IT EU
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Call the get_entity_generator web service function
*
* Takes the name of an entity generator and returns an object containing a list of the required fields.
*
* @param {String} entityType
* @returns {Promise}
*/
const getGeneratorEntities = (entityType) => Ajax.call([{
methodname: 'tool_behat_get_entity_generator',
args: {entitytype: entityType}
}])[0];
/**
* Render HTML for required fields
*
* Takes the entity data returned from getGeneratorEntities and renders the HTML to display the required fields.
*
* @param {String} entityData
* @return {Promise}
*/
const getRequiredFieldsContent = (entityData) => {
if (!entityData.required?.length) {
return Promise.resolve({
html: '',
js: ''
});
}
return Templates.renderForPromise('tool_behat/steprequiredfields', {fields: entityData.required});
};
export const init = () => {
// When an entity is selected in the "the following exist" step, fetch and display the required fields.
document.addEventListener('change', async(e) => {
const entityElement = e.target.closest('.entities');
const stepElement = e.target.closest('.stepcontent');
if (!entityElement || !stepElement) {
return;
}
const pendingPromise = new PendingJS('tool_behat/steps:change');
const entityData = await getGeneratorEntities(e.target.value);
const {html, js} = await getRequiredFieldsContent(entityData);
const stepRequiredFields = stepElement.querySelector('.steprequiredfields');
if (stepRequiredFields) {
await Templates.replaceNode(stepRequiredFields, html, js);
} else {
await Templates.appendNodeContents(stepElement, html, js);
}
pendingPromise.resolve();
});
};
@@ -0,0 +1,94 @@
<?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/>.
/**
* Return data about an entity generator.
*
* @package tool_behat
* @copyright 2022 onwards Catalyst IT EU {@link https://catalyst-eu.net}
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_behat\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
/**
* External function for getting properties of entity generators.
*/
class get_entity_generator extends external_api {
/**
* Define parameters for external function.
*
* The parameter is either in the format 'entity' or 'component_name > entity'. There is no appropriate param type for a
* string like this containing angle brackets, so we will do PARAM_RAW. The value will be parsed by
* behat_data_generators::parse_entity_type, which validates the format of the parameter and throws an exception if it is not
* correct.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'entitytype' => new external_value(PARAM_RAW, 'Entity type that can be created by a generator.'),
]);
}
/**
* Return a list of the required fields for a given entity type.
*
* @param string $entitytype
* @return array
*/
public static function execute(string $entitytype): array {
global $CFG;
// Ensure we can load Behat and Facebook namespaces in behat libraries.
require_once("{$CFG->dirroot}/vendor/autoload.php");
require_once("{$CFG->libdir}/tests/behat/behat_data_generators.php");
$params = self::validate_parameters(self::execute_parameters(), ['entitytype' => $entitytype]);
$context = \context_system::instance();
self::validate_context($context);
require_capability('moodle/site:config', $context);
$generators = new \behat_data_generators();
$entity = $generators->get_entity($params['entitytype']);
return ['required' => $entity['required']];
}
/**
* Define return values.
*
* Return required fields
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'required' => new external_multiple_structure(
new external_value(PARAM_TEXT, 'Required field'),
'Required fields',
VALUE_OPTIONAL
),
]);
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for tool_behat.
*
* @package tool_behat
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_behat\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for tool_behat implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+206
View File
@@ -0,0 +1,206 @@
<?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 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!
}
// Force OPcache reset if used, we do not want any stale caches
// when preparing test environment.
if (function_exists('opcache_reset')) {
opcache_reset();
}
// Is not really necessary but adding it as is a CLI_SCRIPT.
define('CLI_SCRIPT', true);
define('CACHE_DISABLE_ALL', true);
// Basic functions.
require_once(__DIR__ . '/../../../../lib/clilib.php');
require_once(__DIR__ . '/../../../../lib/behat/lib.php');
list($options, $unrecognized) = cli_get_params(
array(
'parallel' => 0,
'maxruns' => false,
'help' => false,
'fromrun' => 1,
'torun' => 0,
'optimize-runs' => '',
'add-core-features-to-theme' => false,
'axe' => null,
'disable-composer' => false,
'composer-upgrade' => true,
'composer-self-update' => true,
'scss-deprecations' => false,
),
array(
'j' => 'parallel',
'm' => 'maxruns',
'h' => 'help',
'o' => 'optimize-runs',
'a' => 'add-core-features-to-theme',
)
);
// Checking run.php CLI script usage.
$help = "
Behat utilities to initialise behat tests
Usage:
php init.php [--parallel=value [--maxruns=value] [--fromrun=value --torun=value]]
[--no-axe] [--scss-deprecations] [-o | --optimize-runs] [-a | --add-core-features-to-theme]
[--no-composer-self-update] [--no-composer-upgrade]
[--disable-composer]
[--help]
Options:
-j, --parallel Number of parallel behat run to initialise
-m, --maxruns Max parallel processes to be executed at one time
--fromrun Execute run starting from (Used for parallel runs on different vms)
--torun Execute run till (Used for parallel runs on different vms)
--no-axe Disable axe accessibility tests.
--scss-deprecations Enable SCSS deprecation checks.
-o, --optimize-runs
Split features with specified tags in all parallel runs.
-a, --add-core-features-to-theme
Add all core features to specified theme's
--no-composer-self-update
Prevent upgrade of the composer utility using its self-update command
--no-composer-upgrade
Prevent update development dependencies using composer
--disable-composer
A shortcut to disable composer self-update and dependency update
Note: Installation of composer and/or dependencies will still happen as required
-h, --help Print out this help
Example from Moodle root directory:
\$ php admin/tool/behat/cli/init.php --parallel=2
More info in https://moodledev.io/general/development/tools/behat/running
";
if (!empty($options['help'])) {
echo $help;
exit(0);
}
if ($options['axe']) {
echo "Axe accessibility tests are enabled by default, to disable them, use the --no-axe option.\n";
} else if ($options['axe'] === false) {
echo "Axe accessibility tests have been disabled.\n";
}
// Check which util file to call.
$utilfile = 'util_single_run.php';
$commandoptions = "";
// If parallel run then use utilparallel.
if ($options['parallel'] && $options['parallel'] > 1) {
$utilfile = 'util.php';
// Sanitize all input options, so they can be passed to util.
foreach ($options as $option => $value) {
$commandoptions .= behat_get_command_flags($option, $value);
}
} else {
// Only sanitize options for single run.
$cmdoptionsforsinglerun = [
'add-core-features-to-theme',
'axe',
'scss-deprecations',
];
foreach ($cmdoptionsforsinglerun as $option) {
$commandoptions .= behat_get_command_flags($option, $options[$option]);
}
}
// Changing the cwd to admin/tool/behat/cli.
$cwd = getcwd();
$output = null;
if ($options['disable-composer']) {
// Disable self-update and upgrade easily.
// Note: Installation will still occur regardless of this setting.
$options['composer-self-update'] = false;
$options['composer-upgrade'] = false;
}
// Install and update composer and dependencies as required.
testing_update_composer_dependencies($options['composer-self-update'], $options['composer-upgrade']);
// Check whether the behat test environment needs to be updated.
chdir(__DIR__);
exec("php $utilfile --diag $commandoptions", $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.
chdir(__DIR__);
passthru("php $utilfile --install $commandoptions", $code);
if ($code != 0) {
chdir($cwd);
exit($code);
}
} else if ($code == BEHAT_EXITCODE_REINSTALL) {
// Test site data is outdated.
chdir(__DIR__);
passthru("php $utilfile --drop $commandoptions", $code);
if ($code != 0) {
chdir($cwd);
exit($code);
}
chdir(__DIR__);
passthru("php $utilfile --install $commandoptions", $code);
if ($code != 0) {
chdir($cwd);
exit($code);
}
} else {
// Generic error, we just output it.
echo implode("\n", $output)."\n";
chdir($cwd);
exit($code);
}
// Enable editing mode according to config.php vars.
chdir(__DIR__);
passthru("php $utilfile --enable $commandoptions", $code);
if ($code != 0) {
echo "Error enabling site" . PHP_EOL;
chdir($cwd);
exit($code);
}
exit(0);
+524
View File
@@ -0,0 +1,524 @@
<?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/>.
/**
* Wrapper to run previously set-up behat tests in parallel.
*
* @package tool_behat
* @copyright 2014 NetSpot Pty Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (isset($_SERVER['REMOTE_ADDR'])) {
die(); // No access from web!
}
define('CLI_SCRIPT', true);
define('ABORT_AFTER_CONFIG', true);
define('CACHE_DISABLE_ALL', true);
define('NO_OUTPUT_BUFFERING', true);
require_once(__DIR__ .'/../../../../config.php');
require_once(__DIR__.'/../../../../lib/clilib.php');
require_once(__DIR__.'/../../../../lib/behat/lib.php');
require_once(__DIR__.'/../../../../lib/behat/classes/behat_command.php');
require_once(__DIR__.'/../../../../lib/behat/classes/behat_config_manager.php');
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', '1');
ini_set('log_errors', '1');
list($options, $unrecognised) = cli_get_params(
array(
'stop-on-failure' => 0,
'verbose' => false,
'replace' => '',
'help' => false,
'tags' => '',
'profile' => '',
'feature' => '',
'suite' => '',
'fromrun' => 1,
'torun' => 0,
'single-run' => false,
'rerun' => 0,
'auto-rerun' => 0,
),
array(
'h' => 'help',
't' => 'tags',
'p' => 'profile',
's' => 'single-run',
)
);
// Checking run.php CLI script usage.
$help = "
Behat utilities to run behat tests in parallel
Usage:
php run.php [--BEHAT_OPTION=\"value\"] [--feature=\"value\"] [--replace=\"{run}\"] [--fromrun=value --torun=value] [--help]
Options:
--BEHAT_OPTION Any combination of behat option specified in http://behat.readthedocs.org/en/v2.5/guides/6.cli.html
--feature Only execute specified feature file (Absolute path of feature file).
--suite Specified theme scenarios will be executed.
--replace Replace args string with run process number, useful for output.
--fromrun Execute run starting from (Used for parallel runs on different vms)
--torun Execute run till (Used for parallel runs on different vms)
--rerun Re-run scenarios that failed during last execution.
--auto-rerun Automatically re-run scenarios that failed during last execution.
-h, --help Print out this help
Example from Moodle root directory:
\$ php admin/tool/behat/cli/run.php --tags=\"@javascript\"
More info in https://moodledev.io/general/development/tools/behat/running
";
if (!empty($options['help'])) {
echo $help;
exit(0);
}
$parallelrun = behat_config_manager::get_behat_run_config_value('parallel');
// Check if the options provided are valid to run behat.
if ($parallelrun === false) {
// Parallel run should not have fromrun or torun options greater than 1.
if (($options['fromrun'] > 1) || ($options['torun'] > 1)) {
echo "Test site is not initialized for parallel run." . PHP_EOL;
exit(1);
}
} else {
// Ensure fromrun is within limits of initialized test site.
if (!empty($options['fromrun']) && ($options['fromrun'] > $parallelrun)) {
echo "From run (" . $options['fromrun'] . ") is more than site with parallel runs (" . $parallelrun . ")" . PHP_EOL;
exit(1);
}
// Default torun is maximum parallel runs and should be less than equal to parallelruns.
if (empty($options['torun'])) {
$options['torun'] = $parallelrun;
} else {
if ($options['torun'] > $parallelrun) {
echo "To run (" . $options['torun'] . ") is more than site with parallel runs (" . $parallelrun . ")" . PHP_EOL;
exit(1);
}
}
}
// Capture signals and ensure we clean symlinks.
if (extension_loaded('pcntl')) {
$disabled = explode(',', ini_get('disable_functions'));
if (!in_array('pcntl_signal', $disabled)) {
pcntl_signal(SIGTERM, "signal_handler");
pcntl_signal(SIGINT, "signal_handler");
}
}
$time = microtime(true);
array_walk($unrecognised, function (&$v) {
if ($x = preg_filter("#^(-+\w+)=(.+)#", "\$1=\"\$2\"", $v)) {
$v = $x;
} else if (!preg_match("#^-#", $v)) {
$v = escapeshellarg($v);
}
});
$extraopts = $unrecognised;
if ($options['profile']) {
$profile = $options['profile'];
// If profile passed is not set, then exit (note we skip if the 'replace' option is found within the 'profile' value).
if (!isset($CFG->behat_config[$profile]) && !isset($CFG->behat_profiles[$profile]) &&
!($options['replace'] && (strpos($profile, (string) $options['replace']) !== false))) {
echo "Invalid profile passed: " . $profile . PHP_EOL;
exit(1);
}
$extraopts['profile'] = '--profile="' . $profile . '"';
// By default, profile tags will be used.
if (!empty($CFG->behat_config[$profile]['filters']['tags'])) {
$tags = $CFG->behat_config[$profile]['filters']['tags'];
}
}
// Command line tags have precedence (std behat behavior).
if ($options['tags']) {
$tags = $options['tags'];
$extraopts['tags'] = '--tags="' . $tags . '"';
}
// Add suite option if specified.
if ($options['suite']) {
$extraopts['suite'] = '--suite="' . $options['suite'] . '"';
}
// Feature should be added to last, for behat command.
if ($options['feature']) {
$extraopts['feature'] = $options['feature'];
// Only run 1 process as process.
// Feature file is picked from absolute path provided, so no need to check for behat.yml.
$options['torun'] = $options['fromrun'];
}
// Set of options to pass to behat.
$extraoptstr = implode(' ', $extraopts);
// If rerun is passed then ensure we just run the failed processes.
$lastfailedstatus = 0;
$lasttorun = $options['torun'];
$lastfromrun = $options['fromrun'];
if ($options['rerun']) {
// Get last combined failed status.
$lastfailedstatus = behat_config_manager::get_behat_run_config_value('lastcombinedfailedstatus');
$lasttorun = behat_config_manager::get_behat_run_config_value('lasttorun');
$lastfromrun = behat_config_manager::get_behat_run_config_value('lastfromrun');
if ($lastfailedstatus !== false) {
$extraoptstr .= ' --rerun';
}
// If torun is less than last torun, then just set this to min last to run and similar for fromrun.
if ($options['torun'] < $lasttorun) {
$options['torun'];
}
if ($options['fromrun'] > $lastfromrun) {
$options['fromrun'];
}
unset($options['rerun']);
}
$cmds = array();
$exitcodes = array();
$status = 0;
$verbose = empty($options['verbose']) ? false : true;
// Execute behat run commands.
if (empty($parallelrun)) {
$cwd = getcwd();
chdir(__DIR__);
$runtestscommand = behat_command::get_behat_command(false, false, true);
$runtestscommand .= ' --config ' . behat_config_manager::get_behat_cli_config_filepath();
$runtestscommand .= ' ' . $extraoptstr;
$cmds['singlerun'] = $runtestscommand;
echo "Running single behat site:" . PHP_EOL;
passthru("php $runtestscommand", $status);
$exitcodes['singlerun'] = $status;
chdir($cwd);
} else {
echo "Running " . ($options['torun'] - $options['fromrun'] + 1) . " parallel behat sites:" . PHP_EOL;
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
$lastfailed = 1 & $lastfailedstatus >> ($i - 1);
// Bypass if not failed in last run.
if ($lastfailedstatus && !$lastfailed && ($i <= $lasttorun) && ($i >= $lastfromrun)) {
continue;
}
$CFG->behatrunprocess = $i;
// Options parameters to be added to each run.
$myopts = !empty($options['replace']) ? str_replace($options['replace'], $i, $extraoptstr) : $extraoptstr;
$behatcommand = behat_command::get_behat_command(false, false, true);
$behatconfigpath = behat_config_manager::get_behat_cli_config_filepath($i);
// Command to execute behat run.
$cmds[BEHAT_PARALLEL_SITE_NAME . $i] = $behatcommand . ' --config ' . $behatconfigpath . " " . $myopts;
echo "[" . BEHAT_PARALLEL_SITE_NAME . $i . "] " . $cmds[BEHAT_PARALLEL_SITE_NAME . $i] . PHP_EOL;
}
if (empty($cmds)) {
echo "No commands to execute " . PHP_EOL;
exit(1);
}
// Create site symlink if necessary.
if (!behat_config_manager::create_parallel_site_links($options['fromrun'], $options['torun'])) {
echo "Check permissions. If on windows, make sure you are running this command as admin" . PHP_EOL;
exit(1);
}
// Save torun and from run, so it can be used to detect if it was executed in last run.
behat_config_manager::set_behat_run_config_value('lasttorun', $options['torun']);
behat_config_manager::set_behat_run_config_value('lastfromrun', $options['fromrun']);
// Keep no delay by default, between each parallel, let user decide.
if (!defined('BEHAT_PARALLEL_START_DELAY')) {
define('BEHAT_PARALLEL_START_DELAY', 0);
}
// Execute all commands, relative to moodle root directory.
$processes = cli_execute_parallel($cmds, __DIR__ . "/../../../../", BEHAT_PARALLEL_START_DELAY);
$stoponfail = empty($options['stop-on-failure']) ? false : true;
// Print header.
print_process_start_info($processes);
// Print combined run o/p from processes.
$exitcodes = print_combined_run_output($processes, $stoponfail);
// Time to finish run.
$time = round(microtime(true) - $time, 0);
echo "Finished in " . gmdate("G\h i\m s\s", $time) . PHP_EOL . PHP_EOL;
ksort($exitcodes);
// Print exit info from each run.
// Status bits contains pass/fail status of parallel runs.
foreach ($exitcodes as $name => $exitcode) {
if ($exitcode) {
$runno = str_replace(BEHAT_PARALLEL_SITE_NAME, '', $name);
$status |= (1 << ($runno - 1));
}
}
// Print each process information.
print_each_process_info($processes, $verbose, $status);
}
// Save final exit code containing which run failed.
behat_config_manager::set_behat_run_config_value('lastcombinedfailedstatus', $status);
// Show exit code from each process, if any process failed and how to rerun failed process.
if ($verbose || $status) {
// Check if status of last run is failure and rerun is suggested.
if (!empty($options['auto-rerun']) && $status) {
// Rerun for the number of tries passed.
for ($i = 0; $i < $options['auto-rerun']; $i++) {
// Run individual commands, to avoid parallel failures.
foreach ($exitcodes as $behatrunname => $exitcode) {
// If not failed in last run, then skip.
if ($exitcode == 0) {
continue;
}
// This was a failure.
echo "*** Re-running behat run: $behatrunname ***" . PHP_EOL;
if ($verbose) {
echo "Executing: " . $cmds[$behatrunname] . " --rerun" . PHP_EOL;
}
passthru("php $cmds[$behatrunname] --rerun", $rerunstatus);
// Update exit code.
$exitcodes[$behatrunname] = $rerunstatus;
}
}
// Update status after auto-rerun finished.
$status = 0;
foreach ($exitcodes as $name => $exitcode) {
if ($exitcode) {
if (!empty($parallelrun)) {
$runno = str_replace(BEHAT_PARALLEL_SITE_NAME, '', $name);
} else {
$runno = 1;
}
$status |= (1 << ($runno - 1));
}
}
}
// Show final o/p with re-run commands.
if ($status) {
if (!empty($parallelrun)) {
// Echo exit codes.
echo "Exit codes for each behat run: " . PHP_EOL;
foreach ($exitcodes as $run => $exitcode) {
echo $run . ": " . $exitcode . PHP_EOL;
}
unset($extraopts['fromrun']);
unset($extraopts['torun']);
if (!empty($options['replace'])) {
$extraopts['replace'] = '--replace="' . $options['replace'] . '"';
}
}
echo "To re-run failed processes, you can use following command:" . PHP_EOL;
$extraopts['rerun'] = '--rerun';
$extraoptstr = implode(' ', $extraopts);
echo behat_command::get_behat_command(true, true, true) . " " . $extraoptstr . PHP_EOL;
}
echo PHP_EOL;
}
// Remove site symlink if necessary.
behat_config_manager::drop_parallel_site_links();
exit($status);
/**
* Signal handler for terminal exit.
*
* @param int $signal signal number.
*/
function signal_handler($signal) {
switch ($signal) {
case SIGTERM:
case SIGKILL:
case SIGINT:
// Remove site symlink if necessary.
behat_config_manager::drop_parallel_site_links();
exit(1);
}
}
/**
* Prints header from the first process.
*
* @param array $processes list of processes to loop though.
*/
function print_process_start_info($processes) {
$printed = false;
// Keep looping though processes, till we get first process o/p.
while (!$printed) {
usleep(10000);
foreach ($processes as $name => $process) {
// Exit if any process has stopped.
if (!$process->isRunning()) {
$printed = true;
break;
}
$op = explode(PHP_EOL, $process->getOutput());
if (count($op) >= 3) {
foreach ($op as $line) {
if (trim($line) && (strpos($line, '.') !== 0)) {
echo $line . PHP_EOL;
}
}
$printed = true;
}
}
}
}
/**
* Loop though all processes and print combined o/p
*
* @param array $processes list of processes to loop though.
* @param bool $stoponfail Stop all processes and exit if failed.
* @return array list of exit codes from all processes.
*/
function print_combined_run_output($processes, $stoponfail = false) {
$exitcodes = array();
$maxdotsonline = 70;
$remainingprintlen = $maxdotsonline;
$progresscount = 0;
while (count($exitcodes) != count($processes)) {
usleep(10000);
foreach ($processes as $name => $process) {
if ($process->isRunning()) {
$op = $process->getIncrementalOutput();
if (trim($op)) {
$update = preg_filter('#^\s*([FS\.\-]+)(?:\s+\d+)?\s*$#', '$1', $op);
// Exit process if anything fails.
if ($stoponfail && (strpos($update, 'F') !== false)) {
$process->stop(0);
}
$strlentoprint = strlen($update ?? '');
// If not enough dots printed on line then just print.
if ($strlentoprint < $remainingprintlen) {
echo $update;
$remainingprintlen = $remainingprintlen - $strlentoprint;
} else if ($strlentoprint == $remainingprintlen) {
$progresscount += $maxdotsonline;
echo $update ." " . $progresscount . PHP_EOL;
$remainingprintlen = $maxdotsonline;
} else {
while ($part = substr($update, 0, $remainingprintlen) > 0) {
$progresscount += $maxdotsonline;
echo $part . " " . $progresscount . PHP_EOL;
$update = substr($update, $remainingprintlen);
$remainingprintlen = $maxdotsonline;
}
}
}
} else {
$exitcodes[$name] = $process->getExitCode();
if ($stoponfail && ($exitcodes[$name] != 0)) {
foreach ($processes as $l => $p) {
$exitcodes[$l] = -1;
$process->stop(0);
}
}
}
}
}
echo PHP_EOL;
return $exitcodes;
}
/**
* Loop though all processes and print combined o/p
*
* @param array $processes list of processes to loop though.
* @param bool $verbose Show verbose output for each process.
*/
function print_each_process_info($processes, $verbose = false, $status = 0) {
foreach ($processes as $name => $process) {
echo "**************** [" . $name . "] ****************" . PHP_EOL;
if ($verbose) {
echo $process->getOutput();
echo $process->getErrorOutput();
} else if ($status) {
// Only show failed o/p.
$runno = str_replace(BEHAT_PARALLEL_SITE_NAME, '', $name);
if ((1 << ($runno - 1)) & $status) {
echo $process->getOutput();
echo $process->getErrorOutput();
} else {
echo get_status_lines_from_run_op($process);
}
} else {
echo get_status_lines_from_run_op($process);
}
echo PHP_EOL;
}
}
/**
* Extract status information from behat o/p and return.
* @param Symfony\Component\Process\Process $process
* @return string
*/
function get_status_lines_from_run_op(Symfony\Component\Process\Process $process) {
$statusstr = '';
$op = explode(PHP_EOL, $process->getOutput());
foreach ($op as $line) {
// Don't print progress .
if (trim($line) && (strpos($line, '.') !== 0) && (strpos($line, 'Moodle ') !== 0) &&
(strpos($line, 'Server OS ') !== 0) && (strpos($line, 'Started at ') !== 0) &&
(strpos($line, 'Browser specific fixes ') !== 0)) {
$statusstr .= $line . PHP_EOL;
}
}
return $statusstr;
}
+501
View File
@@ -0,0 +1,501 @@
<?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 parallel Behat integration in Moodle
*
* All CLI utilities uses $CFG->behat_dataroot and $CFG->prefix_dataroot as
* $CFG->dataroot and $CFG->prefix
* Same applies for $CFG->behat_dbname, $CFG->behat_dbuser, $CFG->behat_dbpass
* and $CFG->behat_dbhost. But if any of those is not defined $CFG->dbname,
* $CFG->dbuser, $CFG->dbpass and/or $CFG->dbhost will be used.
*
* @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!.
}
define('BEHAT_UTIL', true);
define('CLI_SCRIPT', true);
define('NO_OUTPUT_BUFFERING', true);
define('IGNORE_COMPONENT_CACHE', true);
define('ABORT_AFTER_CONFIG', true);
require_once(__DIR__ . '/../../../../lib/clilib.php');
// CLI options.
list($options, $unrecognized) = cli_get_params(
array(
'help' => false,
'install' => false,
'drop' => false,
'enable' => false,
'disable' => false,
'diag' => false,
'parallel' => 0,
'maxruns' => false,
'updatesteps' => false,
'fromrun' => 1,
'torun' => 0,
'optimize-runs' => '',
'add-core-features-to-theme' => false,
'axe' => true,
'scss-deprecations' => false,
),
array(
'h' => 'help',
'j' => 'parallel',
'm' => 'maxruns',
'o' => 'optimize-runs',
'a' => 'add-core-features-to-theme',
)
);
// Checking util.php CLI script usage.
$help = "
Behat utilities to manage the test environment
Usage:
php util.php [--install|--drop|--enable|--disable|--diag|--updatesteps|--no-axe|--scss-deprecations|--help]
[--parallel=value [--maxruns=value]]
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
--diag Get behat test environment status code
--updatesteps Update feature step file.
--no-axe Disable axe accessibility tests.
--scss-deprecations Enable SCSS deprecation checks.
-j, --parallel Number of parallel behat run operation
-m, --maxruns Max parallel processes to be executed at one time.
-o, --optimize-runs Split features with specified tags in all parallel runs.
-a, --add-core-features-to-theme Add all core features to specified theme's
-h, --help Print out this help
Example from Moodle root directory:
\$ php admin/tool/behat/cli/util.php --enable --parallel=4
More info in https://moodledev.io/general/development/tools/behat/running
";
if (!empty($options['help'])) {
echo $help;
exit(0);
}
$cwd = getcwd();
// If Behat parallel site is being initiliased, then define a param to be used to ignore single run install.
if (!empty($options['parallel'])) {
define('BEHAT_PARALLEL_UTIL', true);
}
require_once(__DIR__ . '/../../../../config.php');
require_once(__DIR__ . '/../../../../lib/behat/lib.php');
require_once(__DIR__ . '/../../../../lib/behat/classes/behat_command.php');
require_once(__DIR__ . '/../../../../lib/behat/classes/behat_config_manager.php');
// Remove error handling overrides done in config.php. This is consistent with admin/tool/behat/cli/util_single_run.php.
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;
error_reporting($CFG->debug);
ini_set('display_errors', '1');
ini_set('log_errors', '1');
// Import the necessary libraries.
require_once($CFG->libdir . '/setuplib.php');
require_once($CFG->libdir . '/behat/classes/util.php');
// For drop option check if parallel site.
if ((empty($options['parallel'])) && ($options['drop']) || $options['updatesteps']) {
$options['parallel'] = behat_config_manager::get_behat_run_config_value('parallel');
}
// If not a parallel site then open single run.
if (empty($options['parallel'])) {
// Set run config value for single run.
behat_config_manager::set_behat_run_config_value('singlerun', 1);
chdir(__DIR__);
// Check if behat is initialised, if not exit.
passthru("php util_single_run.php --diag", $status);
if ($status) {
exit ($status);
}
$cmd = commands_to_execute($options);
$processes = cli_execute_parallel(array($cmd), __DIR__);
$status = print_sequential_output($processes, false);
chdir($cwd);
exit($status);
}
// Default torun is maximum parallel runs.
if (empty($options['torun'])) {
$options['torun'] = $options['parallel'];
}
$status = false;
$cmds = commands_to_execute($options);
// Start executing commands either sequential/parallel for options provided.
if ($options['diag'] || $options['enable'] || $options['disable']) {
// Do it sequentially as it's fast and need to be displayed nicely.
foreach (array_chunk($cmds, 1, true) as $cmd) {
$processes = cli_execute_parallel($cmd, __DIR__);
print_sequential_output($processes);
}
} else if ($options['drop']) {
$processes = cli_execute_parallel($cmds, __DIR__);
$exitcodes = print_combined_drop_output($processes);
foreach ($exitcodes as $exitcode) {
$status = (bool)$status || (bool)$exitcode;
}
// Remove run config file.
$behatrunconfigfile = behat_config_manager::get_behat_run_config_file_path();
if (file_exists($behatrunconfigfile)) {
if (!unlink($behatrunconfigfile)) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'Can not delete behat run config file');
}
}
// Remove test file path.
if (file_exists(behat_util::get_test_file_path())) {
if (!unlink(behat_util::get_test_file_path())) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'Can not delete test file enable info');
}
}
} else if ($options['install']) {
// This is intensive compared to behat itself so run them in chunk if option maxruns not set.
if ($options['maxruns']) {
foreach (array_chunk($cmds, $options['maxruns'], true) as $chunk) {
$processes = cli_execute_parallel($chunk, __DIR__);
$exitcodes = print_combined_install_output($processes);
foreach ($exitcodes as $name => $exitcode) {
if ($exitcode != 0) {
echo "Failed process [[$name]]" . PHP_EOL;
echo $processes[$name]->getOutput();
echo PHP_EOL;
echo $processes[$name]->getErrorOutput();
echo PHP_EOL . PHP_EOL;
}
$status = (bool)$status || (bool)$exitcode;
}
}
} else {
$processes = cli_execute_parallel($cmds, __DIR__);
$exitcodes = print_combined_install_output($processes);
foreach ($exitcodes as $name => $exitcode) {
if ($exitcode != 0) {
echo "Failed process [[$name]]" . PHP_EOL;
echo $processes[$name]->getOutput();
echo PHP_EOL;
echo $processes[$name]->getErrorOutput();
echo PHP_EOL . PHP_EOL;
}
$status = (bool)$status || (bool)$exitcode;
}
}
} else if ($options['updatesteps']) {
// Rewrite config file to ensure we have all the features covered.
if (empty($options['parallel'])) {
behat_config_manager::update_config_file('', true, '', $options['add-core-features-to-theme'], false, false);
} else {
// Update config file, ensuring we have up-to-date behat.yml.
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
$CFG->behatrunprocess = $i;
// Update config file for each run.
behat_config_manager::update_config_file('', true, $options['optimize-runs'], $options['add-core-features-to-theme'],
$options['parallel'], $i);
}
unset($CFG->behatrunprocess);
}
// Do it sequentially as it's fast and need to be displayed nicely.
foreach (array_chunk($cmds, 1, true) as $cmd) {
$processes = cli_execute_parallel($cmd, __DIR__);
print_sequential_output($processes);
}
exit(0);
} else {
// We should never reach here.
echo $help;
exit(1);
}
// Ensure we have success status to show following information.
if ($status) {
echo "Unknown failure $status" . PHP_EOL;
exit((int)$status);
}
// Show command o/p (only one per time).
if ($options['install']) {
echo "Acceptance tests site installed for sites:".PHP_EOL;
// Display all sites which are installed/drop/diabled.
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
if (empty($CFG->behat_parallel_run[$i - 1]['behat_wwwroot'])) {
echo $CFG->behat_wwwroot . "/" . BEHAT_PARALLEL_SITE_NAME . $i . PHP_EOL;
} else {
echo $CFG->behat_parallel_run[$i - 1]['behat_wwwroot'] . PHP_EOL;
}
}
} else if ($options['drop']) {
echo "Acceptance tests site dropped for " . $options['parallel'] . " parallel sites" . PHP_EOL;
} else if ($options['enable']) {
echo "Acceptance tests environment enabled on $CFG->behat_wwwroot, to run the tests use:" . PHP_EOL;
echo behat_command::get_behat_command(true, true);
// Save fromrun and to run information.
if (isset($options['fromrun'])) {
behat_config_manager::set_behat_run_config_value('fromrun', $options['fromrun']);
}
if (isset($options['torun'])) {
behat_config_manager::set_behat_run_config_value('torun', $options['torun']);
}
if (isset($options['parallel'])) {
behat_config_manager::set_behat_run_config_value('parallel', $options['parallel']);
}
echo PHP_EOL;
} else if ($options['disable']) {
echo "Acceptance tests environment disabled for " . $options['parallel'] . " parallel sites" . PHP_EOL;
} else if ($options['diag']) {
// Valid option, so nothing to do.
} else {
echo $help;
chdir($cwd);
exit(1);
}
chdir($cwd);
exit(0);
/**
* Create commands to be executed for parallel run.
*
* @param array $options options provided by user.
* @return array commands to be executed.
*/
function commands_to_execute($options) {
$removeoptions = array('maxruns', 'fromrun', 'torun');
$cmds = array();
$extraoptions = $options;
$extra = "";
// Remove extra options not in util_single_run.php.
foreach ($removeoptions as $ro) {
$extraoptions[$ro] = null;
unset($extraoptions[$ro]);
}
foreach ($extraoptions as $option => $value) {
$extra .= behat_get_command_flags($option, $value);
}
if (empty($options['parallel'])) {
$cmds = "php util_single_run.php " . $extra;
} else {
// Create commands which has to be executed for parallel site.
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
$prefix = BEHAT_PARALLEL_SITE_NAME . $i;
$cmds[$prefix] = "php util_single_run.php " . $extra . " --run=" . $i . " 2>&1";
}
}
return $cmds;
}
/**
* Print drop output merging each run.
*
* @param array $processes list of processes.
* @return array exit codes of each process.
*/
function print_combined_drop_output($processes) {
$exitcodes = array();
$maxdotsonline = 70;
$remainingprintlen = $maxdotsonline;
$progresscount = 0;
echo "Dropping tables:" . PHP_EOL;
while (count($exitcodes) != count($processes)) {
usleep(10000);
foreach ($processes as $name => $process) {
if ($process->isRunning()) {
$op = $process->getIncrementalOutput();
if (trim($op)) {
$update = preg_filter('#^\s*([FS\.\-]+)(?:\s+\d+)?\s*$#', '$1', $op);
$strlentoprint = $update ? strlen($update) : 0;
// If not enough dots printed on line then just print.
if ($strlentoprint < $remainingprintlen) {
echo $update;
$remainingprintlen = $remainingprintlen - $strlentoprint;
} else if ($strlentoprint == $remainingprintlen) {
$progresscount += $maxdotsonline;
echo $update . " " . $progresscount . PHP_EOL;
$remainingprintlen = $maxdotsonline;
} else {
while ($part = substr($update, 0, $remainingprintlen) > 0) {
$progresscount += $maxdotsonline;
echo $part . " " . $progresscount . PHP_EOL;
$update = substr($update, $remainingprintlen);
$remainingprintlen = $maxdotsonline;
}
}
}
} else {
// Process exited.
$process->clearOutput();
$exitcodes[$name] = $process->getExitCode();
}
}
}
echo PHP_EOL;
return $exitcodes;
}
/**
* Print install output merging each run.
*
* @param array $processes list of processes.
* @return array exit codes of each process.
*/
function print_combined_install_output($processes) {
$exitcodes = array();
$line = array();
// Check what best we can do to accommodate all parallel run o/p on single line.
// Windows command line has length of 80 chars, so default we will try fit o/p in 80 chars.
if (defined('BEHAT_MAX_CMD_LINE_OUTPUT') && BEHAT_MAX_CMD_LINE_OUTPUT) {
$lengthofprocessline = (int)max(10, BEHAT_MAX_CMD_LINE_OUTPUT / count($processes));
} else {
$lengthofprocessline = (int)max(10, 80 / count($processes));
}
echo "Installing behat site for " . count($processes) . " parallel behat run" . PHP_EOL;
// Show process name in first row.
foreach ($processes as $name => $process) {
// If we don't have enough space to show full run name then show runX.
if ($lengthofprocessline < strlen($name) + 2) {
$name = substr($name, -5);
}
// One extra padding as we are adding | separator for rest of the data.
$line[$name] = str_pad('[' . $name . '] ', $lengthofprocessline + 1);
}
ksort($line);
$tableheader = array_keys($line);
echo implode("", $line) . PHP_EOL;
// Now print o/p from each process.
while (count($exitcodes) != count($processes)) {
usleep(50000);
$poutput = array();
// Create child process.
foreach ($processes as $name => $process) {
if ($process->isRunning()) {
$output = $process->getIncrementalOutput();
if (trim($output)) {
$poutput[$name] = explode(PHP_EOL, $output);
}
} else {
// Process exited.
$exitcodes[$name] = $process->getExitCode();
}
}
ksort($poutput);
// Get max depth of o/p before displaying.
$maxdepth = 0;
foreach ($poutput as $pout) {
$pdepth = count($pout);
$maxdepth = $pdepth >= $maxdepth ? $pdepth : $maxdepth;
}
// Iterate over each process to get line to print.
for ($i = 0; $i <= $maxdepth; $i++) {
$pline = "";
foreach ($tableheader as $name) {
$po = empty($poutput[$name][$i]) ? "" : substr($poutput[$name][$i], 0, $lengthofprocessline - 1);
$po = str_pad($po, $lengthofprocessline);
$pline .= "|". $po;
}
if (trim(str_replace("|", "", $pline))) {
echo $pline . PHP_EOL;
}
}
unset($poutput);
$poutput = null;
}
echo PHP_EOL;
return $exitcodes;
}
/**
* Print install output merging showing one run at a time.
* If any process fail then exit.
*
* @param array $processes list of processes.
* @param bool $showprefix show prefix.
* @return bool exitcode.
*/
function print_sequential_output($processes, $showprefix = true) {
$status = false;
foreach ($processes as $name => $process) {
$shownname = false;
while ($process->isRunning()) {
$op = $process->getIncrementalOutput();
if (trim($op)) {
// Show name of the run once for sequential.
if ($showprefix && !$shownname) {
echo '[' . $name . '] ';
$shownname = true;
}
echo $op;
}
}
// If any error then exit.
$exitcode = $process->getExitCode();
if ($exitcode != 0) {
exit($exitcode);
}
$status = $status || (bool)$exitcode;
}
return $status;
}
+315
View File
@@ -0,0 +1,315 @@
<?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
* Same applies for $CFG->behat_dbname, $CFG->behat_dbuser, $CFG->behat_dbpass
* and $CFG->behat_dbhost. But if any of those is not defined $CFG->dbname,
* $CFG->dbuser, $CFG->dbpass and/or $CFG->dbhost will be used.
*
* @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,
'parallel' => 0,
'run' => 0,
'drop' => false,
'enable' => false,
'disable' => false,
'diag' => false,
'tags' => '',
'updatesteps' => false,
'optimize-runs' => '',
'add-core-features-to-theme' => false,
'axe' => true,
'scss-deprecations' => false,
),
array(
'h' => 'help',
'o' => 'optimize-runs',
'a' => 'add-core-features-to-theme',
)
);
if ($options['install'] or $options['drop']) {
define('CACHE_DISABLE_ALL', true);
}
// Checking util_single_run.php CLI script usage.
$help = "
Behat utilities to manage the test environment
Usage:
php util_single_run.php [--install|--drop|--enable|--disable|--diag|--updatesteps|--help]
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
--diag Get behat test environment status code
--updatesteps Update feature step file.
--no-axe Disable axe accessibility tests.
--scss-deprecations Enable SCSS deprecation checks.
-o, --optimize-runs Split features with specified tags in all parallel runs.
-a, --add-core-features-to-theme Add all core features to specified theme's
-h, --help Print out this help
Example from Moodle root directory:
\$ php admin/tool/behat/cli/util_single_run.php --enable
More info in https://moodledev.io/general/development/tools/behat/running
";
if (!empty($options['help'])) {
echo $help;
exit(0);
}
// Describe this script.
define('BEHAT_UTIL', true);
define('CLI_SCRIPT', true);
define('NO_OUTPUT_BUFFERING', true);
define('IGNORE_COMPONENT_CACHE', true);
// Set run value, to be used by setup for configuring proper CFG variables.
if ($options['run']) {
define('BEHAT_CURRENT_RUN', $options['run']);
}
// Only load CFG from config.php, stop ASAP in lib/setup.php.
define('ABORT_AFTER_CONFIG', true);
require_once(__DIR__ . '/../../../../config.php');
// Remove error handling overrides done in config.php.
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;
error_reporting($CFG->debug);
ini_set('display_errors', '1');
ini_set('log_errors', '1');
// Finish moodle init.
define('ABORT_AFTER_CONFIG_CANCEL', true);
require("$CFG->dirroot/lib/setup.php");
raise_memory_limit(MEMORY_HUGE);
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/upgradelib.php');
require_once($CFG->libdir.'/clilib.php');
require_once($CFG->libdir.'/installlib.php');
require_once($CFG->libdir.'/testing/classes/test_lock.php');
if ($unrecognized) {
$unrecognized = implode(PHP_EOL . " ", $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');
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
// Ensure run option is <= parallel run installed.
$run = 0;
$parallel = 0;
if ($options['run']) {
$run = $options['run'];
// If parallel option is not passed, then try get it form config.
if (!$options['parallel']) {
$parallel = behat_config_manager::get_behat_run_config_value('parallel');
} else {
$parallel = $options['parallel'];
}
if (empty($parallel) || $run > $parallel) {
echo "Parallel runs can't be more then ".$parallel.PHP_EOL;
exit(1);
}
$CFG->behatrunprocess = $run;
}
// Run command (only one per time).
if ($options['install']) {
behat_util::install_site();
// This is only displayed once for parallel install.
if (empty($run)) {
mtrace("Acceptance tests site installed");
}
// Note: Do not build the themes here. This is done during the 'enable' stage.
} else if ($options['drop']) {
// Ensure no tests are running.
test_lock::acquire('behat');
behat_util::drop_site();
// This is only displayed once for parallel install.
if (empty($run)) {
mtrace("Acceptance tests site dropped");
}
} else if ($options['enable']) {
if (!empty($parallel)) {
// Save parallel site info for enable and install options.
behat_config_manager::set_behat_run_config_value('behatsiteenabled', 1);
}
// Configure axe according to option.
behat_config_manager::set_behat_run_config_value('axe', $options['axe']);
// Define whether to run Behat with SCSS deprecation checks.
behat_config_manager::set_behat_run_config_value('scss-deprecations', $options['scss-deprecations']);
// Enable test mode.
$timestart = microtime(true);
mtrace('Creating Behat configuration ...', '');
behat_util::start_test_mode($options['add-core-features-to-theme'], $options['optimize-runs'], $parallel, $run);
mtrace(' done in ' . round(microtime(true) - $timestart, 2) . ' seconds.');
// Themes are only built in the 'enable' command.
behat_util::build_themes(true);
mtrace("Testing environment themes built");
// This is only displayed once for parallel install.
if (empty($run)) {
// Notify user that 2.5 profile has been converted to 3.5.
if (behat_config_manager::$autoprofileconversion) {
mtrace("2.5 behat profile detected, automatically converted to current 3.x format");
}
$runtestscommand = behat_command::get_behat_command(true, !empty($run));
$runtestscommand .= ' --config ' . behat_config_manager::get_behat_cli_config_filepath();
mtrace("Acceptance tests environment enabled on $CFG->behat_wwwroot, to run the tests use: " . PHP_EOL .
$runtestscommand);
}
} else if ($options['disable']) {
behat_util::stop_test_mode($run);
// This is only displayed once for parallel install.
if (empty($run)) {
mtrace("Acceptance tests environment disabled");
}
} else if ($options['diag']) {
$code = behat_util::get_behat_status();
exit($code);
} else if ($options['updatesteps']) {
if (defined('BEHAT_FEATURE_STEP_FILE') && BEHAT_FEATURE_STEP_FILE) {
$behatstepfile = BEHAT_FEATURE_STEP_FILE;
} else {
echo "BEHAT_FEATURE_STEP_FILE is not set, please ensure you set this to writable file" . PHP_EOL;
exit(1);
}
// Run behat command to get steps in feature files.
$featurestepscmd = behat_command::get_behat_command(true);
$featurestepscmd .= ' --config ' . behat_config_manager::get_behat_cli_config_filepath();
$featurestepscmd .= ' --dry-run --format=moodle_stepcount';
$processes = cli_execute_parallel(array($featurestepscmd), __DIR__ . "/../../../../");
$status = print_update_step_output(array_pop($processes), $behatstepfile);
exit($status);
} else {
echo $help;
exit(1);
}
exit(0);
/**
* Print update progress as dots for updating feature file step list.
*
* @param Process $process process executing update step command.
* @param string $featurestepfile feature step file in which steps will be saved.
* @return int exitcode.
*/
function print_update_step_output($process, $featurestepfile) {
$printedlength = 0;
echo "Updating steps feature file for parallel behat runs" . PHP_EOL;
// Show progress while running command.
while ($process->isRunning()) {
usleep(10000);
$op = $process->getIncrementalOutput();
if (trim($op)) {
echo ".";
$printedlength++;
if ($printedlength > 70) {
$printedlength = 0;
echo PHP_EOL;
}
}
}
// If any error then exit.
$exitcode = $process->getExitCode();
// Output err.
if ($exitcode != 0) {
echo $process->getErrorOutput();
exit($exitcode);
}
// Extract features with step info and save it in file.
$featuresteps = $process->getOutput();
$featuresteps = explode(PHP_EOL, $featuresteps);
$realroot = realpath(__DIR__.'/../../../../').'/';
foreach ($featuresteps as $featurestep) {
if (trim($featurestep)) {
$step = explode("::", $featurestep);
$step[0] = str_replace($realroot, '', $step[0]);
$steps[$step[0]] = $step[1];
}
}
if ($existing = @json_decode(file_get_contents($featurestepfile), true)) {
$steps = array_merge($existing, $steps);
}
arsort($steps);
if (!@file_put_contents($featurestepfile, json_encode($steps, JSON_PRETTY_PRINT))) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'File ' . $featurestepfile . ' can not be created');
$exitcode = -1;
}
echo PHP_EOL. "Updated step count in " . $featurestepfile . PHP_EOL;
return $exitcode;
}
+37
View File
@@ -0,0 +1,37 @@
<?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/>.
/**
* Define web service functions for tool_behat
*
* @package tool_behat
* @copyright 2022 onwards Catalyst IT EU {@link https://catalyst-eu.net}
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$functions = [
'tool_behat_get_entity_generator' => [
'classname' => 'tool_behat\\external\\get_entity_generator',
'methodname' => 'execute',
'description' => 'Get the generator details for an entity',
'type' => 'read',
'ajax' => true,
'capabilities' => 'moodle/site:config'
]
];
+62
View File
@@ -0,0 +1,62 @@
<?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');
// This page usually takes an exceedingly long time to load, so we need to
// increase the time limit. At present it takes about a minute on some
// systems, but let's allow room for expansion.
core_php_time_limit::raise(300);
$filter = optional_param('filter', '', PARAM_NOTAGS);
$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.
$behatconfig = new behat_config_util();
$components = $behatconfig->get_components_contexts();
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.
$PAGE->requires->js_call_amd('tool_behat/steps', 'init');
$renderer = $PAGE->get_renderer('tool_behat');
echo $renderer->render_stepsdefinitions($steps, $form);
+54
View File
@@ -0,0 +1,54 @@
<?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['aim'] = 'This administration tool helps developers and test writers to create .feature files describing Moodle\'s functionalities and run them automatically. Step definitions available for use in .feature files are listed below.';
$string['allavailablesteps'] = 'All available step definitions';
$string['errorbehatcommand'] = 'Error running behat CLI command. Try running "{$a} --help" manually from CLI to find out more about the problem.';
$string['errorcomposer'] = 'Composer dependencies are not installed.';
$string['errordataroot'] = '$CFG->behat_dataroot is not set or is invalid.';
$string['errorsetconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot need to be set in config.php.';
$string['erroruniqueconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot values need to be different than $CFG->dataroot, $CFG->prefix, $CFG->wwwroot, $CFG->phpunit_dataroot and $CFG->phpunit_prefix values.<br/>Or, if $CFG->behat_prefix is the same, $CFG->behat_dbname or $CFG->behat_dbhost need to be different from $CFG->phpunit_dbname and $CFG->phpunit_dbhost and from $CFG->dbname and $CFG->dbhost.';
$string['fieldvalueargument'] = 'Field value arguments';
$string['fieldvalueargument_help'] = 'This argument should be completed by a field value. There are many field types, including simple ones like checkboxes, selects or textareas, or complex ones like date selectors. See the dev documentation <a href="https://moodledev.io/general/development/tools/behat" target="_blank">Acceptance_testing</a> for details of expected field values.';
$string['giveninfo'] = 'Given. Processes to set up the environment';
$string['infoheading'] = 'Info';
$string['installinfo'] = 'Read {$a} for installation and tests execution info';
$string['newstepsinfo'] = 'Read {$a} for info about how to add new step definitions';
$string['newtestsinfo'] = 'Read {$a} for info about how to write new tests';
$string['nostepsdefinitions'] = 'There aren\'t any step definitions matching this filter';
$string['pluginname'] = 'Acceptance testing';
$string['stepsdefinitionscomponent'] = 'Area';
$string['stepsdefinitionscontains'] = 'Contains';
$string['stepsdefinitionsfilters'] = 'Step definitions';
$string['stepsdefinitionstype'] = 'Type';
$string['theninfo'] = 'Then. Checkings to ensure the outcomes are the expected ones';
$string['unknownexceptioninfo'] = 'There was a problem with Selenium or your browser. Please ensure you are using the latest version of Selenium. Error:';
$string['viewsteps'] = 'Filter';
$string['warndirrootconfigfound'] = 'A configuration file was found at {$a}. This file is not automatically updated and may become stale. We recommend removing this file.';
$string['wheninfo'] = 'When. Action that provokes an event';
$string['wrongbehatsetup'] = 'Something is wrong with the behat setup and so step definitions cannot be listed: <b>{$a->errormsg}</b><br/><br/>Please check:<ul>
<li>$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot are set in config.php with different values from $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.</li>
<li>You ran "{$a->behatinit}" from your Moodle root directory.</li>
<li>Dependencies are installed in vendor/ and {$a->behatcommand} file has execution permissions.</li></ul>';
$string['privacy:metadata'] = 'The Acceptance testing plugin does not store any personal data.';
+76
View File
@@ -0,0 +1,76 @@
<?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 array System steps or empty array if case there are no steps
*/
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::behat_setup_problem();
// The loaded steps depends on the component specified.
behat_config_manager::update_config_file($component, false);
// The Moodle\BehatExtension\Definition\Printer\ConsoleDefinitionInformationPrinter will parse this search format.
if ($type) {
$filter .= '&&' . $type;
}
if ($filter) {
$filteroption = ' -d ' . escapeshellarg($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);
return $steps;
}
}
+213
View File
@@ -0,0 +1,213 @@
<?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();
require_once($CFG->libdir . '/behat/classes/behat_generator_base.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 mixed $stepsdefinitions Available steps array.
* @param moodleform $form
* @return string HTML code
*/
public function render_stepsdefinitions($stepsdefinitions, $form) {
global $CFG;
require_once($CFG->libdir . '/behat/classes/behat_selectors.php');
$html = $this->output->header();
$html .= $this->output->heading(get_string('pluginname', 'tool_behat'));
$html .= $form->render();
if (empty($stepsdefinitions)) {
$stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
} else {
$stepsdefinitions = implode('', $stepsdefinitions);
// Replace text selector type arguments with a user-friendly select.
$stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/',
function ($matches) {
return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
},
$stepsdefinitions
);
// Replace selector type arguments with a user-friendly select.
$stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/',
function ($matches) {
return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
},
$stepsdefinitions
);
// Replace simple OR options.
$regex = '#\(\?P<[^>]+>([^\)|]+\|[^\)]+)\)#';
$stepsdefinitions = preg_replace_callback($regex,
function($matches){
return html_writer::select(explode('|', $matches[1]), uniqid());
},
$stepsdefinitions
);
$stepsdefinitions = preg_replace_callback('/(FIELD_VALUE_STRING)/',
function ($matches) {
global $CFG;
// Creating a link to a popup with the help.
$url = new moodle_url(
'/help.php',
array(
'component' => 'tool_behat',
'identifier' => 'fieldvalueargument',
'lang' => current_language()
)
);
// Note: this title is displayed only if JS is disabled,
// otherwise the link will have the new ajax tooltip.
$title = get_string('fieldvalueargument', 'tool_behat');
$title = get_string('helpprefix2', '', trim($title, ". \t"));
$attributes = array('href' => $url, 'title' => $title,
'aria-haspopup' => 'true', 'target' => '_blank');
$output = html_writer::tag('a', 'FIELD_VALUE_STRING', $attributes);
return html_writer::tag('span', $output, array('class' => 'helptooltip'));
},
$stepsdefinitions
);
$elementstrings = [];
$count = 1;
$stepsdefinitions = preg_replace_callback('/(the following ")ELEMENT\d?_STRING(" exist:)/',
function($matches) use (&$elementstrings, &$count) {
// Replace element type arguments with a user-friendly select.
if (empty($elementstrings)) {
$behatgenerators = new behat_data_generators();
$componententities = $behatgenerators->get_all_entities();
ksort($componententities);
$elementstrings = [];
foreach ($componententities as $component => $entities) {
asort($entities);
foreach ($entities as $entity) {
$string = ($component === 'core') ? $entity : $component . ' > ' . $entity;
$elementstrings[$string] = $string;
}
}
}
$select = html_writer::select($elementstrings, 'entities' . $count, '', ['' => 'choosedots'],
['class' => 'entities']);
$count++;
return $matches[1] . $select . $matches[2];
},
$stepsdefinitions
);
}
// Steps definitions.
$html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
$html .= $this->output->footer();
return $html;
}
/**
* Renders an error message adding the generic info about the tool purpose and setup.
*
* @param string $msg The error message
* @return string HTML
*/
public function render_error($msg) {
$html = $this->output->header();
$html .= $this->output->heading(get_string('pluginname', 'tool_behat'));
$html .= $this->generic_info();
$a = new stdClass();
$a->errormsg = $msg;
$a->behatcommand = behat_command::get_behat_command();
$a->behatinit = 'php admin' . DIRECTORY_SEPARATOR . 'tool' . DIRECTORY_SEPARATOR .
'behat' . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'init.php';
$msg = get_string('wrongbehatsetup', 'tool_behat', $a);
// Error box including generic error string + specific error msg.
$html .= $this->output->box_start('box errorbox alert alert-danger');
$html .= html_writer::tag('div', $msg);
$html .= $this->output->box_end();
$html .= $this->output->footer();
return $html;
}
/**
* Generic info about the tool.
*
* @return string
*/
public function generic_info() {
// Info.
$installurl = behat_command::DOCS_URL;
$installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank'));
$writetestsurl = 'https://moodledev.io/general/development/tools/behat/writing';
$writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank'));
$writestepsurl = 'https://moodledev.io/general/development/tools/behat/writing#' .
'writing-new-acceptance-test-step-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('div', get_string('aim', 'tool_behat'));
$html .= html_writer::start_tag('div');
$html .= html_writer::start_tag('ul');
$html .= html_writer::start_tag('li');
$html .= implode(html_writer::end_tag('li') . html_writer::start_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();
return $html;
}
}
+31
View 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));
}
@@ -0,0 +1,74 @@
<?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() {
global $PAGE;
$mform = $this->_form;
$output = $PAGE->get_renderer('tool_behat');
$mform->addElement('header', 'info', get_string('infoheading', 'tool_behat'));
$mform->setExpanded('info', false);
$mform->addElement('html', $output->generic_info());
$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->setType('filter', PARAM_NOTAGS);
$mform->addElement('submit', 'submit', get_string('viewsteps', 'tool_behat'));
}
}
+37
View File
@@ -0,0 +1,37 @@
#page-admin-tool-behat-index .steps-definitions {
margin: 1rem auto;
}
#page-admin-tool-behat-index .steps-definitions .step {
margin: 1rem 0 0 0;
border: 1px solid #eee;
padding: 1rem;
}
#page-admin-tool-behat-index .steps-definitions .stepdescription {
font-style: italic;
}
#page-admin-tool-behat-index .steps-definitions .stepcontent {
margin: 1rem 0;
}
#page-admin-tool-behat-index .steps-definitions .steptype {
color: #1467a6;
margin-right: 1ex;
}
#page-admin-tool-behat-index .steps-definitions .stepapipath {
font-family: monospace;
font-size: smaller;
}
#page-admin-tool-behat-index .steps-definitions .stepregex {
color: #060;
}
#page-admin-tool-behat-index .steprequiredfields {
font-weight: bold;
font-size: 1em;
margin-top: 1em;
}
@@ -0,0 +1,33 @@
{{!
This file is part of Moodle - https://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/>.
}}
{{!
@template tool_behat/steprequiredfields
Display a Gherkin-style table row showing required columns for a step.
Example context (json):
{
"fields": [
"user",
"role",
"context"
]
}
}}
<pre class="steprequiredfields">
|{{#fields}} {{{.}}} |{{/fields}}
</pre>
@@ -0,0 +1,412 @@
@tool @tool_behat @javascript
Feature: Set up contextual data for tests
In order to write tests quickly
As a developer
I need to fill the database with fixtures
Scenario: Add a bunch of users
Given the following "users" exist:
| username | password | firstname | lastname |
| testuser | testuser | | |
| testuser2 | testuser2 | TestFirstname | TestLastname |
And I log in as "testuser"
And I log out
When I log in as "testuser2"
Then I should see "TestFirstname"
Scenario: Add a bunch of courses and categories
Given the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
| Cat 2 | CAT1 | CAT2 |
| Cat 3 | CAT1 | CAT3 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | COURSE1 | CAT3 |
| Course 2 | COURSE2 | CAT3 |
| Course 3 | COURSE3 | 0 |
When I log in as "admin"
And I am on site homepage
Then I should see "Course 1"
And I should see "Course 2"
And I should see "Course 3"
And I go to the courses management page
And I follow "Cat 1"
And I should see "Cat 2"
And I should see "Cat 3"
And I follow "Cat 3"
And I should see "Course 1"
And I should see "Course 2"
And I follow "Cat 2"
And I should see "No courses in this category"
And I follow "Category 1"
And I should see "Course 3"
Scenario: Add a bunch of groups and groupings
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
And the following "groupings" exist:
| name | course | idnumber |
| Grouping 1 | C1 | GG1 |
| Grouping 2 | C1 | GG2 |
When I log in as "admin"
And I am on the "Course 1" "groups" page
Then I should see "Group 1"
And I should see "Group 2"
And I set the field "Participants tertiary navigation" to "Groupings"
And I should see "Grouping 1"
And I should see "Grouping 2"
Scenario: Role overrides
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| mod/forum:editanypost | Allow | student | Course | C1 |
| mod/forum:replynews | Prevent | editingteacher | Course | C1 |
When I log in as "admin"
And I am on the "Course 1" "permissions" page
And I set the field "Advanced role override" to "Student (1)"
Then "mod/forum:editanypost" capability has "Allow" permission
And I press "Cancel"
And I set the field "Advanced role override" to "Teacher (1)"
And "mod/forum:replynews" capability has "Prevent" permission
And I press "Cancel"
Scenario: Add course enrolments
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
When I am on the "Course 1" course page logged in as student1
Then I should see "New section"
Scenario: Add role assigns
Given the following "roles" exist:
| name | shortname | description | archetype |
| Custom editing teacher | custom1 | My custom role 1 | editingteacher |
| Custom student | custom2 | | |
And the following "users" exist:
| username | firstname | lastname | email |
| user1 | User | 1 | user1@example.com |
| user2 | User | 2 | user2@example.com |
| user3 | User | 3 | user3@example.com |
| user4 | User | 4 | user4@example.com |
| user5 | User | 5 | user5@example.com |
And the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | CAT1 |
And the following "course enrolments" exist:
| user | course | role |
| user4 | C1 | custom1 |
| user2 | C1 | student |
| user3 | C1 | editingteacher |
And the following "role assigns" exist:
| user | role | contextlevel | reference |
| user1 | manager | System | |
| user2 | editingteacher | Category | CAT1 |
| user5 | custom2 | System | |
When I log in as "user1"
And I am on site homepage
Then edit mode should be available on the current page
And I am on the "Course 1" course page logged in as user2
Then edit mode should be available on the current page
And I am on the "Course 1" course page logged in as user3
Then edit mode should be available on the current page
And I am on the "Course 1" course page logged in as user4
Then edit mode should be available on the current page
And I log out
And I log in as "user5"
And I should see "You are logged in as"
And I am on "Course 1" course homepage
And I should see "You cannot enrol yourself in this course."
Scenario: Add modules
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And I enable "chat" "mod" plugin
And I enable "survey" "mod" plugin
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| assign | Test assignment name | Test assignment description | C1 | assign1 |
| book | Test book name | Test book description | C1 | book1 |
| chat | Test chat name | Test chat description | C1 | chat1 |
| choice | Test choice name | Test choice description | C1 | choice1 |
| data | Test database name | Test database description | C1 | data1 |
| feedback | Test feedback name | Test feedback description | C1 | feedback1 |
| folder | Test folder name | Test folder description | C1 | folder1 |
| forum | Test forum name | Test forum description | C1 | forum1 |
| glossary | Test glossary name | Test glossary description | C1 | glossary1 |
| imscp | Test imscp name | Test imscp description | C1 | imscp1 |
| label | Test label name | Test label description | C1 | label1 |
| lesson | Test lesson name | Test lesson description | C1 | lesson1 |
| lti | Test lti name | Test lti description | C1 | lti1 |
| page | Test page name | Test page description | C1 | page1 |
| quiz | Test quiz name | Test quiz description | C1 | quiz1 |
| resource | Test resource name | Test resource description | C1 | resource1 |
| scorm | Test scorm name | Test scorm description | C1 | scorm1 |
| survey | Test survey name | Test survey description | C1 | survey1 |
| url | Test url name | Test url description | C1 | url1 |
| wiki | Test wiki name | Test wiki description | C1 | wiki1 |
| workshop | Test workshop name | Test workshop description | C1 | workshop1 |
And the following "scales" exist:
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
And the following "activities" exist:
| activity | name | intro | course | idnumber | grade |
| assign | Test assignment name with scale | Test assignment description | C1 | assign1 | Test Scale 1 |
When I am on the "Course 1" course page logged in as admin
Then I should see "Test assignment name"
# Assignment 2.2 module type is disabled by default
# And I should see "Test assignment22 name"
And I should see "Test book name"
And I should see "Test chat name"
And I should see "Test choice name"
And I should see "Test database name"
# Feedback module type is disabled by default
# And I should see "Test feedback name"
And I should see "Test folder name"
And I should see "Test forum name"
And I should see "Test glossary name"
And I should see "Test imscp name"
# We don't see label name, we see only description:
And I should see "Test label description"
And I should see "Test lesson name"
And I should see "Test lti name"
And I should see "Test page name"
And I should see "Test quiz name"
And I should see "Test resource name"
And I should see "Test scorm name"
And I should see "Test survey name"
And I should see "Test url name"
And I should see "Test wiki name"
And I should see "Test workshop name"
And I follow "Test assignment name"
And I should see "Test assignment description"
And I am on "Course 1" course homepage
And I follow "Test assignment name with scale"
And I follow "Settings"
And the field "Type" matches value "Scale"
Scenario: Add relations between users and groups
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
And the following "groupings" exist:
| name | course | idnumber |
| Grouping 1 | C1 | GG1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G2 |
And the following "grouping groups" exist:
| grouping | group |
| GG1 | G1 |
When I log in as "admin"
And I am on the "Course 1" "groups" page
Then the "groups" select box should contain "Group 1 (1)"
And the "groups" select box should contain "Group 2 (1)"
And I set the field "groups" to "Group 1 (1)"
And the "members" select box should contain "Student 1 (student1@example.com)"
And I set the field "groups" to "Group 2 (1)"
And the "members" select box should contain "Student 2 (student2@example.com)"
Scenario: Add cohorts and cohort members with data generator
Given the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
And the following "cohorts" exist:
| name | idnumber |
| System cohort A | CHSA |
And the following "cohorts" exist:
| name | idnumber | contextlevel | reference |
| System cohort B | CHSB | System | |
| Cohort in category | CHC | Category | CAT1 |
| Empty cohort | CHE | Category | CAT1 |
And the following "cohort members" exist:
| user | cohort |
| student1 | CHSA |
| student2 | CHSB |
| student1 | CHSB |
| student1 | CHC |
When I log in as "admin"
And I navigate to "Users > Accounts > Cohorts" in site administration
Then the following should exist in the "reportbuilder-table" table:
| Name | Cohort size |
| System cohort A | 1 |
| System cohort B | 2 |
And I should not see "Cohort in category"
And I am on course index
And I follow "Cat 1"
And I navigate to "Cohorts" in current page administration
And I should not see "System cohort"
And the following should exist in the "reportbuilder-table" table:
| Name | Cohort size |
| Cohort in category | 1 |
| Empty cohort | 0 |
Scenario: Add grade categories with data generator
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "grade categories" exist:
| fullname | course |
| Grade category 1 | C1 |
And the following "grade categories" exist:
| fullname | course | gradecategory |
| Grade sub category 2 | C1 | Grade category 1 |
When I am on the "Course 1" "grades > Grader report > View" page logged in as "admin"
Then I should see "Grade category 1"
And I should see "Grade sub category 2"
Scenario: Add a bunch of grade items
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "grade categories" exist:
| fullname | course |
| Grade category 1 | C1 |
And the following "grade categories" exist:
| fullname | course | gradecategory |
| Grade sub category 2 | C1 | Grade category 1 |
And the following "grade items" exist:
| itemname | course |
| Test Grade Item 1 | C1 |
And the following "grade items" exist:
| itemname | course | gradecategory |
| Test Grade Item 2 | C1 | Grade category 1 |
| Test Grade Item 3 | C1 | Grade sub category 2 |
When I am on the "Course 1" "grades > gradebook setup" page logged in as "admin"
Then I should see "Test Grade Item 1"
And I click on grade item menu "Test Grade Item 1" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Course 1"
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
And I should see "Grade category 1"
And I should see "Test Grade Item 2"
And I click on grade item menu "Test Grade Item 2" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Grade category 1"
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
And I should see "Grade sub category 2"
And I should see "Test Grade Item 3"
And I click on grade item menu "Test Grade Item 3" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Grade sub category 2"
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
Scenario: Add a bunch of scales
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "scales" exist:
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
When I am on the "Course 1" "grades > scales" page logged in as admin
Then I should see "Test Scale 1"
And I should see "Disappointing, Good, Very good, Excellent"
Scenario: Add a bunch of outcomes
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "scales" exist:
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
And the following "grade outcomes" exist:
| fullname | shortname | scale |
| Grade outcome 1 | OT1 | Test Scale 1 |
And the following "grade outcomes" exist:
| fullname | shortname | course | scale |
| Grade outcome 2 | OT2 | C1 | Test Scale 1 |
And the following config values are set as admin:
| enableoutcomes | 1 |
When I am on the "Course 1" "grades > outcomes" page logged in as admin
Then I should see "Grade outcome 1" in the "#addoutcomes" "css_element"
And I should see "Grade outcome 2" in the "#removeoutcomes" "css_element"
And I press "Manage outcomes"
And the following should exist in the "generaltable" table:
| Full name | Short name | Scale |
| Grade outcome 2 | OT2 | Test Scale 1 |
Scenario: Add a bunch of outcome grade items
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "scales" exist:
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
And the following "grade outcomes" exist:
| fullname | shortname | course | scale |
| Grade outcome 1 | OT1 | C1 | Test Scale 1 |
And the following "grade categories" exist:
| fullname | course |
| Grade category 1 | C1 |
And the following "grade items" exist:
| itemname | course | outcome | gradecategory |
| Test Outcome Grade Item 1 | C1 | OT1 | Grade category 1 |
And the following config values are set as admin:
| enableoutcomes | 1 |
When I am on the "Course 1" "grades > gradebook setup" page logged in as "admin"
Then I should see "Test Outcome Grade Item 1"
And I click on grade item menu "Test Outcome Grade Item 1" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I click on "Show more..." "link" in the "Edit outcome item" "dialogue"
And the field "Outcome" matches value "Grade outcome 1"
And I should see "Grade category 1" in the "Grade category" "form_row"
And I press "Cancel"
Scenario: Add a block
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| online_users | Course | C1 | course-view-* | site-pre |
When I am on the "Course 1" course page logged in as admin
Then I should see "Online users"
@@ -0,0 +1,25 @@
@tool @tool_behat
Feature: Transform date time string arguments
In order to write tests with relative date and time
As a user
I need to apply some transformations to the steps arguments
Scenario: Set date in table and check date with specific format
Given I am on site homepage
And the following "users" exist:
| username | firstname | lastname |
| teacher1 | Teacher | 1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | duedate |
| assign | C1 | assign1 | Test assignment name | Test assignment description | ##yesterday## |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "##yesterday##%d %B %Y##"
And I log out
@@ -0,0 +1,90 @@
@tool @tool_behat
Feature: Edit capabilities
In order to extend and restrict moodle features
As an admin or a teacher
I need to allow/deny the existing capabilities at different levels
Background:
Given the following "users" exist:
| username | firstname | lastname |
| teacher1 | Teacher | 1 |
| tutor | Teaching | Assistant |
| student | Student | One |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| tutor | C1 | teacher |
| student | C1 | student |
Scenario: Default system capabilities modification
Given I log in as "admin"
And I navigate to "Users > Permissions > Define roles" in site administration
And I click on "Edit Teacher role" "link"
And I fill the capabilities form with the following permissions:
| capability | permission |
| block/mnet_hosts:myaddinstance | Allow |
| moodle/site:messageanyuser | Inherit |
| moodle/grade:managesharedforms | Prevent |
| moodle/course:request | Prohibit |
And I press "Save changes"
When I follow "Edit Teacher role"
Then "block/mnet_hosts:myaddinstance" capability has "Allow" permission
And "moodle/site:messageanyuser" capability has "Not set" permission
And "moodle/grade:managesharedforms" capability has "Prevent" permission
And "moodle/course:request" capability has "Prohibit" permission
Scenario: Course capabilities overrides
Given I log in as "teacher1"
And I am on the "Course 1" "permissions" page
And I override the system permissions of "Student" role with:
| mod/forum:deleteanypost | Prohibit |
| mod/forum:editanypost | Prevent |
| mod/forum:addquestion | Allow |
When I set the field "Advanced role override" to "Student (3)"
# There are two select elements and go buttons and we want to press the second one.
And I click on "//div[@class='advancedoverride']/div/form/noscript/input" "xpath_element"
Then "mod/forum:deleteanypost" capability has "Prohibit" permission
And "mod/forum:editanypost" capability has "Prevent" permission
And "mod/forum:addquestion" capability has "Allow" permission
Scenario: Module capabilities overrides
Given the following "activity" exists:
| activity | forum |
| course | C1 |
| idnumber | 00001 |
| name | I'm the name |
And I am on the "I'm the name" "forum activity" page logged in as teacher1
And I navigate to "Permissions" in current page administration
And I override the system permissions of "Student" role with:
| mod/forum:deleteanypost | Prohibit |
| mod/forum:editanypost | Prevent |
| mod/forum:addquestion | Allow |
When I set the field "Advanced role override" to "Student (3)"
And I click on "//div[@class='advancedoverride']/div/form/noscript/input" "xpath_element"
Then "mod/forum:deleteanypost" capability has "Prohibit" permission
And "mod/forum:editanypost" capability has "Prevent" permission
And "mod/forum:addquestion" capability has "Allow" permission
@javascript
Scenario: Edit permissions escapes role names correctly
When I am on the "Course 1" "renameroles" page logged in as "admin"
And I set the following fields to these values:
| Your word for 'Teacher' | Teacher >= editing |
| Your word for 'Non-editing teacher' | Teacher < "editing" |
| Your word for 'Student' | Studier & 'learner' |
And I press "Save"
And I navigate to course participants
Then I should see "Teacher >= editing (Teacher)" in the "Teacher 1" "table_row"
And I should see "Teacher < \"editing\" (Non-editing teacher)" in the "Teaching Assistant" "table_row"
And I should see "Studier & 'learner' (Student)" in the "Student One" "table_row"
And I am on the "C1" "permissions" page
And I should see "Teacher >= editing (Teacher)" in the "mod/forum:replypost" "table_row"
And I should see "Teacher < \"editing\" (Non-editing teacher)" in the "mod/forum:replypost" "table_row"
And I should see "Studier & 'learner' (Student)" in the "mod/forum:replypost" "table_row"
And I follow "Prohibit"
And "Teacher >= editing (Teacher)" "button" in the "Prohibit role" "dialogue" should be visible
And "Teacher < \"editing\" (Non-editing teacher)" "button" in the "Prohibit role" "dialogue" should be visible
And "Studier & 'learner' (Student)" "button" in the "Prohibit role" "dialogue" should be visible
@@ -0,0 +1,34 @@
<?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/>.
/**
* Display environment used for running behat.
*
* This file is used for behat testing to ensure cli and apache
* version of environment is same.
*
* @package tool_behat
* @copyright 2016 onwards Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../../../../../config.php');
// Only continue for behat site.
defined('BEHAT_SITE_RUNNING') || die();
require_once($CFG->libdir.'/behat/classes/util.php');
echo json_encode(behat_util::get_environment(), true);
@@ -0,0 +1,201 @@
@tool_behat
Feature: Verify that all form fields values can be get and set
In order to use behat steps definitions
As a test writer
I need to verify it all works in real moodle forms
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "users" exist:
| username | email | firstname | lastname |
| student1 | s1@example.com | Student | 1 |
| student2 | s2@example.com | Student | 2 |
| student3 | s3@example.com | Student | 3 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| admin | C1 | editingteacher |
And the following "groups" exist:
| name | description | course | idnumber |
| Group 1 | G1 description | C1 | G1 |
| Group 2 | G1 description | C1 | G2 |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G1 |
| student2 | G2 |
| student3 | G2 |
And the following "activities" exist:
| activity | course | idnumber | name | firstpagetitle | wikimode | visible |
| wiki | C1 | wiki1 | Test this one | Test this one | collaborative | 0 |
And I am on the "Course 1" "reset" page logged in as admin
# Select (multi-select) - Checking "the select box should contain".
And I expand all fieldsets
And the "Unenrol users" select box should contain "No roles"
And the "Unenrol users" select box should contain "Student"
And the "Unenrol users" select box should contain "Non-editing teacher"
And the "Unenrol users" select box should contain "Teacher"
And the "Unenrol users" select box should contain "Manager"
And the "Unenrol users" select box should contain "No roles, Student, Non-editing teacher, Teacher, Manager"
And the "Unenrol users" select box should contain "Manager, Teacher, Non-editing teacher, Student, No roles"
And the "Unenrol users" select box should not contain "President"
And the "Unenrol users" select box should not contain "Baker"
And the "Unenrol users" select box should not contain "President, Baker"
And I am on "Course 1" course homepage with editing mode on
And I am on the "Test this one" "wiki activity" page
And I press "Create page"
# Text (textarea & editor) & Select (multi-select) - Checking "I set the following fields to these values".
When I set the following fields to these values:
| HTML format | Student page contents |
And I press "Save"
Then I should see "Student page contents" in the "region-main" "region"
# Select (multi-select) - Checking "I set the field".
And I navigate to "Settings" in current page administration
And I expand all fieldsets
# Checkbox - Checking "I set the field" and "The field matches value" ticked.
And I set the field "Force format" to "1"
And I press "Save and return to course"
And I am on the "Test this one" "wiki activity editing" page
And I expand all fieldsets
And the field "Force format" matches value "1"
And the field "Force format" does not match value ""
# Checkbox - Checking "I set the field" and "The field matches value" unticked.
And I set the field "Force format" to ""
And I press "Save and return to course"
And I am on the "Test this one" "wiki activity editing" page
And I expand all fieldsets
And the field "Force format" matches value ""
And the field "Force format" does not match value "1"
# Checkbox - Checking "I set the following fields to these values:" and "The following fields match these values" ticked.
And I set the following fields to these values:
| Force format | 1 |
And I press "Save and return to course"
And I am on the "Test this one" "wiki activity editing" page
And I expand all fieldsets
And the following fields match these values:
| Force format | 1 |
And the following fields do not match these values:
| Force format | |
# Checkbox - Checking "I set the following fields to these values:" and "The following fields match these values" unticked.
And I set the following fields to these values:
| Force format | |
And I press "Save and return to course"
And I am on the "Test this one" "wiki activity editing" page
And I expand all fieldsets
And the following fields match these values:
| Force format | |
And the following fields do not match these values:
| Force format | 1 |
# Select (simple) - Checking "I set the following fields to these values:".
And I set the following fields to these values:
| Default format | NWiki |
# Select (simple) - Checking "I set the field".
And I set the field "Group mode" to "Separate groups"
And I press "Save and display"
And I navigate to "Settings" in current page administration
And the following fields match these values:
| Default format | NWiki |
| Group mode | Separate groups |
# All fields - Checking "the following fields do not match these values".
And the following fields do not match these values:
| Wiki name | Test this one baby |
| Default format | HTML |
And I press "Cancel"
# Radio - Checking "I set the field" and "the field matches value".
And the following "activity" exists:
| activity | choice |
| course | C1 |
| idnumber | choice1 |
| intro | Test choice description |
| name | Test choice name |
| choice1 | Option 1, Option 2, Option 3 |
| section | 1 |
| allowupdate | 1 |
And I am on "Course 1" course homepage
And I am on the "Test choice name" "choice activity editing" page
And I set the field "Option 1" to "one"
And I set the field "Option 2" to "two"
And I set the field "Option 3" to "three"
And I press "Save and return to course"
And I am on "Course 1" course homepage
And I am on the "Test choice name" "choice activity" page
And I set the field "one" to "1"
And I press "Save my choice"
And the field "one" matches value "1"
And the field "two" matches value ""
# Check if field xpath set/match works.
And I am on "Course 1" course homepage
And I navigate to "Settings" in current page administration
And I set the field with xpath "//input[@id='id_idnumber']" to "Course id number"
And the field with xpath "//input[@name='idnumber']" matches value "Course id number"
And the field with xpath "//input[@name='idnumber']" does not match value ""
And I press "Save and display"
And I navigate to "Settings" in current page administration
And the field "Course ID number" matches value "Course id number"
@javascript
Scenario: with JS enabled all form fields getters and setters works as expected
Given the following "activities" exist:
| activity | course | name |
| lesson | C1 | Test lesson |
Then I am on the "Course 1" "groups" page
# Select (multi-select & AJAX) - Checking "I set the field" and "select box should contain".
And I set the field "groups" to "Group 2"
And the "members" select box should contain "Student 2 (s2@example.com)"
And the "members" select box should contain "Student 3 (s3@example.com)"
And the "members" select box should not contain "Student 1 (s1@example.com)"
And I set the field "groups" to "Group 1"
And the "members" select box should contain "Student 1 (s1@example.com)"
And the "members" select box should contain "Student 2 (s2@example.com)"
And the "members" select box should not contain "Student 3 (s3@example.com)"
# Checkbox (AJAX) - Checking "I set the field" and "I set the following fields to these values".
And I am on the "Test lesson" "lesson activity editing" page
And I set the following fields to these values:
| available[enabled] | 1 |
And I set the field "deadline[enabled]" to "1"
# Checkbox (AJAX) - Checking "the field matches value" before saving.
And the field "available[enabled]" matches value "1"
And the "available[day]" "field" should be enabled
And the field "deadline[enabled]" matches value "1"
And I press "Save and display"
And I navigate to "Settings" in current page administration
And the field "available[enabled]" matches value "1"
And the "available[day]" "field" should be enabled
And the field "deadline[enabled]" matches value "1"
And I press "Cancel"
# Advanced checkbox requires real browser to allow uncheck to work. MDL-58681. MDL-55386.
# Advanced checkbox - Checking "I set the field" and "The field matches value" ticked.
And I am on the "Test choice name" "choice activity editing" page
And I set the field "Display description on course page" to "1"
And I press "Save and return to course"
And I am on the "Test choice name" "choice activity editing" page
And the field "Display description on course page" matches value "1"
And the field "Display description on course page" does not match value ""
# Advanced checkbox - Checking "I set the field" and "The field matches value" unticked.
And I set the field "Display description on course page" to ""
And I press "Save and return to course"
And I am on the "Test choice name" "choice activity editing" page
And the field "Display description on course page" matches value ""
And the field "Display description on course page" does not match value "1"
# Advanced checkbox - Checking "I set the following fields to these values:" and "The following fields match these values" ticked.
And I set the following fields to these values:
| Display description on course page | 1 |
And I press "Save and return to course"
And I am on the "Test choice name" "choice activity editing" page
And the following fields match these values:
| Display description on course page | 1 |
And the following fields do not match these values:
| Display description on course page | |
# Advanced checkbox - Checking "I set the following fields to these values:" and "The following fields match these values" unticked.
And I set the following fields to these values:
| Display description on course page | |
And I press "Save and return to course"
And I am on the "Test choice name" "choice activity editing" page
And the following fields match these values:
| Display description on course page | |
And the following fields do not match these values:
| Display description on course page | 1 |
@@ -0,0 +1,31 @@
@tool_behat
Feature: Behat steps for interacting with form work
In order to test my Moodle code
As a developer
I need the Behat steps for form elements to work reliably
@javascript
Scenario: Test fields in containers
Given the following "courses" exist:
| fullname | shortname | summary | summaryformat |
| Course 1 | C1 | Red | 1 |
When I log in as "admin"
And I am on "Course 1" course homepage
# Just get to any form.
And I navigate to "Settings" in current page administration
And I set the field "Course full name" in the "General" "fieldset" to "Frog"
And I set the following fields in the "Appearance" "fieldset" to these values:
| Show activity reports | Yes |
| Number of announcements | 1 |
And I set the following fields in the "Description" "fieldset" to these values:
| Course summary | Green |
Then the field "Show activity reports" in the "Appearance" "fieldset" matches value "Yes"
And the field "Show activity reports" in the "Appearance" "fieldset" does not match value "No"
And the following fields in the "region-main" "region" match these values:
| Course full name | Frog |
| Number of announcements | 1 |
| Course summary | Green |
And the following fields in the "region-main" "region" do not match these values:
| Course full name | Course 1 |
| Number of announcements | 5 |
| Course summary | Red |
@@ -0,0 +1,85 @@
@tool @tool_behat
Feature: Use core page resolvers for the I am on the page steps
In order to write tests correctly
As a developer
I need to have steps which take me straight to a page
Scenario Outline: When I am on an instance
Given the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "course" exists:
| fullname | Economics 101 |
| shortname | ECON101 |
| idnumber | 2021-econ101 |
And the following "activity" exists:
| course | ECON101 |
| activity | forum |
| name | Fundamentals of Economics |
| idnumber | fundamentalsofeconomics |
And I log in as "admin"
When I am on the <identifier> <type> page
Then I should see "<shouldsee>"
Examples:
| description | identifier | type | shouldsee |
| Course Category idnumber | CAT1 | category | Add a new course |
| Course Category name | "Cat 1" | Category | Add a new course |
| Course Full name | "Economics 101" | course | Fundamentals of Economics |
| Course Short name | ECON101 | COURSE | Fundamentals of Economics |
| Course idnumber | "2021-econ101" | Course | Fundamentals of Economics |
| Forum idnumber | fundamentalsofeconomics | Activity | Add discussion topic |
| Generic activity editing | fundamentalsofeconomics | "Activity editing" | Edit settings |
| Forum name | "Fundamentals of Economics" | "Forum activity" | Add discussion topic |
| Forum name editing | "Fundamentals of Economics" | "Forum activity editing" | Edit settings |
| Forum name permissions | "Fundamentals of Economics" | "Forum activity permissions" | Permissions in Forum: Fun |
| Forum name roles | "Fundamentals of Economics" | "Forum activity roles" | Assign roles in Forum: Fun |
Scenario Outline: When I am on an instance logged in as
Given the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "course" exists:
| fullname | Economics 101 |
| shortname | ECON101 |
| idnumber | 2021-econ101 |
And the following "activity" exists:
| course | ECON101 |
| activity | forum |
| name | Fundamentals of Economics |
| idnumber | fundamentalsofeconomics |
When I am on the <identifier> <type> page logged in as admin
Then I should see "<shouldsee>"
Examples:
| description | identifier | type | shouldsee |
| Course Category idnumber | CAT1 | category | Add a new course |
| Course Category name | "Cat 1" | Category | Add a new course |
| Course Full name | "Economics 101" | course | Fundamentals of Economics |
| Course Short name | ECON101 | COURSE | Fundamentals of Economics |
| Course idnumber | "2021-econ101" | Course | Fundamentals of Economics |
| Forum idnumber | fundamentalsofeconomics | Activity | Add discussion topic |
| Generic activity editing | fundamentalsofeconomics | "Activity editing" | Edit settings |
| Forum name | "Fundamentals of Economics" | "Forum activity" | Add discussion topic |
| Forum name editing | "Fundamentals of Economics" | "Forum activity editing" | Edit settings |
| Forum name permissions | "Fundamentals of Economics" | "Forum activity permissions" | Permissions in Forum: Fun |
| Forum name roles | "Fundamentals of Economics" | "Forum activity roles" | Assign roles in Forum: Fun |
Scenario Outline: When I am on a named page
Given I log in as "admin"
When I am on the <identifier> page
Then I should see "<shouldsee>"
Examples:
| description | identifier | shouldsee |
| Admin page | "Admin notifications" | Check for available updates |
| Home page | Homepage | Calendar |
Scenario Outline: When I am on a named page logged in as
When I am on the <identifier> page logged in as admin
Then I should see "<shouldsee>"
Examples:
| description | identifier | shouldsee |
| Admin page | "Admin notifications" | Check for available updates |
| Home page | Homepage | Calendar |
@@ -0,0 +1,30 @@
@tool_behat
Feature: Verify that the inplace editable field works as expected
In order to use behat step definitions
As a test write
I need to ensure that the inplace editable works in forms
Background:
Given the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
And the following "activities" exist:
| activity | course | name | idnumber |
| forum | C1 | My first forum | forum1 |
| assign | C1 | My first assignment | assign1 |
| quiz | C1 | My first quiz | quiz1 |
And I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
@javascript
Scenario: Using an inplace editable updates the name of an activity
When I set the field "Edit title" in the "My first assignment" "activity" to "Coursework submission"
Then I should see "Coursework submission"
And I should not see "My first assignment"
But I should see "My first forum"
And I should see "My first quiz"
And I set the field "Edit title" in the "Coursework submission" "activity" to "My first assignment"
And I should not see "Coursework submission"
But I should see "My first assignment"
And I should see "My first forum"
And I should see "My first quiz"
@@ -0,0 +1,52 @@
@tool_behat
Feature: Verify that keyboard steps work as expected
In order to use behat step definitions
As a test writer
I need to verify that the keyboard steps work as expected
@javascript
Scenario: Typing keys into a field causes them to be input
Given the following "users" exist:
| username | email | firstname | lastname | password |
| saffronr | saffron.rutledge@example.com | Saffron | Rutledge | flowerpower |
Given I click on "Log in" "link"
And I click on "Username" "field"
When I type "saffronr"
And I press the tab key
And I type "flowerpower"
And I press enter
Then I should see "You are logged in as Saffron Rutledge"
@javascript
Scenario: Using tab changes focus to the next or previous field
Given I click on "Log in" "link"
And I click on "Username" "field"
And the focused element is "Username" "field"
When I press the tab key
Then the focused element is "Password" "field"
And I press the shift tab key
And the focused element is "Username" "field"
@javascript
Scenario: Using the arrow keys allows me to navigate through menus
Given the following "users" exist:
| username | email | firstname | lastname |
| saffronr | saffron.rutledge@example.com | Saffron | Rutledge |
And I log in as "saffronr"
And I click on "User menu" "button" in the ".usermenu" "css_element"
When I press the up key
Then the focused element is "Log out" "link"
@javascript
Scenario: The escape key can be used to close a dialogue
Given the following "course" exists:
| fullname | C1|
| shortname | C1 |
And I log in as "admin"
And I am on "C1" course homepage
And I navigate to course participants
And I press "Enrol users"
And "Enrol users" "dialogue" should be visible
When I press the escape key
Then "Enrol users" "dialogue" should not be visible
@@ -0,0 +1,48 @@
@tool @tool_behat
Feature: List the system steps definitions
In order to create new tests
As a tests writer
I need to list and filter the system steps definitions
Background:
Given I am on homepage
And I log in as "admin"
And I navigate to "Development > Acceptance testing" in site administration
@javascript
Scenario: Accessing the list
Then I should see "Step definitions"
And I should not see "There aren't steps definitions matching this filter"
And I should not see "the following \"ELEMENT_STRING\" exist:"
And "entities1" "select" should exist
And the "entities1" select box should contain "users"
And the "entities1" select box should contain "mod_assign > submissions"
@javascript
Scenario: Filtering by type
Given I set the field "Type" to "Then. Checkings to ensure the outcomes are the expected ones"
When I press "Filter"
Then I should see "Checks, that page contains specified text."
And I should not see "Opens Moodle homepage."
@javascript
Scenario: Filtering by keyword
Given I set the field "Contains" to "homepage"
When I press "Filter"
Then I should see "Opens Moodle homepage."
@javascript
Scenario: Filtering by the multiple words pattern
Given I set the field "Contains" to "should exist"
When I press "Filter"
Then I should not see "There aren't steps definitions matching this filter"
And I should see "Checks the provided element and selector type exists in the current page."
And I should see "Checks that an element and selector type exists in another element and selector type on the current page."
@javascript
Scenario: Get required fields
Given I set the field "entities1" to "users"
And I should see "| username |"
When I set the field "entities1" to "mod_quiz > user overrides"
Then I should not see "| username |"
And I should see "| quiz | user |"
@@ -0,0 +1,110 @@
@tool_behat
Feature: Verify that the behat login and logout steps work as expected
In order to use behat login and log out steps
As a test writer
I need to verify that login and logout happen when the steps are used
Scenario: Log in as a user using the step
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
When I log in as "traverst1"
Then I should see "Thomas Travers"
@javascript
Scenario: Log in as a user using the step (javascript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
When I log in as "traverst1"
Then I should see "Thomas Travers"
Scenario: Log out using the log out step
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
And I am logged in as traverst1
When I log out
Then I should not see "Thomas Travers"
And I should see "You are not logged in"
@javascript
Scenario: Log out using the log out step (javascript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
And I am logged in as traverst1
When I log out
Then I should not see "Thomas Travers"
And I should see "You are not logged in"
Scenario: Log in step should automatically log user out if already logged in
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
| emeryj | Jane | Emery |
And I am logged in as traverst1
When I log in as "emeryj"
Then I should not see "Thomas Travers"
And I should see "Jane Emery"
@javascript
Scenario: Log in step should automatically log user out if already logged in (javascript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
| emeryj | Jane | Emery |
And I am logged in as traverst1
When I log in as "emeryj"
Then I should not see "Thomas Travers"
And I should see "Jane Emery"
Scenario: I am on page logged in as should redirect to correct page
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
And the following "course" exists:
| fullname | Life, the Universe, and Everything |
| shortname | hhgttg |
When I am on the hhgttg Course page logged in as traverst1
Then I should see "Thomas Travers"
And I should see "Life, the Universe, and Everything"
@javascript
Scenario: I am on page logged in as should redirect to correct page (javascript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
And the following "course" exists:
| fullname | Life, the Universe, and Everything |
| shortname | hhgttg |
When I am on the hhgttg Course page logged in as traverst1
Then I should see "Thomas Travers"
And I should see "Life, the Universe, and Everything"
Scenario: I am on page logged in as should redirect to correct page when automatically logging a user out
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
| emeryj | Jane | Emery |
And the following "course" exists:
| fullname | Life, the Universe, and Everything |
| shortname | hhgttg |
And I am logged in as emeryj
When I am on the hhgttg Course page logged in as traverst1
Then I should see "Thomas Travers"
And I should see "Life, the Universe, and Everything"
@javascript
Scenario: I am on page logged in as should redirect to correct page when automatically logging a user out (javacript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
| emeryj | Jane | Emery |
And the following "course" exists:
| fullname | Life, the Universe, and Everything |
| shortname | hhgttg |
And I am logged in as emeryj
When I am on the hhgttg Course page logged in as traverst1
Then I should see "Thomas Travers"
And I should see "Life, the Universe, and Everything"
@@ -0,0 +1,32 @@
@tool @tool_behat
Feature: Forms manipulation
In order to interact with Moodle
As a user
I need to set forms values
@javascript
Scenario: Basic forms manipulation
Given I log in as "admin"
And I open my profile in edit mode
When I set the field "First name" to "Field value"
And I set the field "Select a country" to "Japan"
And I set the field "New password" to "TestPass"
Then the field "First name" matches value "Field value"
And the "Select a country" select box should contain "Japan"
And the field "New password" matches value "TestPass"
@javascript
Scenario: Expand all fieldsets and advanced elements
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | course | section | name |
| quiz | C1 | 1 | Quiz 1 |
And I am on the "Quiz 1" "quiz activity editing" page logged in as admin
When I expand all fieldsets
Then I should see "Close the quiz"
And I should see "Group mode"
And I should see "ID number"
And I should not see "Show more..." in the "region-main" "region"
And I should see "Show less..."
@@ -0,0 +1,58 @@
@tool @tool_behat
Feature: Transform steps arguments
In order to write tests with complex nasty arguments
As a tests writer
I need to apply some transformations to the steps arguments
Background:
Given I am on site homepage
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And I log in as "admin"
And I open my profile in edit mode
Scenario: Use nasty strings on steps arguments
When I set the field "Last name" to "$NASTYSTRING1"
And I set the field "Description" to "$NASTYSTRING2"
And I set the field "City/town" to "$NASTYSTRING3"
And I press "Update profile"
And I click on "Edit profile" "link" in the "region-main" "region"
Then I should not see "NASTYSTRING"
And the field "Last name" matches value "$NASTYSTRING1"
And the field "City/town" matches value "$NASTYSTRING3"
Scenario: Use nasty strings on table nodes
When I set the following fields to these values:
| Last name | $NASTYSTRING1 |
| Description | $NASTYSTRING2 |
| City/town | $NASTYSTRING3 |
And I press "Update profile"
And I click on "Edit profile" "link" in the "region-main" "region"
Then I should not see "NASTYSTRING"
And the field "Last name" matches value "$NASTYSTRING1"
And the field "City/town" matches value "$NASTYSTRING3"
Scenario: Use double quotes
When I set the following fields to these values:
| First name | va"lue1 |
| Description | va\"lue2 |
And I set the field "City/town" to "va\"lue3"
And I press "Update profile"
And I click on "Edit profile" "link" in the "region-main" "region"
Then I should not see "NASTYSTRING"
And the field "First name" matches value "va\"lue1"
And the field "Description" matches value "va\\"lue2"
And the field "City/town" matches value "va\"lue3"
Scenario: Nasty strings with other contents
When I set the field "First name" to "My Firstname $NASTYSTRING1"
And I set the following fields to these values:
| Last name | My Last name $NASTYSTRING2 |
And I press "Update profile"
And I click on "Edit profile" "link" in the "region-main" "region"
Then I should not see "NASTYSTRING"
And I should see "My Firstname"
And I should see "My Last name"
And the field "First name" matches value "My Firstname $NASTYSTRING1"
And the field "Last name" matches value "My Last name $NASTYSTRING2"
+34
View File
@@ -0,0 +1,34 @@
@tool_behat
Feature: Confirm that we can open multiple browser tabs
In order to use multiple browser tabs
As a test writer
I need the relevant Behat steps to work
@javascript @_switch_window
Scenario: Open multiple browser tabs
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
| Course 2 | C2 |
| Course 3 | C3 |
And I am on the "C1" "Course" page logged in as "admin"
# Open a new tab on the same page.
When I open a tab named "CourseViewer1" on the current page
And I should see "Course 1" in the "h1" "css_element"
And I am on the "C2" "Course" page
# Open new tab for specified page with identifier.
And I open a tab named "CourseViewer2" on the "C3" "Course" page
# And for a specified page without identifier.
And I open a tab named "CourseViewer4" on the "My courses" page
# Switch between all the tabs and confirm their different contents.
Then I should see "You're not enrolled in any course"
And I switch to "CourseViewer2" tab
And "Course 3" "heading" should exist
And I switch to "CourseViewer1" tab
And "Course 2" "heading" should exist
And I switch to the main tab
And "Course 1" "heading" should exist
@@ -0,0 +1,9 @@
@tool @tool_behat
Feature: Set up the testing environment
In order to execute automated acceptance tests
As a developer
I need to use the test environment instead of the regular environment
Scenario: Accessing the site
When I am on site homepage
Then I should see "Acceptance test site"
@@ -0,0 +1,191 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Tests for behat_form_text class
*
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_behat;
use behat_form_text;
use Behat\Mink\Session;
use Behat\Mink\Element\NodeElement;
use core_string_manager_standard;
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->libdir . '/behat/classes/behat_session_interface.php');
require_once($CFG->libdir . '/behat/classes/behat_session_trait.php');
require_once($CFG->libdir . '/behat/form_field/behat_form_text.php');
/**
* Tests for the behat_form_text class
*
* @package tool_behat
* @category test
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @covers \behat_form_text
* @covers \behat_form_field
*/
class behat_form_text_test extends \basic_testcase {
/**
* Data provider for the test_set_get_value() method.
*
* @return array of value and expectation pairs to be tested.
*/
public function provider_test_set_get_value() {
return [
'null' => [null, null],
'int' => [3, 3],
'float' => [3.14, 3.14],
'string' => ['hello', 'hello'],
'utf8' => ['你好', '你好'],
];
}
/**
* Test the set_value() and get_value() methods.
*
* @param mixed $value value to be set.
* @param mixed $expectation value to be checked.
* @dataProvider provider_test_set_get_value()
*/
public function test_set_get_value($value, $expectation): void {
$session = $this->createMock(Session::class);
$node = $this->createMock(NodeElement::class);
$node->method('getValue')->willReturn($value);
$field = new behat_form_text($session, $node);
$field->set_value($value);
$this->assertEquals($expectation, $field->get_value());
}
/**
* Data provider for the test_text_matches() method.
*
* @return array of decsep, value, match and result pairs to be tested.
*/
public function provider_test_matches() {
return [
'lazy true' => ['.', 'hello', 'hello', true],
'lazy false' => ['.', 'hello', 'bye', false],
'float true' => ['.', '3.14', '3.1400', true],
'float false' => ['.', '3.14', '3.1401', false],
'float and float string true' => ['.', 3.14, '3.1400', true],
'float and unrelated string false' => ['.', 3.14, 'hello', false],
'float hash decsep true' => ['#', '3#14', '3#1400', true],
'float hash decsep false' => ['#', '3#14', '3#1401', false],
'float and float string hash decsep true' => ['#', 3.14, '3.1400', true],
'float and unrelated string hash decsep false' => ['#', 3.14, 'hello', false],
'float custom-default decsep mix1 true' => ['#', '3#14', '3.1400', true],
'float custom-default decsep mix2 true' => ['#', '3.14', '3#1400', true],
'float 2-custom decsep mix1 false' => ['#', '3#14', '3,1400', false],
'float 2-custom decsep mix2 false' => [',', '3#14', '3,1400', false],
'float default-custom decsep mix1 false' => ['.', '3#14', '3.1400', false],
'float default-custom decsep mix2 false' => ['.', '3.14', '3#1400', false],
];
}
/**
* Test the matches() method.
*
* @param string $decsep decimal separator to use.
* @param mixed $value value to be set.
* @param mixed $match value to be matched.
* @param bool $result expected return status of the function.
* @dataProvider provider_test_matches()
*/
public function test_matches($decsep, $value, $match, $result): void {
global $CFG;
// Switch of string manager to avoid having to (slow) customise the lang file.
$origcustom = $CFG->config_php_settings['customstringmanager'] ?? null;
$CFG->config_php_settings['customstringmanager'] = '\tool_behat\phpunit_string_manager';
$manager = get_string_manager(true);
$manager->set_string('decsep', 'langconfig', $decsep);
$session = $this->createMock(Session::class);
$node = $this->createMock(NodeElement::class);
$node->method('getValue')->willReturn($value);
$field = new behat_form_text($session, $node);
$field->set_value($value);
$this->assertSame($result, $field->matches($match));
// Switch back to the original string manager.
if (is_null($origcustom)) {
unset($CFG->config_php_settings['customstringmanager']);
} else {
$CFG->config_php_settings['customstringmanager'] = $origcustom;
}
$manager = get_string_manager(true);
}
}
/**
* Customised values that will be used instead of standard manager one.
*
* If an existing component/identifier is found, return it instead of the real
* one from language files. Note this doesn't support place holders or another niceties.
*
* @package tool_behat
* @category test
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class phpunit_string_manager extends core_string_manager_standard {
/** @var array language customisations provided by the manager without asking for real contents */
protected $customstrings = [];
/**
* Get String returns a requested string
*
* @param string $identifier The identifier of the string to search for
* @param string $component The module the string is associated with
* @param string|object|array $a An object, string or number that can be used
* within translation strings
* @param string $lang moodle translation language, null means use current
* @return string The String !
*/
public function get_string($identifier, $component = '', $a = null, $lang = null) {
$key = trim($component) . '/' . trim($identifier);
if (isset($this->customstrings[$key])) {
return $this->customstrings[$key];
}
return parent::get_string($identifier, $component, $a, $lang);
}
/**
* Sets a custom string to be returned by the string manager instead of the language file one.
*
* @param string $identifier The identifier of the string to search for
* @param string $component The module the string is associated with
* @param string $value the contents of the language string to be returned by get_string()
*/
public function set_string($identifier, $component, $value) {
$key = trim($component) . '/' . trim($identifier);
$this->customstrings[$key] = $value;
}
}
@@ -0,0 +1,104 @@
<?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 get_entity_generator web service
*
* @package tool_behat
* @copyright 2022 onwards Catalyst IT EU {@link https://catalyst-eu.net}
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_behat\external;
/**
* Tests for get_entity_generator web service
*
* @covers \tool_behat\external\get_entity_generator
*/
class get_entity_generator_test extends \advanced_testcase {
/**
* Log in as admin
*
* @return void
*/
public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
/**
* Get the generator for a core entity.
*
* @return void
*/
public function test_execute_core_entity(): void {
$generator = get_entity_generator::execute('users');
$this->assertEquals(['required' => ['username']], $generator);
}
/**
* Get the generator for the plugin entity.
*
* @return void
*/
public function test_execute_plugin_entity(): void {
$generator = get_entity_generator::execute('mod_book > chapters');
$this->assertEquals(['required' => ['book', 'title', 'content']], $generator);
}
/**
* Get the generator for an entity with no required fields.
*
* @return void
*/
public function test_execute_no_requried(): void {
$generator = get_entity_generator::execute('mod_forum > posts');
$this->assertEquals(['required' => []], $generator);
}
/**
* Attempt to get the generator for a core entity that does not exist.
*
* @return void
*/
public function test_execute_invalid_entity(): void {
$this->expectException('coding_exception');
get_entity_generator::execute('foo');
}
/**
* Attempt to get a generator form a plugin that does not exist.
*
* @return void
*/
public function test_execute_invalid_plugin(): void {
$this->expectException('coding_exception');
get_entity_generator::execute('foo > bar');
}
/**
* Attempt to get a generator for an entity that does not exist, from a plugin that does.
*
* @return void
*/
public function test_execute_invalid_plugin_entity(): void {
$this->expectException('coding_exception');
get_entity_generator::execute('mod_book > bar');
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
/**
* Test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_test_context_1 extends behat_base {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
/**
* Test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_test_context_2 extends behat_base {
}
+9
View File
@@ -0,0 +1,9 @@
@behat_test @test1
Feature: Test feature 1
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
+8
View File
@@ -0,0 +1,8 @@
@behat_test @test2
Feature: Test feature 2
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../../lib/behat/behat_base.php');
/**
* Default Theme test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_defaulttheme_test_context_1 extends behat_base {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 1 overriding test_1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../core/behat_test_context_1.php');
/**
* Theme test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_nofeatures_behat_test_context_2 extends behat_test_context_2 {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../../lib/behat/behat_base.php');
/**
* Theme test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_nofeatures_test_context_1 extends behat_base {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 1 overriding test_1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../core/behat_test_context_1.php');
/**
* Theme test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_withfeatures_behat_test_context_1 extends behat_test_context_1 {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../../lib/behat/behat_base.php');
/**
* Theme test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_withfeatures_test_context_2 extends behat_base {
}
@@ -0,0 +1,9 @@
@behat_test @test1 @testtheme @commontag
Feature: Test feature 1
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,9 @@
@behat_test @test2 @testtheme @commontag
Feature: Test feature 2
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,9 @@
@behat_test @test3 @testtheme
Feature: Test feature 3
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,9 @@
@behat_test @test4 @testtheme
Feature: Test feature 4
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,9 @@
@behat_test @test5 @testtheme
Feature: Test feature 5
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,705 @@
<?php
// phpcs:ignoreFile
// @codeCoverageIgnoreStart
// 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 behat manager.
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_behat;
use behat_config_util;
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');
/**
* Behat manager tests.
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manager_util_test extends \advanced_testcase {
/** @var array Fixtures features which are available. */
private $featurepaths = array(
'default' => array(
'test_1.feature',
'test_2.feature',
),
'withfeatures' => array(
'theme_test_1.feature',
'theme_test_2.feature',
'theme_test_3.feature',
'theme_test_4.feature',
'theme_test_5.feature',
),
'nofeatures' => array()
);
/** @var array Fixture contexts which are available */
private $contextspath = array(
'default' => array(
'behat_test_context_1',
'behat_test_context_2',
'behat_theme_defaulttheme_test_context_1'
),
'withfeatures' => array(
'behat_test_context_2',
'behat_theme_withfeatures_test_context_2',
'behat_theme_withfeatures_behat_test_context_1'
),
'nofeatures' => array(
'behat_test_context_1',
'behat_theme_nofeatures_test_context_1',
'behat_theme_nofeatures_behat_test_context_2'
),
);
/** @var array List of core features. */
private $corefeatures = array('test_1_core_fixtures_tests_behat_tool' => __DIR__.'/fixtures/core/test_1.feature',
'test_2_core_fixtures_tests_behat_tool' => __DIR__.'/fixtures/core/test_2.feature');
/** @var array List of core contexts. */
private $corecontexts = array('behat_test_context_1' => __DIR__.'/fixtures/core/behat_test_context_1.php',
'behat_test_context_2' => __DIR__.'/fixtures/core/behat_test_context_2.php');
/**
* Setup test.
*/
public function setUp(): void {
global $CFG;
$this->resetAfterTest();
$CFG->behat_wwwroot = 'http://example.com/behat';
}
/**
* Utility function to build mock object.
*
* @param behat_config_util $behatconfigutil
* @param bool $notheme
* @return mixed
*/
private function get_behat_config_util($behatconfigutil, $notheme = false) {
// Create a map of arguments to return values.
$map = array(
array('withfeatures', __DIR__.'/fixtures/theme/withfeatures'),
array('nofeatures', __DIR__.'/fixtures/theme/nofeatures'),
array('defaulttheme', __DIR__.'/fixtures/theme/defaulttheme'),
);
// List of themes is const for test.
if ($notheme) {
$themelist = array('defaulttheme');
} else {
$themelist = array('withfeatures', 'nofeatures', 'defaulttheme');
}
$thememap = [];
foreach ($themelist as $themename) {
$mock = $this->getMockBuilder('theme_config');
$mock->disableOriginalConstructor();
$thememap[] = [$themename, $mock->getMock()];
}
$behatconfigutil->expects($this->any())
->method('get_list_of_themes')
->will($this->returnValue($themelist));
// Theme directory for testing.
$behatconfigutil->expects($this->any())
->method('get_theme_test_directory')
->will($this->returnValueMap($map));
// Theme directory for testing.
$behatconfigutil->expects($this->any())
->method('get_theme_config')
->will($this->returnValueMap($thememap));
$behatconfigutil->expects($this->any())
->method('get_default_theme')
->will($this->returnValue('defaulttheme'));
return $behatconfigutil;
}
/**
* Behat config for single run.
*/
public function test_get_config_file_contents_with_single_run() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
// Two suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// Check features.
foreach ($this->featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for single run with no theme installed.
*/
public function test_get_config_file_contents_with_single_run_no_theme() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil, true);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
// Two suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(1, $suites);
$featurepaths = array(
'default' => array(
'test_1.feature',
'test_2.feature',
)
);
$contextspath = array(
'default' => array(
'behat_test_context_1',
'behat_test_context_2',
'behat_theme_defaulttheme_test_context_1',
)
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 3 step definitions.
$this->assertCount(3, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for parallel run.
*/
public function test_get_config_file_contents_with_parallel_run() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Test first run out of 3.
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '', 3, 1);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is first feature file in first run.
$featurepaths = array(
'default' => array('test_1.feature'),
'withfeatures' => array('theme_test_1.feature', 'theme_test_2.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
// Test second run out of 3.
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 2);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is second feature file in first run.
$featurepaths = array(
'default' => array('test_2.feature'),
'withfeatures' => array('theme_test_3.feature', 'theme_test_4.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
// Test third run out of 3.
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 3);
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is second feature file in first run.
$featurepaths = array(
'default' => array(),
'withfeatures' => array('theme_test_5.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for parallel run.
*/
public function test_get_config_file_contents_with_parallel_run_optimize_tags() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Test first run out of 3.
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '@commontag', 3, 1);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is first feature file in first run.
$featurepaths = array(
'default' => array('test_1.feature'),
'withfeatures' => array('theme_test_1.feature', 'theme_test_3.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
// Test second run out of 3.
$config = $behatconfigutil->get_config_file_contents('', '', '@commontag', 3, 2);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is second feature file in first run.
$featurepaths = array(
'default' => array('test_2.feature'),
'withfeatures' => array('theme_test_2.feature', 'theme_test_4.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
// Test third run out of 3.
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 3);
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is second feature file in first run.
$featurepaths = array(
'default' => array(),
'withfeatures' => array('theme_test_5.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Test if clean features key and path is returned.
* @dataProvider clean_features_path_list
*/
public function test_get_clean_feature_key_and_path($featurepath, $key, $cleanfeaturepath) {
global $CFG;
// This is a hack so directory name is correctly detected in tests.
//FIXME: MDL-55722 work out why this is necessary..
$oldroot = $CFG->dirroot;
$CFG->dirroot = 'C:';
$behatconfigutil = new behat_config_util();
// Fix expected directory path for OS.
$cleanfeaturepath = testing_cli_fix_directory_separator($cleanfeaturepath);
list($retkey, $retcleanfeaturepath) = $behatconfigutil->get_clean_feature_key_and_path($featurepath);
$this->assertEquals($key, $retkey);
$this->assertEquals($cleanfeaturepath, $retcleanfeaturepath);
//FIXME: MDL-55722 work out why this is necessary..
$CFG->dirroot = $oldroot;
}
public function clean_features_path_list() {
return array(
['/home/test/this/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_this_test', '/home/test/this/that/test/behat/mod_assign.feature'],
['/home/this/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_this_home', '/home/this/that/test/behat/mod_assign.feature'],
['/home/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_home', '/home/that/test/behat/mod_assign.feature'],
['/home/test/behat/mod_assign.feature', 'mod_assign_behat_test_home', '/home/test/behat/mod_assign.feature'],
['mod_assign.feature', 'mod_assign', 'mod_assign.feature'],
['C:\test\this\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that_this_test', 'C:\test\this\that\test\behat\mod_assign.feature'],
['C:\this\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that_this', 'C:\this\that\test\behat\mod_assign.feature'],
['C:\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that', 'C:\that\test\behat\mod_assign.feature'],
['C:\test\behat\mod_assign.feature', 'mod_assign_behat_test', 'C:\test\behat\mod_assign.feature'],
['C:\mod_assign.feature', 'mod_assign', 'C:\mod_assign.feature'],
);
}
/**
* Behat config for blacklisted tags.
*/
public function test_get_config_file_contents_with_blacklisted_tags() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Blacklisted tags.
$map = array(
array('withfeatures', 'tags', array('@test1')),
array('nofeatures', 'tags', array('@test2')),
array('defaulttheme', 'tags', array()),
array('withfeatures', 'features', array()),
array('nofeatures', 'features', array()),
array('defaulttheme', 'features', array()),
array('withfeatures', 'contexts', array()),
array('nofeatures', 'contexts', array()),
array('defaulttheme', 'contexts', array())
);
$behatconfigutil->expects($this->any())
->method('get_blacklisted_tests_for_theme')
->will($this->returnValueMap($map));
$behatconfigutil->set_theme_suite_to_include_core_features(true);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
$featurepaths = array(
'default' => array('test_1.feature', 'test_2.feature'),
'withfeatures' => array('test_2.feature', 'theme_test_1.feature', 'theme_test_2.feature', 'theme_test_3.feature',
'theme_test_4.feature', 'theme_test_5.feature'),
'nofeatures' => array('test_1.feature')
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for blacklisted features.
*/
public function test_get_config_file_contents_with_blacklisted_features_contexts() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Blacklisted features and contexts.
$map = array(
array('withfeatures', 'tags', array()),
array('nofeatures', 'tags', array()),
array('defaulttheme', 'tags', array()),
array('withfeatures', 'features', array('admin/tool/behat/tests/fixtures/core/test_1.feature')),
array('nofeatures', 'features', array('admin/tool/behat/tests/fixtures/core/test_2.feature')),
array('defaulttheme', 'features', array()),
array('withfeatures', 'contexts', array('admin/tool/behat/tests/fixtures/core/behat_test_context_2.php')),
array('nofeatures', 'contexts', array('admin/tool/behat/tests/fixtures/core/behat_test_context_1.php')),
array('defaulttheme', 'contexts', array()),
);
$behatconfigutil->expects($this->any())
->method('get_blacklisted_tests_for_theme')
->will($this->returnValueMap($map));
$behatconfigutil->set_theme_suite_to_include_core_features(true);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
$featurepaths = array(
'default' => array('test_1.feature', 'test_2.feature'),
'withfeatures' => array('test_2.feature', 'theme_test_1.feature', 'theme_test_2.feature', 'theme_test_3.feature',
'theme_test_4.feature', 'theme_test_5.feature'),
'nofeatures' => array('test_1.feature')
);
$contextspath = array(
'default' => array(
'behat_test_context_1',
'behat_test_context_2',
'behat_theme_defaulttheme_test_context_1',
),
'withfeatures' => array(
'behat_theme_withfeatures_test_context_2',
'behat_theme_withfeatures_behat_test_context_1'
),
'nofeatures' => array(
'behat_theme_nofeatures_test_context_1',
'behat_theme_nofeatures_behat_test_context_2'
),
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for blacklisted tags.
*/
public function test_core_features_to_include_in_specified_theme() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Check features when, no theme is specified.
$behatconfigutil->set_theme_suite_to_include_core_features('');
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$suites = $config['default']['suites'];
foreach ($this->featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check features when all themes are specified.
$featurepaths = $this->featurepaths;
$featurepaths['withfeatures'] = array_merge ($featurepaths['default'], $featurepaths['withfeatures']);
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
$behatconfigutil->set_theme_suite_to_include_core_features('ALL');
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$suites = $config['default']['suites'];
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check features when all themes are specified.
$featurepaths = $this->featurepaths;
$featurepaths['withfeatures'] = array_merge ($featurepaths['default'], $featurepaths['withfeatures']);
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
$behatconfigutil->set_theme_suite_to_include_core_features('withfeatures, nofeatures');
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$suites = $config['default']['suites'];
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check features when specified themes are passed..
$featurepaths = $this->featurepaths;
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
$behatconfigutil->set_theme_suite_to_include_core_features('nofeatures');
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$suites = $config['default']['suites'];
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
}
}
// @codeCoverageIgnoreEnd
+21
View File
@@ -0,0 +1,21 @@
This files describes API changes in the tool_behat code.
=== 4.3 ===
* The goutte behat mink driver has been replaced by the browserkit one because the former has been abandoned. The change should
be completely transparent for (near) everybody. Only if you are using some custom-generated behat.yml file or other configuration
alternatives different from the Moodle default one, then, any "goutte" browser occurrence needs to be changed to "browserkit_http"
when configuring the behat mink extension. See MDL-78934 for more details and changes applied.
=== 4.2 ===
* Behat is initialised with Axe accessibility tests enabled by default, if you want to disable them please use the --no-axe option.
=== 3.7 ===
* Behat will now look for behat step definitions in the current
theme and any parents the theme may have.
=== 2.7 ===
* Constants behat_base::cap_allow, behat_base::cap_prevent and
behat_base::cap_prohibit have been removed in favour of the
lang/en/role.php language strings 'allow', 'prevent' and 'prohibit'.
* @_only_local tag used in .feature files replaced by @_file_upload tag
* @_alerts tag used in .feature files replaced by @_alert tag
+29
View 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 = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'tool_behat'; // Full name of the plugin (used for diagnostics)