You are here

public function SectionTest::testGetLayout in Drupal 10

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()

@covers ::getLayout @dataProvider providerTestGetLayout

File

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

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) {
  $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);
}