You are here

public function UserAccessControlHandlerTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 64
Contains \Drupal\Tests\user\Unit\UserAccessControlHandlerTest.

Class

UserAccessControlHandlerTest
Tests the user access controller.

Namespace

Drupal\Tests\user\Unit

Code

public 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
    ->getMock('\\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
    ->getMock('\\Drupal\\Core\\Session\\AccountInterface');
  $this->owner
    ->expects($this
    ->any())
    ->method('hasPermission')
    ->will($this
    ->returnValueMap(array(
    array(
      'administer users',
      FALSE,
    ),
    array(
      'change own username',
      TRUE,
    ),
  )));
  $this->owner
    ->expects($this
    ->any())
    ->method('id')
    ->will($this
    ->returnValue(2));
  $this->admin = $this
    ->getMock('\\Drupal\\Core\\Session\\AccountInterface');
  $this->admin
    ->expects($this
    ->any())
    ->method('hasPermission')
    ->will($this
    ->returnValue(TRUE));
  $entity_type = $this
    ->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
  $this->accessControlHandler = new UserAccessControlHandler($entity_type);
  $module_handler = $this
    ->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
  $module_handler
    ->expects($this
    ->any())
    ->method('getImplementations')
    ->will($this
    ->returnValue(array()));
  $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()));
}