예제 #1
0
 /**
  * @covers ::onPageContext
  */
 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->executable->expects($this->once())->method('addContext')->with('current_user', $this->isInstanceOf(Context::class));
     $user_storage = $this->prophesize(EntityStorageInterface::class);
     $user_storage->load(1)->willReturn($user->reveal());
     $entity_manager = $this->prophesize(EntityManagerInterface::class);
     $entity_manager->getStorage('user')->willReturn($user_storage->reveal());
     $route_param_context = new CurrentUserContext($account->reveal(), $entity_manager->reveal());
     $route_param_context->onPageContext($this->event);
 }
 /**
  * @covers ::onPageContext
  */
 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);
 }