diff --git a/core/modules/color/src/Tests/ColorConfigSchemaTest.php b/core/modules/color/test/src/Functional/ColorConfigSchemaTest.php similarity index 87% rename from core/modules/color/src/Tests/ColorConfigSchemaTest.php rename to core/modules/color/test/src/Functional/ColorConfigSchemaTest.php index 941e520..157deb8 100644 --- a/core/modules/color/src/Tests/ColorConfigSchemaTest.php +++ b/core/modules/color/test/src/Functional/ColorConfigSchemaTest.php @@ -1,15 +1,15 @@ assertSession()->responseMatches() instead. + */ + protected function assertPattern($pattern) { + $this->assertSession()->responseMatches($pattern); + } + + /** + * 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); + if ($first_occurrence === FALSE) { + $this->assertTrue(FALSE, $message); + } + $offset = $first_occurrence + strlen($text); + $second_occurrence = strpos($this->getTextContent(), $text, $offset); + $this->assertTrue($be_unique == ($second_occurrence === FALSE), $message); + } + + /** * 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 3beb32f..f5efd29 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -7,6 +7,7 @@ use Behat\Mink\Mink; use Behat\Mink\Session; use Drupal\Component\FileCache\FileCacheFactory; +use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Yaml; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; @@ -232,6 +233,15 @@ 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 @@ -637,7 +647,11 @@ 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(); @@ -941,11 +955,15 @@ 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; @@ -1613,6 +1631,30 @@ 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.