function ManageDisplayTest::assertOrderInPage

Same name and namespace in other branches
  1. 10 core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::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.

2 calls to ManageDisplayTest::assertOrderInPage()
ManageDisplayTest::testFormModeLocalTasksOrder in core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php
Tests if form mode local tasks appear in alphabetical order by label.
ManageDisplayTest::testViewModeLocalTasksOrder in core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php
Tests if display mode local tasks appear in alphabetical order by label.

File

core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php, line 432

Class

ManageDisplayTest
Tests the Field UI "Manage display" and "Manage form display" screens.

Namespace

Drupal\Tests\field_ui\Functional

Code

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.