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. 8.9.x core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderNoBlock()
  3. 10 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 528

Class

BlockComponentRenderArrayTest
@coversDefaultClass \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray[[api-linebreak]] @group layout_builder

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testOnBuildRenderNoBlock() : void {
  $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.