Skip to content

Commit

Permalink
MDL-70167 behat: Boolean attributes should either exist or not
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Nov 23, 2020
1 parent c8d33eb commit 7d70165
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
36 changes: 18 additions & 18 deletions lib/editor/atto/tests/behat/disablecontrol.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ Feature: Atto with enable/disable function.
@javascript
Scenario: Check disable Atto editor.
When I set the field "mycontrol" to "Disable"
Then the "disabled" attribute of "button.atto_collapse_button" "css_element" should contain "disabled"
And the "disabled" attribute of "button.atto_title_button" "css_element" should contain "disabled"
And the "disabled" attribute of "button.atto_bold_button" "css_element" should contain "disabled"
And the "disabled" attribute of "button.atto_italic_button" "css_element" should contain "disabled"
And the "disabled" attribute of "button.atto_unorderedlist_button_insertUnorderedList" "css_element" should contain "disabled"
And the "disabled" attribute of "button.atto_orderedlist_button_insertOrderedList" "css_element" should contain "disabled"
And the "disabled" attribute of "button.atto_link_button" "css_element" should contain "disabled"
And the "disabled" attribute of "button.atto_link_button_unlink" "css_element" should contain "disabled"
And the "disabled" attribute of "button.atto_image_button" "css_element" should contain "disabled"
Then the "disabled" attribute of "button.atto_collapse_button" "css_element" should be set
And the "disabled" attribute of "button.atto_title_button" "css_element" should be set
And the "disabled" attribute of "button.atto_bold_button" "css_element" should be set
And the "disabled" attribute of "button.atto_italic_button" "css_element" should be set
And the "disabled" attribute of "button.atto_unorderedlist_button_insertUnorderedList" "css_element" should be set
And the "disabled" attribute of "button.atto_orderedlist_button_insertOrderedList" "css_element" should be set
And the "disabled" attribute of "button.atto_link_button" "css_element" should be set
And the "disabled" attribute of "button.atto_link_button_unlink" "css_element" should be set
And the "disabled" attribute of "button.atto_image_button" "css_element" should be set
And the "contenteditable" attribute of "div#id_myeditoreditable" "css_element" should contain "false"

@javascript
Scenario: Check enable Atto editor.
When I set the field "mycontrol" to "Enable"
Then "button.atto_collapse_button[disabled]" "css_element" should not exist
And "button.atto_title_button[disabled]" "css_element" should not exist
And "button.atto_bold_button[disabled]" "css_element" should not exist
And "button.atto_italic_button[disabled]" "css_element" should not exist
And "button.atto_unorderedlist_button_insertUnorderedList[disabled]" "css_element" should not exist
And "button.atto_orderedlist_button_insertOrderedList[disabled]" "css_element" should not exist
And "button.atto_link_button[disabled]" "css_element" should not exist
And "button.atto_link_button_unlink[disabled]" "css_element" should not exist
And "button.atto_image_button[disabled]" "css_element" should not exist
Then the "disabled" attribute of "button.atto_collapse_button" "css_element" should not be set
And the "disabled" attribute of "button.atto_title_button" "css_element" should not be set
And the "disabled" attribute of "button.atto_bold_button" "css_element" should not be set
And the "disabled" attribute of "button.atto_italic_button" "css_element" should not be set
And the "disabled" attribute of "button.atto_unorderedlist_button_insertUnorderedList" "css_element" should not be set
And the "disabled" attribute of "button.atto_orderedlist_button_insertOrderedList" "css_element" should not be set
And the "disabled" attribute of "button.atto_link_button" "css_element" should not be set
And the "disabled" attribute of "button.atto_link_button_unlink" "css_element" should not be set
And the "disabled" attribute of "button.atto_image_button" "css_element" should not be set
And the "contenteditable" attribute of "div#id_myeditoreditable" "css_element" should contain "true"
4 changes: 2 additions & 2 deletions lib/editor/textarea/tests/behat/disablecontrol.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Feature: Text area with enable/disable function.
@javascript
Scenario: Check disable Text area editor.
When I set the field "mycontrol" to "Disable"
Then the "readonly" attribute of "textarea#id_myeditor" "css_element" should contain "readonly"
Then the "readonly" attribute of "textarea#id_myeditor" "css_element" should be set

@javascript
Scenario: Check enable Text area editor.
When I set the field "mycontrol" to "Enable"
Then "textarea#id_myeditor[readonly]" "css_element" should not exist
Then the "readonly" attribute of "textarea#id_myeditor" "css_element" should not be set
33 changes: 33 additions & 0 deletions lib/tests/behat/behat_general.php
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,39 @@ public function i_change_window_size_to($windowviewport, $windowsize) {
$this->resize_window($windowsize, $windowviewport === 'viewport');
}

/**
* Checks whether there the specified attribute is set or not.
*
* @Then the :attribute attribute of :element :selectortype should be set
* @Then the :attribute attribute of :element :selectortype should :not be set
*
* @throws ExpectationException
* @param string $attribute Name of attribute
* @param string $element The locator of the specified selector
* @param string $selectortype The selector type
* @param string $not
*/
public function the_attribute_of_should_be_set($attribute, $element, $selectortype, $not = null) {
// Get the container node (exception if it doesn't exist).
$containernode = $this->get_selected_node($selectortype, $element);
$hasattribute = $containernode->hasAttribute($attribute);

if ($not && $hasattribute) {
$value = $containernode->getAttribute($attribute);
// Should not be set but is.
throw new ExpectationException(
"The attribute \"{$attribute}\" should not be set but has a value of '{$value}'",
$this->getSession()
);
} else if (!$not && !$hasattribute) {
// Should be set but is not.
throw new ExpectationException(
"The attribute \"{$attribute}\" should be set but is not",
$this->getSession()
);
}
}

/**
* Checks whether there is an attribute on the given element that contains the specified text.
*
Expand Down

0 comments on commit 7d70165

Please sign in to comment.