protected function GroupLevelAccessTest::setUp in Organic groups 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Access/ GroupLevelAccessTest.php, line 88
Class
- GroupLevelAccessTest
- Tests user access to group level entity operations and permissions.
Namespace
Drupal\Tests\og\Kernel\AccessCode
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'og',
]);
$this
->installEntitySchema('og_membership');
$this
->installEntitySchema('user');
$this
->installEntitySchema('entity_test');
$this
->installSchema('system', 'sequences');
$this->ogAccess = $this->container
->get('og.access');
// Declare the test entity as being a group.
$this->groupBundle = mb_strtolower($this
->randomMachineName());
Og::groupTypeManager()
->addGroup('entity_test', $this->groupBundle);
// Create users, and make sure user ID 1 isn't used.
User::create([
'name' => $this
->randomString(),
])
->save();
// Create a user that represents the group owner.
$this->ownerUser = User::create([
'name' => $this
->randomString(),
]);
$this->ownerUser
->save();
// Create a group and associate with the group owner.
$this->group = EntityTest::create([
'type' => $this->groupBundle,
'name' => $this
->randomString(),
'user_id' => $this->ownerUser
->id(),
]);
$this->group
->save();
// Create a non-member.
$this->nonMemberUser = User::create([
'name' => $this
->randomString(),
]);
$this->nonMemberUser
->save();
// Create an administrator user using the role that is created automatically
// when the group is created.
// @see \Drupal\og\EventSubscriber\OgEventSubscriber::provideDefaultRoles()
$admin_role = OgRole::loadByGroupAndName($this->group, OgRoleInterface::ADMINISTRATOR);
$this->adminUser = $this
->createUserWithOgRole($admin_role);
// Create another administrator role and assign it to a second test user.
// This is a supported use case: it is possible to have multiple
// administration roles.
/** @var \Drupal\og\OgRoleInterface $alternative_admin_role */
$alternative_admin_role = $this
->createOgRole([], TRUE);
$this->alternativeAdminUser = $this
->createUserWithOgRole($alternative_admin_role);
}