Skip to content

Commit

Permalink
MDL-70167 behat: Rewrite attribute check steps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrewnicols committed Nov 23, 2020
1 parent 6e7d202 commit 2f842d0
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions lib/tests/behat/behat_general.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,7 @@ protected function check_element_order(
* @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);
}

/**
Expand All @@ -939,13 +933,7 @@ public function the_element_should_be_disabled($element, $selectortype) {
* @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);
}

/**
Expand All @@ -957,12 +945,7 @@ public function the_element_should_be_enabled($element, $selectortype) {
* @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);
}

/**
Expand All @@ -974,12 +957,7 @@ public function the_element_should_be_readonly($element, $selectortype) {
* @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);
}

/**
Expand Down

0 comments on commit 2f842d0

Please sign in to comment.