[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Moodle editor field. 19 * 20 * @package core_form 21 * @category test 22 * @copyright 2012 David Monllaó 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. 27 28 use Behat\Mink\Element\NodeElement as NodeElement; 29 30 require_once (__DIR__ . '/behat_form_textarea.php'); 31 32 /** 33 * Moodle editor field. 34 * 35 * @todo Support for multiple editors 36 * @package core_form 37 * @category test 38 * @copyright 2012 David Monllaó 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class behat_form_editor extends behat_form_textarea { 42 43 /** 44 * Sets the value to a field. 45 * 46 * @param string $value 47 * @return void 48 */ 49 public function set_value($value) { 50 51 $editorid = $this->field->getAttribute('id'); 52 if ($this->running_javascript()) { 53 $value = addslashes($value); 54 $js = ' 55 var editor = Y.one(document.getElementById("'.$editorid.'editable")); 56 if (editor) { 57 editor.setHTML("' . $value . '"); 58 } 59 editor = Y.one(document.getElementById("'.$editorid.'")); 60 editor.set("value", "' . $value . '"); 61 '; 62 $this->session->executeScript($js); 63 } else { 64 parent::set_value($value); 65 } 66 } 67 68 /** 69 * Select all the text in the form field. 70 * 71 */ 72 public function select_text() { 73 // NodeElement.keyPress simply doesn't work. 74 if (!$this->running_javascript()) { 75 throw new coding_exception('Selecting text requires javascript.'); 76 } 77 78 $editorid = $this->field->getAttribute('id'); 79 $js = ' (function() { 80 var e = document.getElementById("'.$editorid.'editable"), 81 r = rangy.createRange(), 82 s = rangy.getSelection(); 83 84 while ((e.firstChild !== null) && (e.firstChild.nodeType != document.TEXT_NODE)) { 85 e = e.firstChild; 86 } 87 e.focus(); 88 r.selectNodeContents(e); 89 s.setSingleRange(r); 90 }()); '; 91 $this->session->executeScript($js); 92 } 93 94 /** 95 * Matches the provided value against the current field value. 96 * 97 * @param string $expectedvalue 98 * @return bool The provided value matches the field value? 99 */ 100 public function matches($expectedvalue) { 101 // A text editor may silently wrap the content in p tags (or not). Neither is an error. 102 return $this->text_matches($expectedvalue) || $this->text_matches('<p>' . $expectedvalue . '</p>'); 103 } 104 } 105
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |