function SectionTest::testGetLayout

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/Unit/SectionTest.php \Drupal\Tests\layout_builder\Unit\SectionTest::testGetLayout()
  2. 10 core/modules/layout_builder/tests/src/Unit/SectionTest.php \Drupal\Tests\layout_builder\Unit\SectionTest::testGetLayout()

@covers ::getLayout @dataProvider providerTestGetLayout

File

core/modules/layout_builder/tests/src/Unit/SectionTest.php, line 377

Class

SectionTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21layout_builder%21src%21Section.php/class/Section/11.x" 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 testGetLayout(array $contexts, bool $should_context_apply) : void {
    $layout = $this->prophesize(LayoutInterface::class);
    $layout_plugin_manager = $this->prophesize(LayoutPluginManagerInterface::class);
    $layout_plugin_manager->createInstance('layout_onecol', [])
        ->willReturn($layout->reveal());
    $context_handler = $this->prophesize(ContextHandlerInterface::class);
    if ($should_context_apply) {
        $context_handler->applyContextMapping($layout->reveal(), $contexts)
            ->shouldBeCalled();
    }
    else {
        $context_handler->applyContextMapping($layout->reveal(), $contexts)
            ->shouldNotBeCalled();
    }
    $container = new ContainerBuilder();
    $container->set('plugin.manager.core.layout', $layout_plugin_manager->reveal());
    $container->set('context.handler', $context_handler->reveal());
    \Drupal::setContainer($container);
    $output = $this->section
        ->getLayout($contexts);
    $this->assertSame($layout->reveal(), $output);
}

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