From ebc7d3123269a87b550563f2ed0d880907a698c7 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 29 Aug 2022 20:47:45 +0800 Subject: [PATCH] MDL-75282 editor_tiny: Always use Tiny for @tiny tests This is a subsequent part of MDL-75886 relating to the introduction of TinyMCE. Part of MDL-75966 --- .../tiny/tests/behat/behat_editor_tiny.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 lib/editor/tiny/tests/behat/behat_editor_tiny.php diff --git a/lib/editor/tiny/tests/behat/behat_editor_tiny.php b/lib/editor/tiny/tests/behat/behat_editor_tiny.php new file mode 100644 index 00000000000..4a8eb7dd73f --- /dev/null +++ b/lib/editor/tiny/tests/behat/behat_editor_tiny.php @@ -0,0 +1,67 @@ +. + +/** + * TinyMCE custom steps definitions. + * + * @package editor_tiny + * @category test + * @copyright 2022 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use Behat\Behat\Hook\Scope\BeforeScenarioScope; + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. +require_once(__DIR__ . '/../../../../behat/behat_base.php'); + +/** + * TinyMCE custom behat step definitions. + * + * @package editor_tiny + * @category test + * @copyright 2022 Andrew Lyons + */ +class behat_editor_tiny extends behat_base { + /** + * Set Tiny as default editor before executing Tiny tests. + * + * This step is required to ensure that TinyMCE is set as the current default editor as it may + * not always be the default editor. + * + * Any Scenario, or Feature, which has the `editor_tiny` tag, or any `tiny_*` tag will have + * this step executed before the Scenario. + * + * @BeforeScenario + * @param BeforeScenarioScope $scope The Behat Scope + */ + public function set_default_editor_flag(BeforeScenarioScope $scope): void { + // This only applies to a scenario which matches the editor_tiny, or an tiny subplugin. + $callback = function (string $tag): bool { + return $tag === 'editor_tiny' || substr($tag, 0, 5) === 'tiny_'; + }; + + if (!self::scope_tags_match($scope, $callback)) { + // This scope does not require TinyMCE. Exit now. + return; + } + + // TinyMCE is a JavaScript editor so require JS here. + $this->require_javascript(); + + $this->execute('behat_general::the_default_editor_is_set_to', ['tiny']); + } +}