function BookJavascriptTest::assertOrderInPage
Same name in other branches
- 9 core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php \Drupal\Tests\book\FunctionalJavascript\BookJavascriptTest::assertOrderInPage()
- 8.9.x core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php \Drupal\Tests\book\FunctionalJavascript\BookJavascriptTest::assertOrderInPage()
- 11.x core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php \Drupal\Tests\book\FunctionalJavascript\BookJavascriptTest::assertOrderInPage()
Asserts that several pieces of markup are in a given order in the page.
@internal
@todo Remove this once https://www.drupal.org/node/2817657 is committed.
Parameters
string[] $items: An ordered list of strings.
Throws
\Behat\Mink\Exception\ExpectationException When any of the given string is not found.
1 call to BookJavascriptTest::assertOrderInPage()
- BookJavascriptTest::testBookOrdering in core/
modules/ book/ tests/ src/ FunctionalJavascript/ BookJavascriptTest.php - Tests re-ordering of books.
File
-
core/
modules/ book/ tests/ src/ FunctionalJavascript/ BookJavascriptTest.php, line 153
Class
- BookJavascriptTest
- Tests Book javascript functionality.
Namespace
Drupal\Tests\book\FunctionalJavascriptCode
protected function assertOrderInPage(array $items) : void {
$session = $this->getSession();
$text = $session->getPage()
->getHtml();
$strings = [];
foreach ($items as $item) {
if (($pos = strpos($text, $item)) === FALSE) {
throw new ExpectationException("Cannot find '{$item}' in the page", $session->getDriver());
}
$strings[$pos] = $item;
}
ksort($strings);
$ordered = implode(', ', array_map(function ($item) {
return "'{$item}'";
}, $items));
$this->assertSame($items, array_values($strings), "Found strings, ordered as: {$ordered}.");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.