diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php deleted file mode 100644 index 25bf18878b9acef0f021d233046757cbc0623956..0000000000000000000000000000000000000000 --- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ /dev/null @@ -1,993 +0,0 @@ -<?php - -namespace Drupal\FunctionalTests; - -use Behat\Mink\Element\NodeElement; -use Behat\Mink\Exception\ExpectationException; -use Behat\Mink\Selector\Xpath\Escaper; -use Drupal\Component\Render\FormattableMarkup; -use Drupal\Component\Utility\Xss; -use Drupal\KernelTests\AssertLegacyTrait as BaseAssertLegacyTrait; - -/** - * Provides convenience methods for assertions in browser tests. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * the methods from \Drupal\Tests\WebAssert instead. - * - * @see https://www.drupal.org/node/3129738 - */ -trait AssertLegacyTrait { - - use BaseAssertLegacyTrait; - - /** - * Asserts that the element with the given CSS selector is present. - * - * @param string $css_selector - * The CSS selector identifying the element to check. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->elementExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertElementPresent($css_selector) { - @trigger_error('AssertLegacyTrait::assertElementPresent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->elementExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->elementExists('css', $css_selector); - } - - /** - * Asserts that the element with the given CSS selector is not present. - * - * @param string $css_selector - * The CSS selector identifying the element to check. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->elementNotExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertElementNotPresent($css_selector) { - @trigger_error('AssertLegacyTrait::assertElementNotPresent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->elementNotExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->elementNotExists('css', $css_selector); - } - - /** - * Passes if the page (with HTML stripped) contains the text. - * - * Note that stripping HTML tags also removes their attributes, such as - * the values of text fields. - * - * @param string $text - * Plain text to look for. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * - $this->assertSession()->responseContains() for non-HTML responses, - * like XML or Json. - * - $this->assertSession()->pageTextContains() for HTML responses. Unlike - * the deprecated assertText(), the passed text should be HTML decoded, - * exactly as a human sees it in the browser. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertText($text) { - @trigger_error('AssertLegacyTrait::assertText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() or $this->assertSession()->pageTextContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - if (func_num_args() > 1) { - @trigger_error('Calling AssertLegacyTrait::assertText() with more than one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() or $this->assertSession()->pageTextContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - } - // Cast MarkupInterface to string. - $text = (string) $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()->responseContains($text); - } - else { - // Trying to simulate what the user sees, given that it removes all text - // inside the head tags, removes inline JavaScript, fix all HTML entities, - // removes dangerous protocols and filtering out all HTML tags, as they are - // not visible in a normal browser. - $raw_content = preg_replace('@<head>(.+?)</head>@si', '', $this->getSession()->getPage()->getContent()); - $page_text = Xss::filter($raw_content, []); - $this->assertStringContainsString($text, $page_text, "\"$text\" found"); - } - } - - /** - * Passes if the page (with HTML stripped) does not contains the text. - * - * Note that stripping HTML tags also removes their attributes, such as - * the values of text fields. - * - * @param string $text - * Plain text to look for. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * - $this->assertSession()->responseNotContains() for non-HTML responses, - * like XML or Json. - * - $this->assertSession()->pageTextNotContains() for HTML responses. - * Unlike the deprecated assertNoText(), the passed text should be HTML - * decoded, exactly as a human sees it in the browser. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoText($text) { - @trigger_error('AssertLegacyTrait::assertNoText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - if (func_num_args() > 1) { - @trigger_error('Calling AssertLegacyTrait::assertNoText() with more than one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - } - - // Cast MarkupInterface to string. - $text = (string) $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 { - // Trying to simulate what the user sees, given that it removes all text - // inside the head tags, removes inline JavaScript, fix all HTML entities, - // removes dangerous protocols and filtering out all HTML tags, as they are - // not visible in a normal browser. - $raw_content = preg_replace('@<head>(.+?)</head>@si', '', $this->getSession()->getPage()->getContent()); - $page_text = Xss::filter($raw_content, []); - $this->assertStringNotContainsString($text, $page_text, "\"$text\" not found"); - } - } - - /** - * Helper for assertText and assertNoText. - * - * @param string $text - * Plain text to look for. - * @param bool $not_exists - * (optional) TRUE if this text should not exist, FALSE if it should. - * Defaults to TRUE. - * - * @return bool - * TRUE on pass, FALSE on fail. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->pageTextContains() or - * $this->assertSession()->pageTextNotContains() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertTextHelper($text, $not_exists = TRUE) { - @trigger_error('AssertLegacyTrait::assertTextHelper() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->pageTextContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $args = ['@text' => $text]; - $message = $not_exists ? new FormattableMarkup('"@text" not found', $args) : new FormattableMarkup('"@text" found', $args); - - $raw_content = $this->getSession()->getPage()->getContent(); - // Trying to simulate what the user sees, given that it removes all text - // inside the head tags, removes inline JavaScript, fix all HTML entities, - // removes dangerous protocols and filtering out all HTML tags, as they are - // not visible in a normal browser. - $raw_content = preg_replace('@<head>(.+?)</head>@si', '', $raw_content); - $page_text = Xss::filter($raw_content, []); - - $actual = $not_exists == (strpos($page_text, (string) $text) === FALSE); - $this->assertTrue($actual, $message); - - return $actual; - } - - /** - * Passes if the text is found ONLY ONCE on the text version of the page. - * - * The text version is the equivalent of what a user would see when viewing - * through a web browser. In other words the HTML has been filtered out of - * the contents. - * - * @param string|\Drupal\Component\Render\MarkupInterface $text - * Plain text to look for. - * @param string $message - * (optional) A message to display with the assertion. Do not translate - * messages with t(). If left blank, a default message will be displayed. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->getSession()->pageTextContainsOnce() or - * $this->getSession()->pageTextMatchesCount() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertUniqueText($text, $message = NULL) { - @trigger_error('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - // Cast MarkupInterface objects to string. - $text = (string) $text; - - $message = $message ?: "'$text' found only once on the page"; - $page_text = $this->getSession()->getPage()->getText(); - $nr_found = substr_count($page_text, $text); - $this->assertSame(1, $nr_found, $message); - } - - /** - * Passes if the text is found MORE THAN ONCE on the text version of the page. - * - * The text version is the equivalent of what a user would see when viewing - * through a web browser. In other words the HTML has been filtered out of - * the contents. - * - * @param string|\Drupal\Component\Render\MarkupInterface $text - * Plain text to look for. - * @param string $message - * (optional) A message to display with the assertion. Do not translate - * messages with t(). If left blank, a default message will be displayed. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, - * use $this->getSession()->pageTextMatchesCount() if you know the - * cardinality in advance, or $this->getSession()->getPage()->getText() - * and substr_count(). - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoUniqueText($text, $message = '') { - @trigger_error('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - // Cast MarkupInterface objects to string. - $text = (string) $text; - - $message = $message ?: "'$text' found more than once on the page"; - $page_text = $this->getSession()->getPage()->getText(); - $nr_found = substr_count($page_text, $text); - $this->assertGreaterThan(1, $nr_found, $message); - } - - /** - * Asserts the page responds with the specified response code. - * - * @param int $code - * Response code. For example 200 is a successful page request. For a list - * of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->statusCodeEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertResponse($code) { - @trigger_error('AssertLegacyTrait::assertResponse() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->statusCodeEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->statusCodeEquals($code); - } - - /** - * 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 in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->fieldExists() or - * $this->assertSession()->buttonExists() or - * $this->assertSession()->fieldValueEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertFieldByName($name, $value = NULL) { - @trigger_error('AssertLegacyTrait::assertFieldByName() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $xpath = $this->assertSession()->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $name]); - $this->assertFieldByXPath($xpath, $value); - } - - /** - * Asserts that a field does not exist with the given name and value. - * - * @param string $name - * Name of field to assert. - * @param string $value - * (optional) Value for the field, to assert that the field's value on the - * page does not match it. You may pass in NULL to skip checking the - * value, while still checking that the field does not exist. However, the - * default value ('') asserts that the field value is not an empty string. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->fieldNotExists() or - * $this->assertSession()->buttonNotExists() or - * $this->assertSession()->fieldValueNotEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoFieldByName($name, $value = '') { - @trigger_error('AssertLegacyTrait::assertNoFieldByName() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $xpath = $this->assertSession()->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $name]); - $this->assertNoFieldByXPath($xpath, $value); - } - - /** - * Asserts that a field exists with the given ID and value. - * - * @param string $id - * ID of field to assert. - * @param string|\Drupal\Component\Render\MarkupInterface $value - * (optional) Value for the field to assert. You may pass in NULL to skip - * checking the value, while still checking that the field exists. - * However, the default value ('') asserts that the field value is an empty - * string. - * - * @throws \Behat\Mink\Exception\ElementNotFoundException - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->fieldExists() or - * $this->assertSession()->buttonExists() or - * $this->assertSession()->fieldValueEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertFieldById($id, $value = '') { - @trigger_error('AssertLegacyTrait::assertFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $xpath = $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $id]); - $this->assertFieldByXPath($xpath, $value); - } - - /** - * Asserts that a field exists with the given name or ID. - * - * @param string $field - * Name or ID of field to assert. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->fieldExists() or - * $this->assertSession()->buttonExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertField($field) { - @trigger_error('AssertLegacyTrait::assertField() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $xpath = $this->assertSession()->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $field]) . - '|' . - $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $field]); - $this->assertFieldByXPath($xpath); - } - - /** - * Asserts that a field does NOT exist with the given name or ID. - * - * @param string $field - * Name or ID of field to assert. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->fieldNotExists() or - * $this->assertSession()->buttonNotExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoField($field) { - @trigger_error('AssertLegacyTrait::assertNoField() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $xpath = $this->assertSession()->buildXPathQuery('//textarea[@name=:value]|//input[@name=:value]|//select[@name=:value]', [':value' => $field]) . - '|' . - $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $field]); - $this->assertNoFieldByXPath($xpath); - } - - /** - * Passes if the raw text IS found on the loaded page, fail otherwise. - * - * Raw text refers to the raw HTML that the page generated. - * - * @param string $raw - * Raw (HTML) string to look for. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->responseContains() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertRaw($raw) { - @trigger_error('AssertLegacyTrait::assertRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - if (func_num_args() > 1) { - @trigger_error('Calling AssertLegacyTrait::assertRaw() with more that one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - } - $this->assertSession()->responseContains($raw); - } - - /** - * Passes if the raw text IS not found on the loaded page, fail otherwise. - * - * Raw text refers to the raw HTML that the page generated. - * - * @param string $raw - * Raw (HTML) string to look for. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->responseNotContains() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoRaw($raw) { - @trigger_error('AssertLegacyTrait::assertNoRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - if (func_num_args() > 1) { - @trigger_error('Calling AssertLegacyTrait::assertNoRaw() with more that one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - } - $this->assertSession()->responseNotContains($raw); - } - - /** - * Pass if the page title is the given string. - * - * @param string $expected_title - * The string the page title should be. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->titleEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertTitle($expected_title) { - @trigger_error('AssertLegacyTrait::assertTitle() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->titleEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - // Cast MarkupInterface to string. - $expected_title = (string) $expected_title; - return $this->assertSession()->titleEquals($expected_title); - } - - /** - * Passes if a link with the specified label is found. - * - * An optional link index may be passed. - * - * @param string|\Drupal\Component\Render\MarkupInterface $label - * Text between the anchor tags. - * @param int $index - * Link position counting from zero. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->linkExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertLink($label, $index = 0) { - @trigger_error('AssertLegacyTrait::assertLink() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - return $this->assertSession()->linkExists($label, $index); - } - - /** - * Passes if a link with the specified label is not found. - * - * @param string|\Drupal\Component\Render\MarkupInterface $label - * Text between the anchor tags. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->linkNotExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoLink($label) { - @trigger_error('AssertLegacyTrait::assertNoLink() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkNotExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - return $this->assertSession()->linkNotExists($label); - } - - /** - * Passes if a link containing a given href (part) is found. - * - * @param string $href - * The full or partial value of the 'href' attribute of the anchor tag. - * @param int $index - * Link position counting from zero. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->linkByHrefExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertLinkByHref($href, $index = 0) { - @trigger_error('AssertLegacyTrait::assertLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->linkByHrefExists($href, $index); - } - - /** - * Passes if a link containing a given href (part) is not found. - * - * @param string $href - * The full or partial value of the 'href' attribute of the anchor tag. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->linkByHrefNotExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoLinkByHref($href) { - @trigger_error('AssertLegacyTrait::assertNoLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefNotExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->linkByHrefNotExists($href); - } - - /** - * Asserts that a field does not exist with the given ID and value. - * - * @param string $id - * ID of field to assert. - * @param string $value - * (optional) Value for the field, to assert that the field's value on the - * page doesn't match it. You may pass in NULL to skip checking the value, - * while still checking that the field doesn't exist. However, the default - * value ('') asserts that the field value is not an empty string. - * - * @throws \Behat\Mink\Exception\ExpectationException - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->fieldNotExists() or - * $this->assertSession()->buttonNotExists() or - * $this->assertSession()->fieldValueNotEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoFieldById($id, $value = '') { - @trigger_error('AssertLegacyTrait::assertNoFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $xpath = $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $id]); - $this->assertNoFieldByXPath($xpath, $value); - } - - /** - * Passes if the internal browser's URL matches the given path. - * - * @param \Drupal\Core\Url|string $path - * The expected system path or URL. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->addressEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertUrl($path) { - @trigger_error('AssertLegacyTrait::assertUrl() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->addressEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - if (func_num_args() > 1) { - @trigger_error('Calling AssertLegacyTrait::assertUrl() with more than one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->addressEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - } - $this->assertSession()->addressEquals($path); - } - - /** - * Asserts that a select option in the current page exists. - * - * @param string $id - * ID of select field to assert. - * @param string $option - * Option to assert. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->optionExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertOption($id, $option) { - @trigger_error('AssertLegacyTrait::assertOption() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - return $this->assertSession()->optionExists($id, $option); - } - - /** - * Asserts that a select option with the visible text exists. - * - * @param string $id - * The ID of the select field to assert. - * @param string $text - * The text for the option tag to assert. - * - * @deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->optionExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertOptionByText($id, $text) { - @trigger_error('AssertLegacyTrait::assertOptionByText() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - return $this->assertSession()->optionExists($id, $text); - } - - /** - * 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 in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->optionNotExists() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoOption($id, $option) { - @trigger_error('AssertLegacyTrait::assertNoOption() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionNotExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - return $this->assertSession()->optionNotExists($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. - * @param string $message - * (optional) A message to display with the assertion. Do not translate - * messages with t(). If left blank, a default message will be displayed. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->optionExists() instead and check the - * "selected" attribute yourself. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertOptionSelected($id, $option, $message = NULL) { - @trigger_error('AssertLegacyTrait::assertOptionSelected() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead and check the "selected" attribute. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $option_field = $this->assertSession()->optionExists($id, $option); - $message = $message ?: "Option $option for field $id is selected."; - $this->assertTrue($option_field->hasAttribute('selected'), $message); - } - - /** - * Asserts that a checkbox field in the current page is checked. - * - * @param string $id - * ID of field to assert. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->checkboxChecked() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertFieldChecked($id) { - @trigger_error('AssertLegacyTrait::assertFieldChecked() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->checkboxChecked() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $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 in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->checkboxNotChecked() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoFieldChecked($id) { - @trigger_error('AssertLegacyTrait::assertNoFieldChecked() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->checkboxNotChecked() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->checkboxNotChecked($id); - } - - /** - * Asserts that a field exists in the current page by the given XPath. - * - * @param string $xpath - * XPath used to find the field. - * @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. - * @param string $message - * (optional) A message to display with the assertion. Do not translate - * messages with t(). - * - * @deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use - * $this->xpath() instead and check the values directly in the test. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertFieldByXPath($xpath, $value = NULL, $message = '') { - @trigger_error('AssertLegacyTrait::assertFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and check the values directly in the test. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $fields = $this->xpath($xpath); - - $this->assertFieldsByValue($fields, $value, $message); - } - - /** - * Asserts that a field does not exist or its value does not match, by XPath. - * - * @param string $xpath - * XPath used to find the field. - * @param string $value - * (optional) Value of the field, to assert that the field's value on the - * page does not match it. - * @param string $message - * (optional) A message to display with the assertion. Do not translate - * messages with t(). - * - * @throws \Behat\Mink\Exception\ExpectationException - * - * @deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use - * $this->xpath() instead and assert that the result is empty. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '') { - @trigger_error('AssertLegacyTrait::assertNoFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and assert that the result is empty. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $fields = $this->xpath($xpath); - - if (!empty($fields)) { - if (isset($value)) { - $found = FALSE; - try { - $this->assertFieldsByValue($fields, $value); - $found = TRUE; - } - catch (\Exception $e) { - } - - if ($found) { - throw new ExpectationException(sprintf('The field resulting from %s was found with the provided value %s.', $xpath, $value), $this->getSession()->getDriver()); - } - } - else { - throw new ExpectationException(sprintf('The field resulting from %s was found.', $xpath), $this->getSession()->getDriver()); - } - } - } - - /** - * Asserts that a field exists in the current page with a given Xpath result. - * - * @param \Behat\Mink\Element\NodeElement[] $fields - * Xml elements. - * @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. - * @param string $message - * (optional) A message to display with the assertion. Do not translate - * messages with t(). - * - * @deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use - * iteration over the fields yourself instead and directly check the values - * in the test. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertFieldsByValue($fields, $value = NULL, $message = '') { - @trigger_error('AssertLegacyTrait::assertFieldsByValue() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use iteration over the fields yourself instead and directly check the values in the test. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - // If value specified then check array for match. - $found = TRUE; - if (isset($value)) { - $found = FALSE; - if ($fields) { - foreach ($fields as $field) { - if ($field->getAttribute('type') == 'checkbox') { - if (is_bool($value)) { - $found = $field->isChecked() == $value; - } - else { - $found = TRUE; - } - } - elseif ($field->getAttribute('value') == $value) { - // Input element with correct value. - $found = TRUE; - } - elseif ($field->find('xpath', '//option[@value = ' . (new Escaper())->escapeLiteral($value) . ' and @selected = "selected"]')) { - // Select element with an option. - $found = TRUE; - } - elseif ($field->getTagName() === 'textarea' && $field->getValue() == $value) { - // Text area with correct text. Use getValue() here because - // getText() would remove any newlines in the value. - $found = TRUE; - } - elseif ($field->getTagName() !== 'input' && $field->getText() == $value) { - $found = TRUE; - } - } - } - } - $this->assertTrue($fields && $found, $message); - } - - /** - * 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. - * - * @param string $raw - * Raw (HTML) string to look for. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->assertEscaped() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertEscaped($raw) { - @trigger_error('AssertLegacyTrait::assertEscaped() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->assertEscaped() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->assertEscaped($raw); - } - - /** - * Passes if the raw text is not found escaped on the loaded page. - * - * Raw text refers to the raw HTML that the page generated. - * - * @param string $raw - * Raw (HTML) string to look for. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->assertNoEscaped() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoEscaped($raw) { - @trigger_error('AssertLegacyTrait::assertNoEscaped() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->assertNoEscaped() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->assertNoEscaped($raw); - } - - /** - * Triggers a pass if the Perl regex pattern is found in the raw content. - * - * @param string $pattern - * Perl regex to look for including the regex delimiters. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->responseMatches() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertPattern($pattern) { - @trigger_error('AssertLegacyTrait::assertPattern() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseMatches() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->responseMatches($pattern); - } - - /** - * Triggers a pass if the Perl regex pattern is not found in the raw content. - * - * @param string $pattern - * Perl regex to look for including the regex delimiters. - * - * @deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->responseNotMatches() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoPattern($pattern) { - @trigger_error('AssertLegacyTrait::assertNoPattern() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotMatches() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->responseNotMatches($pattern); - } - - /** - * Asserts whether an expected cache tag was present in the last response. - * - * @param string $expected_cache_tag - * The expected cache tag. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->responseHeaderContains() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertCacheTag($expected_cache_tag) { - @trigger_error('AssertLegacyTrait::assertCacheTag() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $expected_cache_tag); - } - - /** - * Asserts whether an expected cache tag was absent in the last response. - * - * @param string $cache_tag - * The cache tag to check. - * - * @deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->responseHeaderNotContains() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNoCacheTag($cache_tag) { - @trigger_error('AssertLegacyTrait::assertNoCacheTag() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderNotContains() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', $cache_tag); - } - - /** - * Checks that current response header equals value. - * - * @param string $name - * Name of header to assert. - * @param string $value - * Value of the header to assert - * - * @deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->responseHeaderEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertHeader($name, $value) { - @trigger_error('AssertLegacyTrait::assertHeader() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSession()->responseHeaderEquals($name, $value); - } - - /** - * Returns WebAssert object. - * - * @param string $name - * (optional) Name of the session. Defaults to the active session. - * - * @return \Drupal\Tests\WebAssert - * A new web-assert option for asserting the presence of elements with. - */ - 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 in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->assertSession()->buildXPathQuery() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function buildXPathQuery($xpath, array $args = []) { - @trigger_error('AssertLegacyTrait::buildXPathQuery() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->buildXPathQuery() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - return $this->assertSession()->buildXPathQuery($xpath, $args); - } - - /** - * Helper: Constructs an XPath for the given set of attributes and value. - * - * @param string $attribute - * Field attributes. - * @param string $value - * Value of field. - * - * @return string - * XPath for specified values. - * - * @deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use - * $this->getSession()->getPage()->findField() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function constructFieldXpath($attribute, $value) { - @trigger_error('AssertLegacyTrait::constructFieldXpath() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->findField() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $xpath = '//textarea[@' . $attribute . '=:value]|//input[@' . $attribute . '=:value]|//select[@' . $attribute . '=:value]'; - return $this->assertSession()->buildXPathQuery($xpath, [':value' => $value]); - } - - /** - * Gets the current raw content. - * - * @deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use - * $this->getSession()->getPage()->getContent() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function getRawContent() { - @trigger_error('AssertLegacyTrait::getRawContent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->getContent() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - return $this->getSession()->getPage()->getContent(); - } - - /** - * Get all option elements, including nested options, in a select. - * - * @param \Behat\Mink\Element\NodeElement $element - * The element for which to get the options. - * - * @return \Behat\Mink\Element\NodeElement[] - * Option elements in select. - * - * @deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use - * $element->findAll('xpath', 'option') instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function getAllOptions(NodeElement $element) { - @trigger_error('AssertLegacyTrait::getAllOptions() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $element->findAll(\'xpath\', \'option\') instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - return $element->findAll('xpath', '//option'); - } - -} diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 96bc4d5443d0d3155d49019df8eaac4c9e0bbb08..9085e3e288c8c11f5b48361c7a98ca50d3c4977a 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -257,41 +257,6 @@ public function testInvalidLinkNotExistsExact() { $this->assertSession()->linkNotExistsExact('foo|bar|baz'); } - /** - * Tests legacy assertResponse(). - * - * @group legacy - */ - public function testAssertResponse() { - $this->expectDeprecation('AssertLegacyTrait::assertResponse() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->statusCodeEquals() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-encoded'); - $this->assertResponse(200); - } - - /** - * Tests legacy assertTitle(). - * - * @group legacy - */ - public function testAssertTitle() { - $this->expectDeprecation('AssertLegacyTrait::assertTitle() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->titleEquals() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-encoded'); - $this->assertTitle("Page with encoded HTML | Drupal"); - } - - /** - * Tests legacy assertHeader(). - * - * @group legacy - */ - public function testAssertHeader() { - $this->expectDeprecation('AssertLegacyTrait::assertHeader() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderEquals() instead. See https://www.drupal.org/node/3129738'); - $account = $this->drupalCreateUser(); - $this->drupalLogin($account); - $this->drupalGet('test-page'); - $this->assertHeader('X-Drupal-Cache-Tags', 'http_response rendered'); - } - /** * Tests legacy text asserts. */ @@ -303,75 +268,6 @@ public function testTextAsserts() { $this->assertSession()->responseContains($sanitized); } - /** - * Tests legacy assertPattern(). - * - * @group legacy - */ - public function testAssertPattern() { - $this->expectDeprecation('AssertLegacyTrait::assertPattern() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseMatches() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-escaped-characters'); - $this->assertPattern('/div class.*escaped/'); - } - - /** - * Tests deprecated assertText. - * - * @group legacy - */ - public function testAssertText() { - $this->expectDeprecation('AssertLegacyTrait::assertText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() or $this->assertSession()->pageTextContains() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('Calling AssertLegacyTrait::assertText() with more than one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() or $this->assertSession()->pageTextContains() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-encoded'); - $dangerous = 'Bad html <script>alert(123);</script>'; - $this->assertText(Html::escape($dangerous), 'Sanitized text should be present.'); - } - - /** - * Tests deprecated assertNoText. - * - * @group legacy - */ - public function testAssertNoText() { - $this->expectDeprecation('AssertLegacyTrait::assertNoText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('Calling AssertLegacyTrait::assertNoText() with more than one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-encoded'); - $dangerous = 'Bad html <script>alert(123);</script>'; - $this->assertNoText($dangerous, 'Dangerous text should not be present.'); - } - - /** - * Tests legacy getRawContent(). - * - * @group legacy - */ - public function testGetRawContent() { - $this->expectDeprecation('AssertLegacyTrait::getRawContent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->getContent() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-encoded'); - $this->assertSame($this->getSession()->getPage()->getContent(), $this->getRawContent()); - } - - /** - * Tests legacy buildXPathQuery(). - * - * @group legacy - */ - public function testBuildXPathQuery() { - $this->expectDeprecation('AssertLegacyTrait::buildXPathQuery() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->buildXPathQuery() instead. See https://www.drupal.org/node/3129738'); - $this->buildXPathQuery('\\html'); - } - - /** - * Tests legacy assertFieldsByValue(). - * - * @group legacy - */ - public function testAssertFieldsByValue() { - $this->expectDeprecation('AssertLegacyTrait::assertFieldsByValue() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use iteration over the fields yourself instead and directly check the values in the test. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-field-xpath'); - $this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL); - } - /** * Tests legacy field asserts which use xpath directly. */ @@ -403,36 +299,6 @@ public function testXpathAsserts() { } } - /** - * Tests legacy field asserts using textfields. - * - * @group legacy - */ - public function testAssertField() { - $this->expectDeprecation('AssertLegacyTrait::assertField() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertNoField() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-field-xpath'); - $this->assertField('name'); - $this->assertNoField('invalid_name_and_id'); - } - - /** - * Tests legacy field asserts by id and by Xpath. - * - * @group legacy - */ - public function testAssertFieldById() { - $this->expectDeprecation('AssertLegacyTrait::assertFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertNoFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and check the values directly in the test. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertNoFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and assert that the result is empty. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-field-xpath'); - $this->assertFieldById('edit-save', NULL); - $this->assertNoFieldById('invalid', NULL); - $this->assertFieldByXPath("//input[@id = 'edit-name']", 'Test name'); - $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value'); - } - /** * Tests field asserts using textfields. */ @@ -544,64 +410,6 @@ public function testFieldAssertsForTextfields() { $this->assertSession()->fieldValueEquals('edit-test-textarea-with-newline', "Test text with\nnewline"); } - /** - * Tests legacy field asserts for options field type. - * - * @group legacy - */ - public function testFieldAssertsForOptions() { - $this->expectDeprecation('AssertLegacyTrait::assertOptionByText() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertOption() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertNoOption() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionNotExists() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-field-xpath'); - - // Option field type. - $this->assertOptionByText('options', 'one'); - try { - $this->assertOptionByText('options', 'four'); - $this->fail('The select option "four" was found.'); - } - catch (ExpectationException $e) { - // Expected exception; just continue testing. - } - - $this->assertOption('options', 1); - try { - $this->assertOption('options', 4); - $this->fail('The select option "4" was found.'); - } - catch (ExpectationException $e) { - // Expected exception; just continue testing. - } - - $this->assertNoOption('options', 'non-existing'); - try { - $this->assertNoOption('options', 'one'); - $this->fail('The select option "one" was not found.'); - } - catch (ExpectationException $e) { - // Expected exception; just continue testing. - } - - $this->assertTrue($this->assertSession()->optionExists('options', 2)->isSelected()); - try { - $this->assertTrue($this->assertSession()->optionExists('options', 4)->isSelected()); - $this->fail('The select option "4" was selected.'); - } - catch (ExpectationException $e) { - // Expected exception; just continue testing. - } - - try { - $this->assertTrue($this->assertSession()->optionExists('options', 1)->isSelected()); - $this->fail('The select option "1" was selected.'); - } - catch (ExpectationFailedException $e) { - // Expected exception; just continue testing. - } - - } - /** * Tests legacy field asserts for button field type. */ @@ -637,19 +445,6 @@ public function testFieldAssertsForButton() { } } - /** - * Tests legacy assertFieldChecked() and assertNoFieldChecked(). - * - * @group legacy - */ - public function testLegacyFieldAssertsForCheckbox() { - $this->expectDeprecation('AssertLegacyTrait::assertFieldChecked() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->checkboxChecked() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertNoFieldChecked() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->checkboxNotChecked() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-field-xpath'); - $this->assertFieldChecked('edit-checkbox-enabled'); - $this->assertNoFieldChecked('edit-checkbox-disabled'); - } - /** * Tests legacy field asserts for checkbox field type. */ @@ -875,19 +670,6 @@ public function testEscapingAssertions() { $assert->assertNoEscaped("<script>alert('Marked safe');alert(\"Marked safe\");</script>"); } - /** - * Tests deprecation of legacy assertEscaped() and assertNoEscaped(). - * - * @group legacy - */ - public function testLegacyEscapingAssertions(): void { - $this->expectDeprecation('AssertLegacyTrait::assertNoEscaped() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->assertNoEscaped() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertEscaped() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->assertEscaped() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-escaped-characters'); - $this->assertNoEscaped('<div class="escaped">'); - $this->assertEscaped('Escaped: <"\'&>'); - } - /** * Tests deprecation of drupalPostForm(). * @@ -933,19 +715,6 @@ public function testDeprecationHeaders() { $this->assertCount(1, $test_deprecation_messages); } - /** - * Tests legacy assertFieldByName() and assertNoFieldByName(). - * - * @group legacy - */ - public function testLegacyFieldAssertsByName() { - $this->expectDeprecation('AssertLegacyTrait::assertFieldByName() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('AssertLegacyTrait::assertNoFieldByName() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('test-field-xpath'); - $this->assertFieldByName('checkbox_enabled', TRUE); - $this->assertNoFieldByName('checkbox_enabled', FALSE); - } - /** * Tests legacy drupalGetHeader(). * diff --git a/core/tests/Drupal/FunctionalTests/Core/Test/AssertLegacyTraitDeprecatedTest.php b/core/tests/Drupal/FunctionalTests/Core/Test/AssertLegacyTraitDeprecatedTest.php deleted file mode 100644 index 5341a9ac25af32e7245092cd63ee6c3d4791b542..0000000000000000000000000000000000000000 --- a/core/tests/Drupal/FunctionalTests/Core/Test/AssertLegacyTraitDeprecatedTest.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace Drupal\FunctionalTests\Core\Test; - -use Drupal\Tests\BrowserTestBase; - -/** - * Tests deprecated AssertLegacyTrait functionality. - * - * @group browsertestbase - * @group legacy - */ -class AssertLegacyTraitDeprecatedTest extends BrowserTestBase { - - /** - * Modules to enable. - * - * @var array - */ - protected static $modules = ['form_test']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * Tests getAllOptions(). - */ - public function testGetAllOptions() { - $this->expectDeprecation('AssertLegacyTrait::getAllOptions() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $element->findAll(\'xpath\', \'option\') instead. See https://www.drupal.org/node/3129738'); - $this->drupalGet('/form-test/select'); - $this->assertCount(6, $this->getAllOptions($this->cssSelect('select[name="opt_groups"]')[0])); - } - -} diff --git a/core/tests/Drupal/KernelTests/AssertLegacyTrait.php b/core/tests/Drupal/KernelTests/AssertLegacyTrait.php deleted file mode 100644 index 1f7698e916323d243448f320f1809bb65e7d0f4c..0000000000000000000000000000000000000000 --- a/core/tests/Drupal/KernelTests/AssertLegacyTrait.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php - -namespace Drupal\KernelTests; - -/** - * Translates Simpletest assertion methods to PHPUnit. - * - * Protected methods are custom. Public static methods override methods of - * \PHPUnit\Framework\Assert. - * - * @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use - * PHPUnit's native assert methods instead. - * - * @see https://www.drupal.org/node/3129738 - */ -trait AssertLegacyTrait { - - /** - * @see \Drupal\simpletest\TestBase::assert() - * - * @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use - * $this->assertTrue() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assert($actual, $message = '') { - @trigger_error('AssertLegacyTrait::assert() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertTrue() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - parent::assertTrue((bool) $actual, $message); - } - - /** - * @see \Drupal\simpletest\TestBase::assertEqual() - * - * @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use - * $this->assertEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertEqual($actual, $expected, $message = '') { - @trigger_error('AssertLegacyTrait::assertEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertEquals($expected, $actual, (string) $message); - } - - /** - * @see \Drupal\simpletest\TestBase::assertNotEqual() - * - * @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use - * $this->assertNotEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNotEqual($actual, $expected, $message = '') { - @trigger_error('AssertLegacyTrait::assertNotEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertNotEquals($expected, $actual, (string) $message); - } - - /** - * @see \Drupal\simpletest\TestBase::assertIdentical() - * - * @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use - * $this->assertSame() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertIdentical($actual, $expected, $message = '') { - @trigger_error('AssertLegacyTrait::assertIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertSame() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertSame($expected, $actual, (string) $message); - } - - /** - * @see \Drupal\simpletest\TestBase::assertNotIdentical() - * - * @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use - * $this->assertNotSame() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertNotIdentical($actual, $expected, $message = '') { - @trigger_error('AssertLegacyTrait::assertNotIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotSame() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertNotSame($expected, $actual, (string) $message); - } - - /** - * @see \Drupal\simpletest\TestBase::assertIdenticalObject() - * - * @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use - * $this->assertEquals() instead. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function assertIdenticalObject($actual, $expected, $message = '') { - @trigger_error('AssertLegacyTrait::assertIdenticalObject() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - // Note: ::assertSame checks whether its the same object. ::assertEquals - // though compares - - $this->assertEquals($expected, $actual, (string) $message); - } - - /** - * @see \Drupal\simpletest\TestBase::pass() - * - * @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. PHPUnit - * interrupts a test as soon as a test assertion fails, so there is usually - * no need to call this method. If a test's logic relies on this method, - * refactor the test. - * - * @see https://www.drupal.org/node/3129738 - */ - protected function pass($message) { - @trigger_error('AssertLegacyTrait::pass() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. PHPUnit interrupts a test as soon as a test assertion fails, so there is usually no need to call this method. If a test\'s logic relies on this method, refactor the test. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED); - $this->assertTrue(TRUE, $message); - } - - /** - * @see \Drupal\simpletest\TestBase::verbose() - * - * @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use - * dump() instead. - * - * @see https://www.drupal.org/node/3197514 - */ - protected function verbose($message) { - @trigger_error('AssertLegacyTrait::verbose() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use dump() instead. See https://www.drupal.org/node/3197514', E_USER_DEPRECATED); - if (in_array('--debug', $_SERVER['argv'], TRUE)) { - // Write directly to STDOUT to not produce unexpected test output. - // The STDOUT stream does not obey output buffering. - fwrite(STDOUT, $message . "\n"); - } - } - -} diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index 148c6d3d941877723c50d0bf0cb4597e4538ccc4..9dbcc1db76277144a7b931372bba25bbf04ddf94 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -82,7 +82,6 @@ */ abstract class KernelTestBase extends TestCase implements ServiceProviderInterface { - use AssertLegacyTrait; use AssertContentTrait; use RandomGeneratorTrait; use ConfigTestTrait; diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index 942e9f537790202d70e805ea278d15a201d80872..ed45b1fe0f85482fc63577788e884d1dd217c529 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -339,76 +339,6 @@ public function testProfileModules() { ); } - /** - * Tests the deprecation of AssertLegacyTrait::assert. - * - * @group legacy - */ - public function testAssert() { - $this->expectDeprecation('AssertLegacyTrait::assert() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertTrue() instead. See https://www.drupal.org/node/3129738'); - $this->assert(TRUE); - } - - /** - * Tests the deprecation of AssertLegacyTrait::assertIdenticalObject. - * - * @group legacy - */ - public function testAssertIdenticalObject() { - $this->expectDeprecation('AssertLegacyTrait::assertIdenticalObject() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738'); - $this->assertIdenticalObject((object) ['foo' => 'bar'], (object) ['foo' => 'bar']); - } - - /** - * Tests the deprecation of AssertLegacyTrait::assertEqual. - * - * @group legacy - */ - public function testAssertEqual() { - $this->expectDeprecation('AssertLegacyTrait::assertEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738'); - $this->assertEqual('0', 0); - } - - /** - * Tests the deprecation of AssertLegacyTrait::assertNotEqual. - * - * @group legacy - */ - public function testAssertNotEqual() { - $this->expectDeprecation('AssertLegacyTrait::assertNotEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotEquals() instead. See https://www.drupal.org/node/3129738'); - $this->assertNotEqual('foo', 'bar'); - } - - /** - * Tests the deprecation of AssertLegacyTrait::assertIdentical. - * - * @group legacy - */ - public function testAssertIdentical() { - $this->expectDeprecation('AssertLegacyTrait::assertIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertSame() instead. See https://www.drupal.org/node/3129738'); - $this->assertIdentical('foo', 'foo'); - } - - /** - * Tests the deprecation of AssertLegacyTrait::assertNotIdentical. - * - * @group legacy - */ - public function testAssertNotIdentical() { - $this->expectDeprecation('AssertLegacyTrait::assertNotIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotSame() instead. See https://www.drupal.org/node/3129738'); - $this->assertNotIdentical('foo', 'bar'); - } - - /** - * Tests the deprecation of AssertLegacyTrait::verbose(). - * - * @group legacy - */ - public function testVerbose() { - $this->expectDeprecation('AssertLegacyTrait::verbose() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use dump() instead. See https://www.drupal.org/node/3197514'); - $this->verbose('The show must go on'); - } - /** * Tests the deprecation of ::installSchema with the tables key_value(_expire). * diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index aad64ee4542c17af546baefaa24e4e090862d2a0..704149fdd24c33e98c93c89946629d34ae1a8a1f 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -13,7 +13,6 @@ use Drupal\Core\Test\TestSetupTrait; use Drupal\Core\Url; use Drupal\Core\Utility\Error; -use Drupal\FunctionalTests\AssertLegacyTrait; use Drupal\Tests\block\Traits\BlockCreationTrait; use Drupal\Tests\node\Traits\ContentTypeCreationTrait; use Drupal\Tests\node\Traits\NodeCreationTrait; @@ -54,7 +53,6 @@ abstract class BrowserTestBase extends TestCase { use BlockCreationTrait { placeBlock as drupalPlaceBlock; } - use AssertLegacyTrait; use RandomGeneratorTrait; use NodeCreationTrait { getNodeByTitle as drupalGetNodeByTitle; diff --git a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php deleted file mode 100644 index 0ae737516eab7a164302a63570e802a56bd7958d..0000000000000000000000000000000000000000 --- a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php +++ /dev/null @@ -1,331 +0,0 @@ -<?php - -namespace Drupal\Tests\Core\Assert; - -use Behat\Mink\Element\DocumentElement; -use Behat\Mink\Element\NodeElement; -use Behat\Mink\Session; -use Drupal\Component\Render\MarkupInterface; -use Drupal\FunctionalTests\AssertLegacyTrait; -use Drupal\Tests\UnitTestCase; -use Drupal\Tests\WebAssert; -use PHPUnit\Framework\ExpectationFailedException; -use Prophecy\Argument; - -/** - * @coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait - * @group Assert - * @group legacy - */ -class AssertLegacyTraitTest extends UnitTestCase { - - use AssertLegacyTrait; - - /** - * The mocked Mink session object used for testing. - * - * @var \Behat\Mink\Session|\Prophecy\Prophecy\ObjectProphecy - */ - protected $session; - - /** - * The mocked page element used for testing. - * - * @var Behat\Mink\Element\DocumentElement|\Prophecy\Prophecy\ObjectProphecy - */ - protected $page; - - /** - * The mocked web assert class. - * - * @var \Drupal\Tests\WebAssert|\Prophecy\Prophecy\ObjectProphecy - */ - protected $webAssert; - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - parent::setUp(); - - $this->page = $this->prophesize(DocumentElement::class); - $this->session = $this->prophesize(Session::class); - $this->session->getPage()->willReturn($this->page->reveal()); - $this->webAssert = $this->prophesize(WebAssert::class); - } - - /** - * @covers ::assertTextHelper - */ - public function testAssertTextHelper() { - $this->expectDeprecation('AssertLegacyTrait::assertTextHelper() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->pageTextContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738'); - $this->page->getContent()->willReturn('foo bar bar'); - $this->assertTextHelper('foo', FALSE); - } - - /** - * @covers ::assertRaw - */ - public function testAssertRaw() { - $this->expectDeprecation('AssertLegacyTrait::assertRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('Calling AssertLegacyTrait::assertRaw() with more that one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() instead. See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $this->assertRaw('foo', '\'foo\' should be present.'); - } - - /** - * @covers ::assertNoRaw - */ - public function testAssertNoRaw() { - $this->expectDeprecation('AssertLegacyTrait::assertNoRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('Calling AssertLegacyTrait::assertNoRaw() with more that one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() instead. See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $this->assertNoRaw('qux', '\'qux\' should not be present.'); - } - - /** - * @covers ::assertUniqueText - */ - public function testAssertUniqueText() { - $this->expectDeprecation('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $this->assertUniqueText('foo'); - } - - /** - * @covers ::assertUniqueText - */ - public function testAssertUniqueTextFail() { - $this->expectDeprecation('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $this->expectException(ExpectationFailedException::class); - $this->assertUniqueText('bar'); - } - - /** - * @covers ::assertUniqueText - */ - public function testAssertUniqueTextUnknown() { - $this->expectDeprecation('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $this->expectException(ExpectationFailedException::class); - $this->assertUniqueText('alice'); - } - - /** - * @covers ::assertUniqueText - */ - public function testAssertUniqueTextMarkup() { - $this->expectDeprecation('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $markupObject = $this->prophesize(MarkupInterface::class); - $markupObject->__toString()->willReturn('foo'); - $this->assertUniqueText($markupObject->reveal()); - } - - /** - * @covers ::assertNoUniqueText - */ - public function testAssertNoUniqueText() { - $this->expectDeprecation('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $this->assertNoUniqueText('bar'); - } - - /** - * @covers ::assertNoUniqueText - */ - public function testAssertNoUniqueTextFail() { - $this->expectDeprecation('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $this->expectException(ExpectationFailedException::class); - $this->assertNoUniqueText('foo'); - } - - /** - * @covers ::assertNoUniqueText - */ - public function testAssertNoUniqueTextUnknown() { - $this->expectDeprecation('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $this->expectException(ExpectationFailedException::class); - $this->assertNoUniqueText('alice'); - } - - /** - * @covers ::assertNoUniqueText - */ - public function testAssertNoUniqueTextMarkup() { - $this->expectDeprecation('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738'); - $this->page->getText()->willReturn('foo bar bar'); - $markupObject = $this->prophesize(MarkupInterface::class); - $markupObject->__toString()->willReturn('bar'); - $this->assertNoUniqueText($markupObject->reveal()); - } - - /** - * @covers ::assertOptionSelected - */ - public function testAssertOptionSelected() { - $this->expectDeprecation('AssertLegacyTrait::assertOptionSelected() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead and check the "selected" attribute. See https://www.drupal.org/node/3129738'); - $option_field = $this->prophesize(NodeElement::class); - $option_field->hasAttribute('selected')->willReturn(TRUE); - - $this->webAssert - ->optionExists('my_select', 'two') - ->willReturn($option_field->reveal()); - - $this->assertOptionSelected('my_select', 'two'); - } - - /** - * @covers ::assertOptionSelected - */ - public function testAssertOptionSelectedFail() { - $this->expectDeprecation('AssertLegacyTrait::assertOptionSelected() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead and check the "selected" attribute. See https://www.drupal.org/node/3129738'); - $option_field = $this->prophesize(NodeElement::class); - $option_field->hasAttribute('selected')->willReturn(FALSE); - - $this->webAssert - ->optionExists('my_select', 'two') - ->willReturn($option_field->reveal()); - - $this->expectException(ExpectationFailedException::class); - $this->assertOptionSelected('my_select', 'two'); - } - - /** - * @covers ::assertNoPattern - */ - public function testAssertNoPattern() { - $this->expectDeprecation('AssertLegacyTrait::assertNoPattern() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotMatches() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->responseNotMatches('/.*foo$/') - ->shouldBeCalled(); - - $this->assertNoPattern('/.*foo$/'); - } - - /** - * @covers ::assertCacheTag - */ - public function testAssertCacheTag() { - $this->expectDeprecation('AssertLegacyTrait::assertCacheTag() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderContains() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->responseHeaderContains('X-Drupal-Cache-Tags', 'some-cache-tag') - ->shouldBeCalled(); - - $this->assertCacheTag('some-cache-tag'); - } - - /** - * @covers ::assertNoCacheTag - */ - public function testAssertNoCacheTag() { - $this->expectDeprecation('AssertLegacyTrait::assertNoCacheTag() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderNotContains() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->responseHeaderNotContains('X-Drupal-Cache-Tags', 'some-cache-tag') - ->shouldBeCalled(); - - $this->assertNoCacheTag('some-cache-tag'); - } - - /** - * @covers ::assertUrl - */ - public function testAssertUrl() { - $this->expectDeprecation('AssertLegacyTrait::assertUrl() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->addressEquals() instead. See https://www.drupal.org/node/3129738'); - $this->expectDeprecation('Calling AssertLegacyTrait::assertUrl() with more than one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->addressEquals() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->addressEquals('bingo') - ->shouldBeCalled(); - - $this->assertUrl('bingo', 'Redundant message.'); - } - - /** - * @covers ::assertElementPresent - */ - public function testAssertElementPresent() { - $this->expectDeprecation('AssertLegacyTrait::assertElementPresent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->elementExists() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->elementExists('css', '.pager') - ->shouldBeCalled(); - - $this->assertElementPresent('.pager'); - } - - /** - * @covers ::assertElementNotPresent - */ - public function testAssertElementNotPresent() { - $this->expectDeprecation('AssertLegacyTrait::assertElementNotPresent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->elementNotExists() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->elementNotExists('css', '.pager') - ->shouldBeCalled(); - - $this->assertElementNotPresent('.pager'); - } - - /** - * @covers ::pass - */ - public function testPass() { - $this->expectDeprecation('AssertLegacyTrait::pass() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. PHPUnit interrupts a test as soon as a test assertion fails, so there is usually no need to call this method. If a test\'s logic relies on this method, refactor the test. See https://www.drupal.org/node/3129738'); - $this->pass('Passed.'); - } - - /** - * @covers ::assertLinkByHref - */ - public function testAssertLinkByHref() { - $this->expectDeprecation('AssertLegacyTrait::assertLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefExists() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->linkByHrefExists('boo', 0) - ->shouldBeCalled(); - - $this->assertLinkByHref('boo', 0); - } - - /** - * @covers ::assertNoLinkByHref - */ - public function testAssertNoLinkByHref() { - $this->expectDeprecation('AssertLegacyTrait::assertNoLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefNotExists() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->linkByHrefNotExists('boo') - ->shouldBeCalled(); - - $this->assertNoLinkByHref('boo'); - } - - /** - * @covers ::constructFieldXpath - */ - public function testConstructFieldXpath() { - $this->expectDeprecation('AssertLegacyTrait::constructFieldXpath() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->findField() instead. See https://www.drupal.org/node/3129738'); - $this->webAssert - ->buildXPathQuery(Argument::any(), Argument::any()) - ->willReturn('qux'); - - $this->assertSame('qux', $this->constructFieldXpath('foo', ['bar'])); - } - - /** - * Returns a mocked behat session object. - * - * @return \Behat\Mink\Session - * The mocked session. - */ - protected function getSession() { - return $this->session->reveal(); - } - - /** - * {@inheritdoc} - */ - public function assertSession($name = NULL) { - return $this->webAssert->reveal(); - } - -}