You are here

public function CurrentUserContextTest::testOnPageContext in Page Manager 8

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

@covers ::onPageContext

File

tests/src/Unit/CurrentUserContextTest.php, line 32
Contains \Drupal\Tests\page_manager\Unit\CurrentUserContextTest.

Class

CurrentUserContextTest
Tests the current user context.

Namespace

Drupal\Tests\page_manager\Unit

Code

public function testOnPageContext() {
  $account = $this
    ->prophesize(AccountInterface::class);
  $account
    ->id()
    ->willReturn(1);
  $user = $this
    ->prophesize(UserInterface::class);
  $data_definition = new DataDefinition([
    'type' => 'entity:user',
  ]);
  $this->typedDataManager
    ->create($data_definition, $user)
    ->willReturn(EntityAdapter::createFromEntity($user
    ->reveal()));
  $this->typedDataManager
    ->getDefaultConstraints($data_definition)
    ->willReturn([]);
  $this->typedDataManager
    ->createDataDefinition('entity:user')
    ->will(function () use ($data_definition) {
    return $data_definition;
  });
  $this->page
    ->addContext('current_user', Argument::type(Context::class))
    ->shouldBeCalled();
  $user_storage = $this
    ->prophesize(EntityStorageInterface::class);
  $user_storage
    ->load(1)
    ->willReturn($user
    ->reveal());
  $entity_type_manager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $entity_type_manager
    ->getStorage('user')
    ->willReturn($user_storage
    ->reveal());
  $route_param_context = new CurrentUserContext($account
    ->reveal(), $entity_type_manager
    ->reveal());
  $route_param_context
    ->onPageContext($this->event);
}