diff --git a/core/modules/action/tests/src/Functional/ConfigurationTest.php b/core/modules/action/tests/src/Functional/ConfigurationTest.php index 647e1a7..22e5991 100644 --- a/core/modules/action/tests/src/Functional/ConfigurationTest.php +++ b/core/modules/action/tests/src/Functional/ConfigurationTest.php @@ -83,7 +83,7 @@ function testActionConfiguration() { $this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action."); $action = Action::load($aid); - $this->assertNull($action, 'Make sure the action is gone after being deleted.'); + $this->assertFalse($action, 'Make sure the action is gone after being deleted.'); } } diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php index d340d2e..8f24139 100644 --- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php @@ -78,10 +78,19 @@ protected function assertText($text) { * Plain text to look for. * * @deprecated Scheduled for removal in Drupal 9.0.0. - * Use $this->assertSession()->responseNotContains() instead. + * Use $this->assertSession()->pageTextNotContains() or + * $this->assertSession()->responseNotContains() instead. */ protected function assertNoText($text) { - $this->assertSession()->responseNotContains($text); + $content_type = $this->getSession()->getResponseHeader('Content-type'); + // In case of a Non-HTML response (example: XML) check the original + // response. + if (strpos($content_type, 'html') === FALSE) { + $this->assertSession()->responseNotContains($text); + } + else { + $this->assertSession()->pageTextNotContains($text); + } } /** @@ -192,4 +201,33 @@ protected function assertOption($id, $option) { return $this->assertSession()->optionExists($id, $option); } + /** + * Asserts that a select option does NOT exist in the current page. + * + * @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()->optionNotExists() instead. + */ + protected function assertNoOption($id, $option) { + return $this->assertSession()->optionNotExists($id, $option); + } + + /** + * Passes if the internal browser's URL matches the given path. + * + * @param \Drupal\Core\Url|string $path + * The expected system path or URL. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->addressEquals() instead. + */ + protected function assertUrl($path) { + $path = "/$path"; + $this->assertSession()->addressEquals($path); + } + } diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 8c72d80..867db61 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -1766,6 +1766,16 @@ protected function drupalGetHeader($name) { } /** + * Get the current URL from the browser. + * + * @return string + * The current URL. + */ + protected function getUrl() { + return $this->getSession()->getCurrentUrl(); + } + + /** * {@inheritdoc} */ public static function assertEquals($expected, $actual, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE) { diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index 7b15d2d..da3a86d 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -103,6 +103,35 @@ public function optionExists($select, $option, TraversableElement $container = N } /** + * Checks that an option in a select field does NOT exist on the current page. + * + * @param string $select + * One of id|name|label|value for the select field. + * @param string $option + * The option value that shoulkd not exist. + * @param \Behat\Mink\Element\TraversableElement $container + * (optional) The document to check against. Defaults to the current page. + * + * @throws \Behat\Mink\Exception\ElementNotFoundException + * When the select element doesn't exist. + */ + public function optionNotExists($select, $option, TraversableElement $container = NULL) { + $container = $container ?: $this->session->getPage(); + $select_field = $container->find('named', array( + 'select', + $this->session->getSelectorsHandler()->xpathLiteral($select), + )); + + if ($select_field === NULL) { + throw new ElementNotFoundException($this->session, 'select', 'id|name|label|value', $select); + } + + $option_field = $select_field->find('named', array('option', $option)); + + $this->assert($option_field === NULL, sprintf('An option "%s" exists in select "%s", but it should not.', $option, $select)); + } + + /** * Pass if the page title is the given string. * * @param string $expected_title