function UserAccessControlHandlerTest::setUp

Same name and namespace in other branches
  1. 11.x core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::setUp()
  2. 10 core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::setUp()
  3. 9 core/modules/user/tests/src/Unit/UserAccessControlHandlerTest.php \Drupal\Tests\user\Unit\UserAccessControlHandlerTest::setUp()
  4. 8.9.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 74

Class

UserAccessControlHandlerTest
Tests the user access controller.

Namespace

Drupal\Tests\user\Unit

Code

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->createStub(UserInterface::class);
  $this->viewer
    ->method('hasPermission')
    ->willReturn(FALSE);
  $this->viewer
    ->method('id')
    ->willReturn(1);
  $this->owner = $this->createStub(UserInterface::class);
  $this->owner
    ->method('hasPermission')
    ->willReturnMap([
    [
      'administer users',
      FALSE,
    ],
    [
      'change own username',
      TRUE,
    ],
  ]);
  $this->owner
    ->method('id')
    ->willReturn(2);
  $this->admin = $this->createStub(UserInterface::class);
  $this->admin
    ->method('hasPermission')
    ->willReturn(TRUE);
  $this->emailViewer = $this->createStub(UserInterface::class);
  $this->emailViewer
    ->method('hasPermission')
    ->willReturnMap([
    [
      'view user email addresses',
      TRUE,
    ],
  ]);
  $this->emailViewer
    ->method('id')
    ->willReturn(3);
  $this->accessControlHandler = new UserAccessControlHandler($this->createStub(EntityTypeInterface::class));
  $this->accessControlHandler
    ->setModuleHandler($this->createStub(ModuleHandlerInterface::class));
  $this->items = $this->createStub(FieldItemList::class);
  $this->items
    ->method('defaultAccess')
    ->willReturn(AccessResult::allowed());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.