You are here

public function BlockComponentRenderArrayTest::testOnBuildRenderNoBlock in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderNoBlock()
  2. 9 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 \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray @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);
}