function BlockComponentRenderArrayTest::testOnBuildRenderNoBlock

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderNoBlock()
  2. 10 core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderNoBlock()
  3. 11.x core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderNoBlock()

@covers ::onBuildRender

File

core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php, line 497

Class

BlockComponentRenderArrayTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21layout_builder%21src%21EventSubscriber%21BlockComponentRenderArray.php/class/BlockComponentRenderArray/8.9.x" title="Builds render arrays and handles access for all block components." class="local">\Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray</a> @group layout_builder

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testOnBuildRenderNoBlock() {
    $this->blockManager
        ->createInstance('some_block_id', [
        'id' => 'some_block_id',
    ])
        ->willReturn(NULL);
    $component = new SectionComponent('some-uuid', 'some-region', [
        'id' => 'some_block_id',
    ]);
    $contexts = [];
    $in_preview = FALSE;
    $event = new SectionComponentBuildRenderArrayEvent($component, $contexts, $in_preview);
    $subscriber = new BlockComponentRenderArray($this->account
        ->reveal());
    $expected_build = [];
    $expected_cache = [
        '#cache' => [
            'contexts' => [],
            'tags' => [],
            'max-age' => -1,
        ],
    ];
    $subscriber->onBuildRender($event);
    $result = $event->getBuild();
    $this->assertEquals($expected_build, $result);
    $event->getCacheableMetadata()
        ->applyTo($result);
    $this->assertEquals($expected_cache, $result);
}

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