function SectionRenderTest::setUp

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

Overrides UnitTestCase::setUp

File

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

Class

SectionRenderTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21layout_builder%21src%21Section.php/class/Section/8.9.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

protected function setUp() {
    parent::setUp();
    $layout_plugin_manager = $this->prophesize(LayoutPluginManagerInterface::class);
    $this->blockManager = $this->prophesize(BlockManagerInterface::class);
    $this->contextHandler = $this->prophesize(ContextHandlerInterface::class);
    $this->contextRepository = $this->prophesize(ContextRepositoryInterface::class);
    // @todo Refactor this into some better tests in https://www.drupal.org/node/2942605.
    $this->eventDispatcher = (new \ReflectionClass(ContainerAwareEventDispatcher::class))->newInstanceWithoutConstructor();
    $this->account = $this->prophesize(AccountInterface::class);
    $subscriber = new BlockComponentRenderArray($this->account
        ->reveal());
    $this->eventDispatcher
        ->addSubscriber($subscriber);
    $layout = $this->prophesize(LayoutInterface::class);
    $layout->getPluginDefinition()
        ->willReturn(new LayoutDefinition([]));
    $layout->build(Argument::type('array'))
        ->willReturnArgument(0);
    $layout_plugin_manager->createInstance('layout_onecol', [])
        ->willReturn($layout->reveal());
    $container = new ContainerBuilder();
    $container->set('current_user', $this->account
        ->reveal());
    $container->set('plugin.manager.block', $this->blockManager
        ->reveal());
    $container->set('plugin.manager.core.layout', $layout_plugin_manager->reveal());
    $container->set('context.handler', $this->contextHandler
        ->reveal());
    $container->set('context.repository', $this->contextRepository
        ->reveal());
    $container->set('event_dispatcher', $this->eventDispatcher);
    \Drupal::setContainer($container);
}

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