public function GroupRoleStorageTest::testLoadByUserAndGroup in Group 2.0.x
Same name and namespace in other branches
- 8 tests/src/Kernel/GroupRoleStorageTest.php \Drupal\Tests\group\Kernel\GroupRoleStorageTest::testLoadByUserAndGroup()
Tests the loading of group roles by user and group.
@covers ::loadByUserAndGroup
File
- tests/
src/ Kernel/ GroupRoleStorageTest.php, line 61
Class
- GroupRoleStorageTest
- Tests the behavior of group role storage handler.
Namespace
Drupal\Tests\group\KernelCode
public function testLoadByUserAndGroup() {
$this
->compareMemberRoles([], FALSE, 'User has no explicit group roles as they are not a member.');
$this
->compareMemberRoles([
'default-outsider',
], TRUE, 'User initially has implicit outsider role.');
// Grant the user a new site role and check the storage.
$this->entityTypeManager
->getStorage('user_role')
->create([
'id' => 'publisher',
])
->save();
$this->account
->addRole('publisher');
$this->account
->save();
$group_role_id = $this->groupRoleSynchronizer
->getGroupRoleId('default', 'publisher');
$this
->compareMemberRoles([], FALSE, 'User has no explicit group roles as they are not a member.');
$this
->compareMemberRoles([
$group_role_id,
'default-outsider',
], TRUE, 'User has implicit and synchronized outsider roles.');
// From this point on we test with the user as a member.
$this->group
->addMember($this->account);
$this
->compareMemberRoles([], FALSE, 'User still has no explicit group roles.');
$this
->compareMemberRoles([
'default-member',
], TRUE, 'User has implicit member role now that they have joined the group.');
// Grant the member a new group role and check the storage.
$this->storage
->create([
'id' => 'default-editor',
'label' => 'Default editor',
'weight' => 0,
'group_type' => 'default',
])
->save();
// @todo This displays a desperate need for addRole() and removeRole().
$membership = $this->group
->getMember($this->account)
->getGroupContent();
$membership->group_roles[] = 'default-editor';
$membership
->save();
$this
->compareMemberRoles([
'default-editor',
], FALSE, 'User has the editor group role.');
$this
->compareMemberRoles([
'default-editor',
'default-member',
], TRUE, 'User also has implicit member role.');
}