public function GroupQueryAccessHandlerTest::testOnlyGroupViewAccess in Group 2.0.x
Same name and namespace in other branches
- 8 tests/src/Kernel/GroupQueryAccessHandlerTest.php \Drupal\Tests\group\Kernel\GroupQueryAccessHandlerTest::testOnlyGroupViewAccess()
Tests the conditions for people with view access in just the group scope.
@covers ::getConditions
File
- tests/
src/ Kernel/ GroupQueryAccessHandlerTest.php, line 156
Class
- GroupQueryAccessHandlerTest
- Tests the behavior of group query access handler.
Namespace
Drupal\Tests\group\KernelCode
public function testOnlyGroupViewAccess() {
$user = $this
->getCurrentUser();
$group = $this
->createGroup();
$group
->addMember($user);
// Remove the 'view group' permission from the default group type's outsider
// role so the user only has the permission for the groups they are in.
$this->entityTypeManager
->getStorage('group_role')
->load('default-outsider')
->revokePermission('view group')
->save();
$conditions = $this->handler
->getConditions('view', $user);
$expected_conditions = [
(new ConditionGroup())
->addCondition('status', 1)
->addCondition('id', [
$group
->id(),
]),
];
$this
->assertEquals(1, $conditions
->count());
$this
->assertEquals($expected_conditions, $conditions
->getConditions());
$this
->assertEqualsCanonicalizing([
'user.group_permissions',
'user.permissions',
], $conditions
->getCacheContexts());
$this
->assertFalse($conditions
->isAlwaysFalse());
foreach ([
'update',
'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());
}
}