You are here

public function PageTest::testGetContexts in Page Manager 8

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/PageTest.php \Drupal\Tests\page_manager\Unit\PageTest::testGetContexts()

@covers ::getContexts

File

tests/src/Unit/PageTest.php, line 186
Contains \Drupal\Tests\page_manager\Unit\PageTest.

Class

PageTest
Tests the Page entity.

Namespace

Drupal\Tests\page_manager\Unit

Code

public function testGetContexts() {
  $context = new Context(new ContextDefinition('bar'));
  $event_dispatcher = $this
    ->prophesize(EventDispatcherInterface::class);
  $event_dispatcher
    ->dispatch(PageManagerEvents::PAGE_CONTEXT, Argument::type(PageManagerContextEvent::class))
    ->will(function ($args) use ($context) {
    $args[1]
      ->getPage()
      ->addContext('foo', $context);
  });
  $container = new ContainerBuilder();
  $container
    ->set('event_dispatcher', $event_dispatcher
    ->reveal());
  \Drupal::setContainer($container);
  $contexts = $this->page
    ->getContexts();
  $this
    ->assertSame([
    'foo' => $context,
  ], $contexts);
}