You are here

protected function BookJavascriptTest::assertOrderInPage in Drupal 9

Same name and namespace in other branches
  1. 8 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.

@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 148

Class

BookJavascriptTest
Tests Book javascript functionality.

Namespace

Drupal\Tests\book\FunctionalJavascript

Code

protected function assertOrderInPage(array $items) {
  $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}.");
}