function UserAccessControlHandlerTest::setUp

Same name and namespace in other branches
  1. 9 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. 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 59

Class

UserAccessControlHandlerTest
Tests the user access controller.

Namespace

Drupal\Tests\user\Unit

Code

protected function setUp() {
    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')
        ->will($this->returnValueMap([
        [
            '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));
    $entity_type = $this->createMock('Drupal\\Core\\Entity\\EntityTypeInterface');
    $this->accessControlHandler = new UserAccessControlHandler($entity_type);
    $module_handler = $this->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $module_handler->expects($this->any())
        ->method('getImplementations')
        ->will($this->returnValue([]));
    $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()));
}

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