diff --git a/core/modules/color/test/src/Functional/ColorConfigSchemaTest.php b/core/modules/color/tests/src/Functional/ColorConfigSchemaTest.php similarity index 100% rename from core/modules/color/test/src/Functional/ColorConfigSchemaTest.php rename to core/modules/color/tests/src/Functional/ColorConfigSchemaTest.php diff --git a/core/modules/color/test/src/Functional/ColorSafePreviewTest.php b/core/modules/color/tests/src/Functional/ColorSafePreviewTest.php similarity index 98% rename from core/modules/color/test/src/Functional/ColorSafePreviewTest.php rename to core/modules/color/tests/src/Functional/ColorSafePreviewTest.php index 18b0534..e80202f 100644 --- a/core/modules/color/test/src/Functional/ColorSafePreviewTest.php +++ b/core/modules/color/tests/src/Functional/ColorSafePreviewTest.php @@ -8,7 +8,7 @@ /** * Tests sanitizing color preview loaded from theme. * - * @group Theme + * @group color */ class ColorSafePreviewTest extends BrowserTestBase { diff --git a/core/modules/color/test/src/Functional/ColorTest.php b/core/modules/color/tests/src/Functional/ColorTest.php similarity index 97% rename from core/modules/color/test/src/Functional/ColorTest.php rename to core/modules/color/tests/src/Functional/ColorTest.php index dc44566..7ea8ace 100644 --- a/core/modules/color/test/src/Functional/ColorTest.php +++ b/core/modules/color/tests/src/Functional/ColorTest.php @@ -108,7 +108,7 @@ function _testColor($theme, $test_values) { $this->drupalLogin($this->bigUser); $this->drupalGet($settings_path); $this->assertResponse(200); - $this->assertUniqueText('Color set'); + $this->assertSession()->assertUniqueText('Color set'); $edit['scheme'] = ''; $edit[$test_values['palette_input']] = '#123456'; $this->drupalPostForm($settings_path, $edit, t('Save configuration')); @@ -116,7 +116,7 @@ function _testColor($theme, $test_values) { $this->drupalGet(''); $stylesheets = $this->config('color.theme.' . $theme)->get('stylesheets'); foreach ($stylesheets as $stylesheet) { - $this->assertPattern('|' . file_url_transform_relative(file_create_url($stylesheet)) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')'); + $this->assertSession()->responseMatches('|' . file_url_transform_relative(file_create_url($stylesheet)) . '|'); $stylesheet_content = join("\n", file($stylesheet)); $this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')'); } diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php index 20f16c5..6ca9f85 100644 --- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php @@ -204,19 +204,6 @@ protected function assertNoRaw($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 Scheduled for removal in Drupal 9.0.0. - * Use $this->assertSession()->responseMatches() instead. - */ - protected function assertPattern($pattern) { - $this->assertSession()->responseMatches($pattern); - } - - /** * Pass if the page title is the given string. * * @param string $expected_title diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index a70e0cf..fbb0c65 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -236,15 +236,6 @@ protected $preserveGlobalState = FALSE; /** - * The drupalSettings value from the current raw $content. - * - * The drupalSettings refers to the drupalSettings JavaScript variable. - * - * @var array - */ - protected $drupalSettings = []; - - /** * Class name for HTML output logging. * * @var string @@ -344,7 +335,7 @@ protected function initMink() { /** * Gets an instance of the default Mink driver. * - * @return Behat\Mink\Driver\DriverInterface + * @return \Behat\Mink\Driver\DriverInterface * Instance of default Mink driver. * * @throws \InvalidArgumentException @@ -650,11 +641,7 @@ protected function drupalGet($path, array $options = array()) { $this->prepareRequest(); $session->visit($url); $out = $session->getPage()->getContent(); - // Store the drupalSettings JavaScript variable. - $this->drupalSettings = []; - if (preg_match('@@', $out, $matches)) { - $this->drupalSettings = Json::decode($matches[1]); - } + // Ensure that any changes to variables in the other thread are picked up. $this->refreshVariables(); @@ -825,15 +812,11 @@ protected function submitForm(array $edit, $submit, $form_html_id = NULL) { // Submit form. $this->prepareRequest(); $submit_button->press(); - // Store the drupalSettings JavaScript variable. - $out = $this->getSession()->getPage()->getContent(); - $this->drupalSettings = []; - if (preg_match('@@', $out, $matches)) { - $this->drupalSettings = Json::decode($matches[1]); - } + // Ensure that any changes to variables in the other thread are picked up. $this->refreshVariables(); if ($this->htmlOutputEnabled) { + $out = $this->getSession()->getPage()->getContent(); $html_output = 'POST request to: ' . $action . '
Ending URL: ' . $this->getSession()->getCurrentUrl(); $html_output .= '
' . $out; @@ -1501,30 +1484,6 @@ public function __sleep() { } /** - * Gets the value of drupalSettings for the currently-loaded page. - * - * The drupalSettings refers to the drupalSettings JavaScript variable. - * - * @return array - * The drupalSettings value from the current page. - */ - protected function getDrupalSettings() { - return $this->drupalSettings; - } - - /** - * Sets the value of drupalSettings for the currently-loaded page. - * - * The drupalSettings refers to the drupalSettings JavaScript variable. - * - * @param array $settings - * The drupalSettings JavaScript variable. - */ - protected function setDrupalSettings(array $settings) { - $this->drupalSettings = $settings; - } - - /** * Logs a HTML output message in a text file. * * The link to the HTML output message will be printed by the results printer. @@ -1706,56 +1665,6 @@ public static function assertEquals($expected, $actual, $message = '', $delta = } /** - * 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. - */ - protected function assertUniqueText($text) { - $this->assertUniqueTextHelper($text, TRUE); - } - - /** - * 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. - */ - protected function assertNoUniqueText($text) { - $this->assertUniqueTextHelper($text, FALSE); - } - - /** - * Helper for assertUniqueText and assertNoUniqueText. - * - * It is not recommended to call this function directly. - * - * @param string|\Drupal\Component\Render\MarkupInterface $text - * Plain text to look for. - * @param bool $be_unique - * (optional) TRUE if this text should be found only once, FALSE if it - * should be found more than once. Defaults to FALSE. - */ - protected function assertUniqueTextHelper($text, $be_unique = FALSE) { - // Cast MarkupInterface objects to string. - $text = (string) $text; - $message = '"' . $text . '"' . ($be_unique ? ' found only once' : ' found more than once'); - $first_occurrence = strpos($this->getTextContent(), $text); - $this->assertNotFalse($first_occurence, $message); - $offset = $first_occurrence + strlen($text); - $second_occurrence = strpos($this->getTextContent(), $text, $offset); - $this->assertTrue($be_unique === ($second_occurrence === FALSE), $message); - } - - /** * Changes parameters in the services.yml file. * * @param string $name diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index 6156dda..cc801bd 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -422,4 +422,55 @@ public function fieldDisabled($field, TraversableElement $container = NULL) { return $node; } + /** + * 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. + */ + public function assertUniqueText($text) { + $this->assertUniqueTextHelper($text, TRUE); + } + + /** + * 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. + */ + public function assertNoUniqueText($text) { + $this->assertUniqueTextHelper($text, FALSE); + } + + /** + * Helper for assertUniqueText and assertNoUniqueText. + * + * It is not recommended to call this function directly. + * + * @param string|\Drupal\Component\Render\MarkupInterface $text + * Plain text to look for. + * @param bool $be_unique + * (optional) TRUE if this text should be found only once, FALSE if it + * should be found more than once. Defaults to FALSE. + */ + protected function assertUniqueTextHelper($text, $be_unique = FALSE) { + // Cast MarkupInterface objects to string. + $text = (string) $text; + $message = '"' . $text . '"' . ($be_unique ? ' found only once' : ' found more than once'); + $content = $this->session->getPage()->getContent(); + $first_occurrence = strpos($content, $text); + $this->assert($first_occurrence !== FALSE, $message); + $offset = $first_occurrence + strlen($text); + $second_occurrence = strpos($content, $text, $offset); + $this->assert($be_unique === ($second_occurrence === FALSE), $message); + } + }