mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-75105_400_STABLE' of https://github.com/marxjohnson…
…/moodle into MOODLE_400_STABLE
- Loading branch information
Showing
14 changed files
with
460 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}; |
88 changes: 88 additions & 0 deletions
88
admin/tool/behat/classes/external/get_entity_generator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?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; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir . '/externallib.php'); | ||
require_once($CFG->dirroot . '/vendor/autoload.php'); // Ensure we can load Behat and Facebook namespaces in behat libraries. | ||
require_once($CFG->libdir . '/tests/behat/behat_data_generators.php'); | ||
|
||
/** | ||
* 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 { | ||
$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 | ||
), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.