function SectionTest::testGetLayout

Same name 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 \Drupal\layout_builder\Section @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.