diff --git a/core/modules/color/src/Tests/ColorConfigSchemaTest.php b/core/modules/color/tests/src/Functional/ColorConfigSchemaTest.php similarity index 87% rename from core/modules/color/src/Tests/ColorConfigSchemaTest.php rename to core/modules/color/tests/src/Functional/ColorConfigSchemaTest.php index 941e520..157deb8 100644 --- a/core/modules/color/src/Tests/ColorConfigSchemaTest.php +++ b/core/modules/color/tests/src/Functional/ColorConfigSchemaTest.php @@ -1,15 +1,15 @@ 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/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index ded28f2..fbb0c65 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -335,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 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); + } + }