From 051e9663f0fb55874e26f08cb29cababa0e80b5f Mon Sep 17 00:00:00 2001 From: David Monllao Date: Fri, 14 Jun 2013 15:11:36 +0800 Subject: [PATCH] MDL-39634 behat: Removing unused arguments Also adding deprecated methods. --- backup/util/ui/tests/behat/behat_backup.php | 2 +- lib/behat/behat_field_manager.php | 57 ++++++++++++++++++--- lib/behat/form_field/behat_form_field.php | 2 +- lib/behat/form_field/behat_form_radio.php | 2 +- lib/tests/behat/behat_forms.php | 4 +- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/backup/util/ui/tests/behat/behat_backup.php b/backup/util/ui/tests/behat/behat_backup.php index 4d8f4b1155b..b0d99986caf 100644 --- a/backup/util/ui/tests/behat/behat_backup.php +++ b/backup/util/ui/tests/behat/behat_backup.php @@ -322,7 +322,7 @@ class behat_backup extends behat_base { try { $fieldnode = $this->find_field($locator); - $field = behat_field_manager::get_field($fieldnode, $locator, $this->getSession()); + $field = behat_field_manager::get_form_field($fieldnode, $this->getSession()); $field->set_value($value); } catch (ElementNotFoundException $e) { diff --git a/lib/behat/behat_field_manager.php b/lib/behat/behat_field_manager.php index a72e7536054..b83b18e2b90 100644 --- a/lib/behat/behat_field_manager.php +++ b/lib/behat/behat_field_manager.php @@ -48,15 +48,14 @@ class behat_field_manager { * the value of form elements. * * @param NodeElement $fieldnode - * @param string $locator The locator to help give more info about the possible problem. * @param Session $session The behat browser session * @return behat_form_field */ - public static function get_field(NodeElement $fieldnode, $locator, Session $session) { + public static function get_form_field(NodeElement $fieldnode, Session $session) { // Get the field type if is part of a moodleform. if (self::is_moodleform_field($fieldnode)) { - $type = self::get_node_type($fieldnode, $locator, $session); + $type = self::get_field_node_type($fieldnode, $session); } // If is not a moodleforms field use the base field type. @@ -100,7 +99,7 @@ class behat_field_manager { * * Note that there are fields inside moodleforms that are not * moodleform element; this method can not detect this, this will - * be managed by get_node_type, after failing to find the form + * be managed by get_field_node_type, after failing to find the form * element element type. * * @param NodeElement $fieldnode @@ -117,15 +116,14 @@ class behat_field_manager { /** * Recursive method to find the field type. * - * Depending on the field the felement class node is a level or in another. We + * Depending on the field the felement class node is in a level or in another. We * look recursively for a parent node with a 'felement' class to find the field type. * * @param NodeElement $fieldnode The current node. - * @param string $locator Just to send an exception that makes sense for the user. * @param Session $session The behat browser session * @return mixed A NodeElement if we continue looking for the element type and String or false when we are done. */ - protected static function get_node_type(NodeElement $fieldnode, $locator, Session $session) { + protected static function get_field_node_type(NodeElement $fieldnode, Session $session) { // We look for a parent node with 'felement' class. if ($class = $fieldnode->getParent()->getAttribute('class')) { @@ -141,7 +139,50 @@ class behat_field_manager { } } - return self::get_node_type($fieldnode->getParent(), $locator, $session); + return self::get_field_node_type($fieldnode->getParent(), $session); + } + + /** + * Gets an instance of the form field. + * + * Not all the fields are part of a moodle form, in this + * cases it fallsback to the generic form field. Also note + * that this generic field type is using a generic setValue() + * method from the Behat API, which is not always good to set + * the value of form elements. + * + * @deprecated since Moodle 2.6 MDL-39634 - please do not use this function any more. + * @todo MDL-XXXXX This will be deleted in Moodle 2.8 + * @see behat_field_manager::get_form_field() + * @param NodeElement $fieldnode + * @param Session $session The behat browser session + * @return behat_form_field + */ + public static function get_field(NodeElement $fieldnode, $locator, Session $session) { + debugging('Function behat_field_manager::get_field() is deprecated, ' . + 'please use function behat_field_manager::get_form_field() instead', DEBUG_DEVELOPER); + + return self::get_form_field($fieldnode, $session); + } + + /** + * Recursive method to find the field type. + * + * Depending on the field the felement class node is in a level or in another. We + * look recursively for a parent node with a 'felement' class to find the field type. + * + * @deprecated since Moodle 2.6 MDL-39634 - please do not use this function any more. + * @todo MDL-XXXXX This will be deleted in Moodle 2.8 + * @see behat_field_manager::get_field_node_type() + * @param NodeElement $fieldnode The current node. + * @param Session $session The behat browser session + * @return mixed A NodeElement if we continue looking for the element type and String or false when we are done. + */ + protected static function get_node_type(NodeElement $fieldnode, $locator, Session $session) { + debugging('Function behat_field_manager::get_node_type() is deprecated, ' . + 'please use function behat_field_manager::get_field_node_type() instead', DEBUG_DEVELOPER); + + return self::get_field_node_type($fieldnode, $session); } } diff --git a/lib/behat/form_field/behat_form_field.php b/lib/behat/form_field/behat_form_field.php index dc28e0416f7..d5d43e1b218 100644 --- a/lib/behat/form_field/behat_form_field.php +++ b/lib/behat/form_field/behat_form_field.php @@ -98,7 +98,7 @@ class behat_form_field { /** * Guesses the element type we are dealing with in case is not a text-based element. * - * This class is the generic field type, behat_field_manager::get_field() + * This class is the generic field type, behat_field_manager::get_form_field() * should be able to find the appropiate class for the field type, but * in cases like moodle form group elements we can not find the type of * the field through the DOM so we also need to take care of the diff --git a/lib/behat/form_field/behat_form_radio.php b/lib/behat/form_field/behat_form_radio.php index 445751ed7a6..1ca020ebec3 100644 --- a/lib/behat/form_field/behat_form_radio.php +++ b/lib/behat/form_field/behat_form_radio.php @@ -36,7 +36,7 @@ require_once(__DIR__ . '/behat_form_checkbox.php'); * This form field type can be added to forms as any other * moodle form element, but it does not make sense without * a group of radio inputs, so is hard to find it alone and - * detect it by behat_form_manager::get_field(), where is useful + * detect it by behat_field_manager::get_form_field(), where is useful * is when the default behat_form_field class is being used, it * finds a input[type=radio] and it delegates set_value() and * get_value() to behat_form_radio. diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 6abb0d707d5..bbd8ffb0794 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -81,7 +81,7 @@ class behat_forms extends behat_base { $fieldnode = $this->find_field($locator); // Gets the field type from a parent node. - $field = behat_field_manager::get_field($fieldnode, $locator, $this->getSession()); + $field = behat_field_manager::get_form_field($fieldnode, $this->getSession()); // Delegates to the field class. $field->set_value($value); @@ -256,7 +256,7 @@ class behat_forms extends behat_base { $fieldnode = $this->find_field($locator); // Get the field. - $field = behat_field_manager::get_field($fieldnode, $locator, $this->getSession()); + $field = behat_field_manager::get_form_field($fieldnode, $this->getSession()); $fieldvalue = $field->get_value(); // Checks if the provided value matches the current field value.