protected function UserAccessControlHandlerTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::setUp()
- 9 core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::setUp()
File
- core/
modules/ user/ tests/ src/ Unit/ UserAccessControlHandlerTest.php, line 66
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\\Core\\Session\\AccountInterface');
$this->viewer
->expects($this
->any())
->method('hasPermission')
->will($this
->returnValue(FALSE));
$this->viewer
->expects($this
->any())
->method('id')
->will($this
->returnValue(1));
$this->owner = $this
->createMock('\\Drupal\\Core\\Session\\AccountInterface');
$this->owner
->expects($this
->any())
->method('hasPermission')
->willReturnMap([
[
'administer users',
FALSE,
],
[
'change own username',
TRUE,
],
]);
$this->owner
->expects($this
->any())
->method('id')
->will($this
->returnValue(2));
$this->admin = $this
->createMock('\\Drupal\\Core\\Session\\AccountInterface');
$this->admin
->expects($this
->any())
->method('hasPermission')
->will($this
->returnValue(TRUE));
$this->emailViewer = $this
->createMock('\\Drupal\\Core\\Session\\AccountInterface');
$this->emailViewer
->expects($this
->any())
->method('hasPermission')
->willReturnMap([
[
'view user email addresses',
TRUE,
],
]);
$this->emailViewer
->expects($this
->any())
->method('id')
->will($this
->returnValue(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')
->will($this
->returnValue(AccessResult::allowed()));
}