function LayoutSectionTest::assertLayoutSection

Same name and namespace in other branches
  1. 8.9.x core/modules/layout_builder/tests/src/Functional/LayoutSectionTest.php \Drupal\Tests\layout_builder\Functional\LayoutSectionTest::assertLayoutSection()
  2. 10 core/modules/layout_builder/tests/src/Functional/LayoutSectionTest.php \Drupal\Tests\layout_builder\Functional\LayoutSectionTest::assertLayoutSection()
  3. 11.x core/modules/layout_builder/tests/src/Functional/LayoutSectionTest.php \Drupal\Tests\layout_builder\Functional\LayoutSectionTest::assertLayoutSection()

Asserts the output of a layout section.

@internal

Parameters

string|array $expected_selector: A selector or list of CSS selectors to find.

string|array $expected_content: A string or list of strings to find.

string $expected_cache_contexts: A string of cache contexts to be found in the header.

string $expected_cache_tags: A string of cache tags to be found in the header.

string $expected_dynamic_cache: The expected dynamic cache header. Either 'HIT', 'MISS' or 'UNCACHEABLE'.

2 calls to LayoutSectionTest::assertLayoutSection()
LayoutSectionTest::testLayoutSectionFormatter in core/modules/layout_builder/tests/src/Functional/LayoutSectionTest.php
Tests layout_section formatter output.
LayoutSectionTest::testLayoutSectionFormatterAccess in core/modules/layout_builder/tests/src/Functional/LayoutSectionTest.php
Tests the access checking of the section formatter.

File

core/modules/layout_builder/tests/src/Functional/LayoutSectionTest.php, line 299

Class

LayoutSectionTest
Tests the rendering of a layout section field.

Namespace

Drupal\Tests\layout_builder\Functional

Code

protected function assertLayoutSection($expected_selector, $expected_content, string $expected_cache_contexts = '', string $expected_cache_tags = '', string $expected_dynamic_cache = 'MISS') : void {
    $assert_session = $this->assertSession();
    // Find the given selector.
    foreach ((array) $expected_selector as $selector) {
        $element = $this->cssSelect($selector);
        $this->assertNotEmpty($element);
    }
    // Find the given content.
    foreach ((array) $expected_content as $content) {
        $assert_session->pageTextContains($content);
    }
    if ($expected_cache_contexts) {
        $assert_session->responseHeaderContains('X-Drupal-Cache-Contexts', $expected_cache_contexts);
    }
    if ($expected_cache_tags) {
        $assert_session->responseHeaderContains('X-Drupal-Cache-Tags', $expected_cache_tags);
    }
    $assert_session->responseHeaderEquals('X-Drupal-Dynamic-Cache', $expected_dynamic_cache);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.