function SectionRenderTest::testContextAwareBlock

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

@covers ::toRenderArray

File

core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php, line 243

Class

SectionRenderTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21layout_builder%21src%21Section.php/class/Section/9" title="Provides a domain object for layout sections." class="local">\Drupal\layout_builder\Section</a> @group layout_builder

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testContextAwareBlock() {
    $block_content = [
        '#markup' => 'The block content.',
    ];
    $placeholder_label = 'Placeholder Label';
    $render_array = [
        '#theme' => 'block',
        '#weight' => 0,
        '#configuration' => [],
        '#plugin_id' => 'block_plugin_id',
        '#base_plugin_id' => 'block_plugin_id',
        '#derivative_plugin_id' => NULL,
        'content' => $block_content,
        '#cache' => [
            'contexts' => [],
            'tags' => [],
            'max-age' => -1,
        ],
        '#in_preview' => FALSE,
    ];
    $block = $this->prophesize(BlockPluginInterface::class)
        ->willImplement(ContextAwarePluginInterface::class)
        ->willImplement(PreviewFallbackInterface::class);
    $this->blockManager
        ->createInstance('block_plugin_id', [
        'id' => 'block_plugin_id',
    ])
        ->willReturn($block->reveal());
    $access_result = AccessResult::allowed();
    $block->access($this->account
        ->reveal(), TRUE)
        ->willReturn($access_result);
    $block->build()
        ->willReturn($block_content);
    $block->getCacheContexts()
        ->willReturn([]);
    $block->getCacheTags()
        ->willReturn([]);
    $block->getCacheMaxAge()
        ->willReturn(Cache::PERMANENT);
    $block->getContextMapping()
        ->willReturn([]);
    $block->getPluginId()
        ->willReturn('block_plugin_id');
    $block->getBaseId()
        ->willReturn('block_plugin_id');
    $block->getDerivativeId()
        ->willReturn(NULL);
    $block->getConfiguration()
        ->willReturn([]);
    $block->getPreviewFallbackString()
        ->willReturn($placeholder_label);
    $section = [
        new SectionComponent('some_uuid', 'content', [
            'id' => 'block_plugin_id',
        ]),
    ];
    $expected = [
        'content' => [
            'some_uuid' => $render_array,
        ],
    ];
    $result = (new Section('layout_onecol', [], $section))->toRenderArray();
    $this->assertEquals($expected, $result);
}

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