diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php index 6ca9f85..81da04a 100644 --- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php @@ -129,6 +129,27 @@ protected function assertFieldByName($name, $value = NULL) { } /** + * Asserts that a field exists with the given name and value. + * + * @param string $name + * Name of field to assert. + * @param string $value + * (optional) Value of the field to assert. You may pass in NULL (default) + * to skip checking the actual value, while still checking that the field + * exists. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->fieldNotExists() or + * $this->assertSession()->fieldValueNotEquals() instead. + */ + protected function assertNoFieldByName($name, $value = NULL) { + $this->assertSession()->fieldNotExists($name); + if ($value !== NULL) { + $this->assertSession()->fieldValueNotEquals($name, (string) $value); + } + } + + /** * Asserts that a field exists with the given ID and value. * * @param string $id @@ -344,6 +365,47 @@ protected function assertNoOption($id, $option) { } /** + * Asserts that a select option in the current page is checked. + * + * @param string $id + * ID of select field to assert. + * @param string $option + * Option to assert. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->optionSelected() instead. + */ + protected function assertOptionSelected($id, $option) { + $this->assertSession()->optionSelected($id, $option); + } + + /** + * Asserts that a checkbox field in the current page is checked. + * + * @param string $id + * ID of field to assert. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->checkboxChecked() instead. + */ + protected function assertFieldChecked($id) { + $this->assertSession()->checkboxChecked($id); + } + + /** + * Asserts that a checkbox field in the current page is not checked. + * + * @param string $id + * ID of field to assert. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->checkboxNotChecked() instead. + */ + protected function assertNoFieldChecked($id) { + $this->assertSession()->checkboxNotChecked($id); + } + + /** * Passes if the raw text IS found escaped on the loaded page, fail otherwise. * * Raw text refers to the raw HTML that the page generated. diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index 6156dda..d4cffd8 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -191,6 +191,29 @@ public function optionNotExists($select, $option, TraversableElement $container } /** + * Checks that a specific option in a select field is selected. + * + * @param string $select + * One of id|name|label|value for the select field. + * @param string $option + * The option value. + * @param \Behat\Mink\Element\TraversableElement $container + * (optional) The document to check against. Defaults to the current page. + * + * @return \Behat\Mink\Element\NodeElement + * The matching option element + * + * @throws \Behat\Mink\Exception\ElementNotFoundException + * When the element doesn't exist. + */ + public function optionSelected($select, $option, TraversableElement $container = NULL) { + $option_field = $this->optionExists($select, $option, $container); + $this->assert(!empty($option_field->getAttribute('selected')), sprintf('Option "%s" in select "%s" is not selected as expected.', $option, $select)); + + return $option_field; + } + + /** * Pass if the page title is the given string. * * @param string $expected_title