public function GroupContentQueryAccessHandlerTest::testOwnerGroupAccess in Group 2.0.x
Same name and namespace in other branches
- 8 tests/src/Kernel/GroupContentQueryAccessHandlerTest.php \Drupal\Tests\group\Kernel\GroupContentQueryAccessHandlerTest::testOwnerGroupAccess()
Tests the conditions for owner access in the group scope.
@covers ::getConditions
File
- tests/
src/ Kernel/ GroupContentQueryAccessHandlerTest.php, line 243
Class
- GroupContentQueryAccessHandlerTest
- Tests the behavior of group content query access handler.
Namespace
Drupal\Tests\group\KernelCode
public function testOwnerGroupAccess() {
$user = $this
->createUser();
$group = $this
->createGroup([
'type' => $this->groupType
->id(),
]);
$group
->addMember($user);
// Allow members to edit their own content.
$group_role = $this->groupType
->getMemberRole();
$group_role
->grantPermission('update own user_as_content relation')
->save();
$conditions = $this->handler
->getConditions('update', $user);
$expected_sub_condition = new ConditionGroup();
$expected_conditions = [
$expected_sub_condition
->addCondition('uid', $user
->id())
->addCondition('gid', [
$group
->id(),
]),
];
$this
->assertEquals(1, $conditions
->count());
$this
->assertEquals('OR', $conditions
->getConjunction());
$this
->assertEquals($expected_conditions, $conditions
->getConditions());
$this
->assertEqualsCanonicalizing([
'user',
'user.group_permissions',
'user.permissions',
], $conditions
->getCacheContexts());
$this
->assertFalse($conditions
->isAlwaysFalse());
foreach ([
'view',
'delete',
] as $operation) {
$conditions = $this->handler
->getConditions($operation, $user);
$this
->assertEquals(0, $conditions
->count());
$this
->assertEqualsCanonicalizing([
'user.group_permissions',
'user.permissions',
], $conditions
->getCacheContexts());
$this
->assertTrue($conditions
->isAlwaysFalse());
}
}