protected function UserSessionTest::setUp in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::setUp()
Overrides UnitTestCase::setUp
File
- core/
tests/ Drupal/ Tests/ Core/ Session/ UserSessionTest.php, line 61 - Contains \Drupal\Tests\Core\Session\UserSessionTest.
Class
- UserSessionTest
- @coversDefaultClass \Drupal\Core\Session\UserSession @group Session
Namespace
Drupal\Tests\Core\SessionCode
protected function setUp() {
parent::setUp();
$roles = array();
$roles['role_one'] = $this
->getMockBuilder('Drupal\\user\\Entity\\Role')
->disableOriginalConstructor()
->setMethods(array(
'hasPermission',
))
->getMock();
$roles['role_one']
->expects($this
->any())
->method('hasPermission')
->will($this
->returnValueMap(array(
array(
'example permission',
TRUE,
),
array(
'another example permission',
FALSE,
),
array(
'last example permission',
FALSE,
),
)));
$roles['role_two'] = $this
->getMockBuilder('Drupal\\user\\Entity\\Role')
->disableOriginalConstructor()
->setMethods(array(
'hasPermission',
))
->getMock();
$roles['role_two']
->expects($this
->any())
->method('hasPermission')
->will($this
->returnValueMap(array(
array(
'example permission',
TRUE,
),
array(
'another example permission',
TRUE,
),
array(
'last example permission',
FALSE,
),
)));
$roles['anonymous'] = $this
->getMockBuilder('Drupal\\user\\Entity\\Role')
->disableOriginalConstructor()
->setMethods(array(
'hasPermission',
))
->getMock();
$roles['anonymous']
->expects($this
->any())
->method('hasPermission')
->will($this
->returnValueMap(array(
array(
'example permission',
FALSE,
),
array(
'another example permission',
FALSE,
),
array(
'last example permission',
FALSE,
),
)));
$role_storage = $this
->getMockBuilder('Drupal\\user\\RoleStorage')
->disableOriginalConstructor()
->setMethods(array(
'loadMultiple',
))
->getMock();
$role_storage
->expects($this
->any())
->method('loadMultiple')
->will($this
->returnValueMap(array(
array(
array(),
array(),
),
array(
NULL,
$roles,
),
array(
array(
'anonymous',
),
array(
$roles['anonymous'],
),
),
array(
array(
'anonymous',
'role_one',
),
array(
$roles['role_one'],
),
),
array(
array(
'anonymous',
'role_two',
),
array(
$roles['role_two'],
),
),
array(
array(
'anonymous',
'role_one',
'role_two',
),
array(
$roles['role_one'],
$roles['role_two'],
),
),
)));
$entity_manager = $this
->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$entity_manager
->expects($this
->any())
->method('getStorage')
->with($this
->equalTo('user_role'))
->will($this
->returnValue($role_storage));
$container = new ContainerBuilder();
$container
->set('entity.manager', $entity_manager);
\Drupal::setContainer($container);
$this->users['user_one'] = $this
->createUserSession(array(
'role_one',
));
$this->users['user_two'] = $this
->createUserSession(array(
'role_one',
'role_two',
));
$this->users['user_three'] = $this
->createUserSession(array(
'role_two',
), TRUE);
$this->users['user_last'] = $this
->createUserSession();
}