diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php index c57bc94..ebd4850 100644 --- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php @@ -148,6 +148,32 @@ protected function assertFieldById($id, $value = NULL) { } /** + * Asserts that a field exists with the given name or ID. + * + * @param string $field + * Name or ID of field to assert. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->fieldExists() instead. + */ + protected function assertField($field) { + $this->assertSession()->fieldExists($field); + } + + /** + * Asserts that a field exists with the given name or ID does NOT exist. + * + * @param string $field + * Name or ID of field to assert. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->fieldNotExists() instead. + */ + protected function assertNoField($field) { + $this->assertSession()->fieldNotExists($field); + } + + /** * Passes if the raw text IS found on the loaded page, fail otherwise. * * Raw text refers to the raw HTML that the page generated. @@ -182,8 +208,13 @@ protected function assertNoRaw($raw) { * * @param string $expected_title * The string the page title should be. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->titleEquals() instead. */ protected function assertTitle($expected_title) { + // Cast MarkupInterface to string. + $expected_title = (string) $expected_title; return $this->assertSession()->titleEquals($expected_title); } @@ -343,6 +374,19 @@ protected function assertNoEscaped($raw) { } /** + * Asserts whether an expected cache tag was present in the last response. + * + * @param string $expected_cache_tag + * The expected cache tag. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->responseHeaderContains() instead. + */ + protected function assertCacheTag($expected_cache_tag) { + $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $expected_cache_tag); + } + + /** * Returns WebAssert object. * * @param string $name @@ -353,4 +397,31 @@ protected function assertNoEscaped($raw) { */ abstract public function assertSession($name = NULL); + /** + * Builds an XPath query. + * + * Builds an XPath query by replacing placeholders in the query by the value + * of the arguments. + * + * XPath 1.0 (the version supported by libxml2, the underlying XML library + * used by PHP) doesn't support any form of quotation. This function + * simplifies the building of XPath expression. + * + * @param string $xpath + * An XPath query, possibly with placeholders in the form ':name'. + * @param array $args + * An array of arguments with keys in the form ':name' matching the + * placeholders in the query. The values may be either strings or numeric + * values. + * + * @return string + * An XPath query with arguments replaced. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->buildXPathQuery() instead. + */ + public function buildXPathQuery($xpath, array $args = array()) { + return $this->assertSession()->buildXPathQuery($xpath, $args); + } + } diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index f22cbc8..bef34ab 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -48,6 +48,7 @@ use RandomGeneratorTrait; use SessionTestTrait; use NodeCreationTrait { + getNodeByTitle as drupalGetNodeByTitle; createNode as drupalCreateNode; } use ContentTypeCreationTrait { diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index c0744a8..6156dda 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -80,6 +80,24 @@ public function buttonExists($button, TraversableElement $container = NULL) { } /** + * Checks that the specific button does NOT exist on the current page. + * + * @param string $button + * One of id|name|label|value for the button. + * @param \Behat\Mink\Element\TraversableElement $container + * (optional) The document to check against. Defaults to the current page. + * + * @throws \Behat\Mink\Exception\ExpectationException + * When the button exists. + */ + public function buttonNotExists($button, TraversableElement $container = NULL) { + $container = $container ?: $this->session->getPage(); + $node = $container->findButton($button); + + $this->assert(NULL === $node, sprintf('A button "%s" appears on this page, but it should not.', $button)); + } + + /** * Checks that specific select field exists on the current page. * * @param string $select @@ -375,4 +393,33 @@ public function assert($condition, $message) { throw new ExpectationException($message, $this->session->getDriver()); } + /** + * Checks that a given form field element is disabled. + * + * @param string $field + * One of id|name|label|value for the field. + * @param \Behat\Mink\Element\TraversableElement $container + * (optional) The document to check against. Defaults to the current page. + * + * @return \Behat\Mink\Element\NodeElement + * The matching element. + * + * @throws \Behat\Mink\Exception\ElementNotFoundException + * @throws \Behat\Mink\Exception\ExpectationException + */ + public function fieldDisabled($field, TraversableElement $container = NULL) { + $container = $container ?: $this->session->getPage(); + $node = $container->findField($field); + + if ($node === NULL) { + throw new ElementNotFoundException($this->session->getDriver(), 'field', 'id|name|label|value', $field); + } + + if (!$node->hasAttribute('disabled')) { + throw new ExpectationException("Field $field is disabled", $this->session->getDriver()); + } + + return $node; + } + }