You are here

public function ScriptManagerTest::assertOrderInPage in Script Manager 8

Asserts that several pieces of markup are in a given order in the page.

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 ScriptManagerTest::assertOrderInPage()
ScriptManagerTest::testScriptManagerPositions in tests/src/Functional/ScriptManagerTest.php
Test the different page positions.

File

tests/src/Functional/ScriptManagerTest.php, line 109

Class

ScriptManagerTest
Test the script manager module.

Namespace

Drupal\Tests\script_manager\Functional

Code

public function assertOrderInPage(array $items) {
  $text = $this
    ->getSession()
    ->getPage()
    ->getHtml();
  $strings = [];
  foreach ($items as $item) {
    if (($pos = strpos($text, $item)) === FALSE) {
      throw new ExpectationException("Cannot find '{$item}' in the page", $this
        ->getSession()
        ->getDriver());
    }
    $strings[$pos] = $item;
  }
  ksort($strings);
  $ordered = implode(', ', array_map(function ($item) {
    return "'{$item}'";
  }, $items));
  if ($items !== array_values($strings)) {
    throw new ExpectationException("Strings were not correctly ordered as: {$ordered}.", $this
      ->getSession()
      ->getDriver());
  }
}