3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Moodle editor field.
23 * @copyright 2012 David Monllaó
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
29 use Behat\Mink\Element\NodeElement as NodeElement;
31 require_once(__DIR__ . '/behat_form_field.php');
34 * Moodle editor field.
36 * @todo Support for multiple editors
39 * @copyright 2012 David Monllaó
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class behat_form_editor extends behat_form_field {
45 * Sets the value to a field.
47 * @param string $value
50 public function set_value($value) {
52 // Set the value to the iframe and save it to the textarea.
53 $editorid = $this->field->getAttribute('id');
54 $this->session->executeScript('tinyMCE.get("'.$editorid.'").setContent("' . $value . '");');
55 $this->session->executeScript('tinyMCE.get("'.$editorid.'").save();');
59 * Returns the editor value.
63 public function get_value() {
65 // Save the current iframe value in case default value has been edited.
66 $editorid = $this->field->getAttribute('id');
67 $this->session->executeScript('tinyMCE.get("'.$editorid.'").save();');
69 return $this->field->getValue();