From 6882d7399ba57014f8b433c771db45990b88d5c8 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 23 Nov 2020 09:00:13 +0800 Subject: [PATCH] MDL-70167 behat: Rewrite attribute check steps This commit updates the following steps to use the `the_attribute_of_should_be_set` step under the hood: - the [element] [type] should be disabled - the [element] [type] should be enabled - the [element] [type] should be readonly - the [element] [type] should not be readonly This reduces unnecssary code duplication. --- lib/tests/behat/behat_general.php | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 852e952a31e..ec1e3a42984 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -945,13 +945,7 @@ EOF; * @param string $selectortype The type of element where we are looking in. */ public function the_element_should_be_disabled($element, $selectortype) { - - // Transforming from steps definitions selector/locator format to Mink format and getting the NodeElement. - $node = $this->get_selected_node($selectortype, $element); - - if (!$node->hasAttribute('disabled')) { - throw new ExpectationException('The element "' . $element . '" is not disabled', $this->getSession()); - } + $this->the_attribute_of_should_be_set("disabled", $element, $selectortype, false); } /** @@ -963,13 +957,7 @@ EOF; * @param string $selectortype The type of where we look */ public function the_element_should_be_enabled($element, $selectortype) { - - // Transforming from steps definitions selector/locator format to mink format and getting the NodeElement. - $node = $this->get_selected_node($selectortype, $element); - - if ($node->hasAttribute('disabled')) { - throw new ExpectationException('The element "' . $element . '" is not enabled', $this->getSession()); - } + $this->the_attribute_of_should_be_set("disabled", $element, $selectortype, true); } /** @@ -981,12 +969,7 @@ EOF; * @param string $selectortype The type of element where we are looking in. */ public function the_element_should_be_readonly($element, $selectortype) { - // Transforming from steps definitions selector/locator format to Mink format and getting the NodeElement. - $node = $this->get_selected_node($selectortype, $element); - - if (!$node->hasAttribute('readonly')) { - throw new ExpectationException('The element "' . $element . '" is not readonly', $this->getSession()); - } + $this->the_attribute_of_should_be_set("readonly", $element, $selectortype, false); } /** @@ -998,12 +981,7 @@ EOF; * @param string $selectortype The type of element where we are looking in. */ public function the_element_should_not_be_readonly($element, $selectortype) { - // Transforming from steps definitions selector/locator format to Mink format and getting the NodeElement. - $node = $this->get_selected_node($selectortype, $element); - - if ($node->hasAttribute('readonly')) { - throw new ExpectationException('The element "' . $element . '" is readonly', $this->getSession()); - } + $this->the_attribute_of_should_be_set("readonly", $element, $selectortype, true); } /** -- 2.43.0