mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-75282 editor_tiny: Add ability to set value regardless of the editor
This is a follow-on part to MDL-75887. Part of MDL-75966.
This commit is contained in:
parent
ebc7d31232
commit
1bd0ad6fa3
1 changed files with 29 additions and 1 deletions
|
@ -35,7 +35,35 @@ require_once(__DIR__ . '/../../../../behat/behat_base.php');
|
||||||
* @category test
|
* @category test
|
||||||
* @copyright 2022 Andrew Lyons <andrew@nicols.co.uk>
|
* @copyright 2022 Andrew Lyons <andrew@nicols.co.uk>
|
||||||
*/
|
*/
|
||||||
class behat_editor_tiny extends behat_base {
|
class behat_editor_tiny extends behat_base implements \core_behat\settable_editor {
|
||||||
|
/**
|
||||||
|
* Set the value for the editor.
|
||||||
|
*
|
||||||
|
* Note: This function is called by the behat_form_editor class.
|
||||||
|
* It is called regardless of the current default editor as editor selection is a user preference.
|
||||||
|
* Therefore it must fail gracefully and only set a value if the editor instance was found on the page.
|
||||||
|
*
|
||||||
|
* @param string $editorid
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function set_editor_value(string $editorid, string $value): void {
|
||||||
|
if (!$this->running_javascript()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$js = <<<EOF
|
||||||
|
require(['editor_tiny/editor'], (editor) => {
|
||||||
|
const instance = editor.getInstanceForElementId('${editorid}');
|
||||||
|
if (instance) {
|
||||||
|
instance.setContent('${value}');
|
||||||
|
instance.undoManager.add();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
$this->execute_script($js);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Tiny as default editor before executing Tiny tests.
|
* Set Tiny as default editor before executing Tiny tests.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue