diff --git a/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php b/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php index 94e7812892..33528cd2e3 100644 --- a/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php +++ b/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\book\FunctionalJavascript; -use Behat\Mink\Exception\ExpectationException; use Drupal\Component\Render\FormattableMarkup; use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\Node; diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 0d3c3bf95c..ee58657b67 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -297,12 +297,12 @@ public function testOrderInPage() { $this->drupalGet('test-order-in-page'); // Check that asserting order in page markup and page works. - $this->assertSession()->orderInPageContent(['item3', 'item1', 'item2']); + $this->assertSession()->orderInPageHtml(['item3', 'item1', 'item2']); $this->assertSession()->orderInPageText(['item3', 'item2', 'item1']); // Check that passing non-existent search strings throws an exception. $this->setExpectedException(ElementNotFoundException::class, "Cannot find item(s): 'item5', 'item8'."); - $this->assertSession()->orderInPageContent(['item5', 'item1', 'item8']); + $this->assertSession()->orderInPageHtml(['item5', 'item1', 'item8']); } } diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index 32f6227822..b9a5432854 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -507,7 +507,7 @@ public function hiddenFieldValueNotEquals($field, $value, TraversableElement $co * @param string[] $items * An ordered list of strings. */ - public function orderInPageContent(array $items) { + public function orderInPageHtml(array $items) { $this->orderInPageHelper($items, $this->session->getPage()->getHtml()); } @@ -532,29 +532,35 @@ public function orderInPageText(array $items) { * @throws \Behat\Mink\Exception\ElementNotFoundException * When one or more of passed items are not found. * - * @see \Drupal\Tests\WebAssert::orderInPageContent() + * @see \Drupal\Tests\WebAssert::orderInPageHtml() * @see \Drupal\Tests\WebAssert::orderInPageText() */ protected function orderInPageHelper(array $items, $string) { $strings = $not_found = []; foreach ($items as $item) { if (($pos = strpos($string, $item)) === FALSE) { - $not_found[] = "'$item'"; + if (!in_array($item, $not_found)) { + $not_found[] = $item; + } } else { $strings[$pos] = $item; } } + $quote_string_list = function (array $list) { + return implode(', ', array_map(function ($string) { + return "'$string'"; + }, $list)); + }; + if ($not_found) { - $not_found = implode(', ', $not_found); + $not_found = $quote_string_list($not_found); throw new ElementNotFoundException($this->session->getDriver(), "Cannot find item(s): $not_found."); } ksort($strings); - $ordered = implode(', ', array_map(function ($item) { - return "'$item'"; - }, $items)); + $ordered = $quote_string_list($items); $this->assert($items === array_values($strings), "Strings correctly ordered as: $ordered."); }