CurrentUserContextTest.php in Page Manager 8.4
Same filename and directory in other branches
Namespace
Drupal\Tests\page_manager\UnitFile
tests/src/Unit/CurrentUserContextTest.phpView source
<?php
namespace Drupal\Tests\page_manager\Unit;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\EntityContext;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\Core\Plugin\Context\LazyContextRepository;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\page_manager\EventSubscriber\CurrentUserContext;
use Prophecy\Argument;
/**
* Tests the current user context.
*
* @coversDefaultClass \Drupal\page_manager\EventSubscriber\CurrentUserContext
*
* @group PageManager
*/
class CurrentUserContextTest extends PageContextTestBase {
/**
* @covers ::onPageContext
*/
public function testOnPageContext() {
$currentUser = $this
->getMockBuilder(AccountProxyInterface::class)
->disableOriginalConstructor()
->getMock();
$contextRepository = $this
->getMockBuilder(LazyContextRepository::class)
->disableOriginalConstructor()
->getMock();
$currentUserContext = new EntityContext(new EntityContextDefinition('user', 'current_user_context'), $currentUser
->getAccount());
$contextRepository
->expects($this
->once())
->method('getRunTimeContexts')
->willReturn([
'@user.current_user_context:current_user' => $currentUserContext,
]);
$this->page
->addContext('@user.current_user_context:current_user', Argument::type(Context::class))
->shouldBeCalled()
->willReturn($this->page);
$this->page
->addContext('current_user', Argument::type(Context::class))
->shouldBeCalled()
->willReturn($this->page);
$route_param_context = new CurrentUserContext($contextRepository);
$route_param_context
->onPageContext($this->event);
}
}
Classes
Name | Description |
---|---|
CurrentUserContextTest | Tests the current user context. |