protected function UserRoleConditionTest::setUp in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/tests/src/Kernel/Condition/UserRoleConditionTest.php \Drupal\Tests\user\Kernel\Condition\UserRoleConditionTest::setUp()
- 10 core/modules/user/tests/src/Kernel/Condition/UserRoleConditionTest.php \Drupal\Tests\user\Kernel\Condition\UserRoleConditionTest::setUp()
Overrides KernelTestBase::setUp
File
- core/
modules/ user/ tests/ src/ Kernel/ Condition/ UserRoleConditionTest.php, line 56
Class
- UserRoleConditionTest
- Tests the user role condition.
Namespace
Drupal\Tests\user\Kernel\ConditionCode
protected function setUp() {
parent::setUp();
$this
->installSchema('system', 'sequences');
$this
->installEntitySchema('user');
$this->manager = $this->container
->get('plugin.manager.condition');
// Set up the authenticated and anonymous roles.
Role::create([
'id' => RoleInterface::ANONYMOUS_ID,
'label' => 'Anonymous user',
])
->save();
Role::create([
'id' => RoleInterface::AUTHENTICATED_ID,
'label' => 'Authenticated user',
])
->save();
// Create new role.
$rid = strtolower($this
->randomMachineName(8));
$label = $this
->randomString(8);
$role = Role::create([
'id' => $rid,
'label' => $label,
]);
$role
->save();
$this->role = $role;
// Setup an anonymous user for our tests.
$this->anonymous = User::create([
'name' => '',
'uid' => 0,
]);
$this->anonymous
->save();
// Loading the anonymous user adds the correct role.
$this->anonymous = User::load($this->anonymous
->id());
// Setup an authenticated user for our tests.
$this->authenticated = User::create([
'name' => $this
->randomMachineName(),
]);
$this->authenticated
->save();
// Add the custom role.
$this->authenticated
->addRole($this->role
->id());
}