function UserAccessControlHandlerTest::setUp
Same name in other branches
- 9 core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::setUp()
- 8.9.x core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::setUp()
- 11.x core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::setUp()
Overrides UnitTestCase::setUp
File
-
core/
modules/ user/ tests/ src/ Unit/ UserAccessControlHandlerTest.php, line 68
Class
- UserAccessControlHandlerTest
- Tests the user access controller.
Namespace
Drupal\Tests\user\UnitCode
protected function setUp() : void {
parent::setUp();
$cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
$cache_contexts_manager->assertValidTokens()
->willReturn(TRUE);
$cache_contexts_manager->reveal();
$container = new Container();
$container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
$this->viewer = $this->createMock('\\Drupal\\user\\UserInterface');
$this->viewer
->expects($this->any())
->method('hasPermission')
->willReturn(FALSE);
$this->viewer
->expects($this->any())
->method('id')
->willReturn(1);
$this->owner = $this->createMock('\\Drupal\\user\\UserInterface');
$this->owner
->expects($this->any())
->method('hasPermission')
->willReturnMap([
[
'administer users',
FALSE,
],
[
'change own username',
TRUE,
],
]);
$this->owner
->expects($this->any())
->method('id')
->willReturn(2);
$this->admin = $this->createMock('\\Drupal\\user\\UserInterface');
$this->admin
->expects($this->any())
->method('hasPermission')
->willReturn(TRUE);
$this->emailViewer = $this->createMock('\\Drupal\\user\\UserInterface');
$this->emailViewer
->expects($this->any())
->method('hasPermission')
->willReturnMap([
[
'view user email addresses',
TRUE,
],
]);
$this->emailViewer
->expects($this->any())
->method('id')
->willReturn(3);
$entity_type = $this->createMock('Drupal\\Core\\Entity\\EntityTypeInterface');
$this->accessControlHandler = new UserAccessControlHandler($entity_type);
$module_handler = $this->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$this->accessControlHandler
->setModuleHandler($module_handler);
$this->items = $this->getMockBuilder('Drupal\\Core\\Field\\FieldItemList')
->disableOriginalConstructor()
->getMock();
$this->items
->expects($this->any())
->method('defaultAccess')
->willReturn(AccessResult::allowed());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.