From 786ced9925ac0bc3841b96e81fcee44b62710179 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 13 Mar 2014 17:04:19 +0800 Subject: [PATCH] MDL-43883 Behat: Fix deprecation and move custom matches to the editor field only. --- lib/behat/behat_base.php | 6 +++++- lib/behat/behat_field_manager.php | 2 +- lib/behat/form_field/behat_form_editor.php | 10 ++++++++++ lib/behat/form_field/behat_form_text.php | 3 +-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index ec71838d427..8c60cecd4fe 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -583,7 +583,11 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext { * @return void */ protected function ensure_editors_are_loaded() { - debugging('Function behat_base::ensure_editors_are_loaded() is deprecated. It is no longer required.'); + global $CFG; + + if (empty($CFG->behat_usedeprecated)) { + debugging('Function behat_base::ensure_editors_are_loaded() is deprecated. It is no longer required.'); + } return; } diff --git a/lib/behat/behat_field_manager.php b/lib/behat/behat_field_manager.php index 7454da8890c..6bbc39ea5f4 100644 --- a/lib/behat/behat_field_manager.php +++ b/lib/behat/behat_field_manager.php @@ -118,7 +118,7 @@ class behat_field_manager { if ($tagname == 'textarea') { // If there is an iframe with $id + _ifr there a TinyMCE editor loaded. - $xpath = '//iframe[@id="' . $fieldnode->getAttribute('id') . '_ifr"]'; + $xpath = '//div[@id="' . $fieldnode->getAttribute('id') . 'editable"]'; if ($session->getPage()->find('xpath', $xpath)) { return 'editor'; } diff --git a/lib/behat/form_field/behat_form_editor.php b/lib/behat/form_field/behat_form_editor.php index 441f4edf417..e666b02beb0 100644 --- a/lib/behat/form_field/behat_form_editor.php +++ b/lib/behat/form_field/behat_form_editor.php @@ -65,5 +65,15 @@ editor.set("value", "' . $value . '"); } } + /** + * Matches the provided value against the current field value. + * + * @param string $expectedvalue + * @return bool The provided value matches the field value? + */ + public function matches($expectedvalue) { + // A text editor may silently wrap the content in p tags (or not). Neither is an error. + return $this->text_matches($expectedvalue) || $this->text_matches('

' . $expectedvalue . '

'); + } } diff --git a/lib/behat/form_field/behat_form_text.php b/lib/behat/form_field/behat_form_text.php index 14291e17357..dffdf86ffa2 100644 --- a/lib/behat/form_field/behat_form_text.php +++ b/lib/behat/form_field/behat_form_text.php @@ -63,8 +63,7 @@ class behat_form_text extends behat_form_field { * @return bool The provided value matches the field value? */ public function matches($expectedvalue) { - // A text editor may silently wrap the content in p tags (or not). Neither is an error. - return $this->text_matches($expectedvalue) || $this->text_matches('

' . $expectedvalue . '

'); + return $this->text_matches($expectedvalue); } }