public function GroupQueryAccessHandlerTest::testCombinedUpdateAccess in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/GroupQueryAccessHandlerTest.php \Drupal\Tests\group\Kernel\GroupQueryAccessHandlerTest::testCombinedUpdateAccess()
Tests the conditions for people with update access in both scopes.
@covers ::getConditions
File
- tests/
src/ Kernel/ GroupQueryAccessHandlerTest.php, line 312
Class
- GroupQueryAccessHandlerTest
- Tests the behavior of group query access handler.
Namespace
Drupal\Tests\group\KernelCode
public function testCombinedUpdateAccess() {
$user = $this
->getCurrentUser();
$group = $this
->createGroup();
$group
->addMember($user);
$this->entityTypeManager
->getStorage('group_role')
->load('default-member')
->grantPermission('edit group')
->revokePermission('view group')
->save();
$this->entityTypeManager
->getStorage('group_role')
->load('default-outsider')
->grantPermission('edit group')
->revokePermission('view group')
->save();
$conditions = $this->handler
->getConditions('update', $user);
$expected_conditions = [
(new ConditionGroup())
->addCondition('type', [
'default',
])
->addCondition('id', [
$group
->id(),
], 'NOT IN'),
new Condition('id', [
$group
->id(),
]),
];
$this
->assertEquals(2, $conditions
->count());
$this
->assertEquals('OR', $conditions
->getConjunction());
$this
->assertEquals($expected_conditions, $conditions
->getConditions());
$this
->assertEquals([
'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
->assertEquals([
'user.group_permissions',
'user.permissions',
], $conditions
->getCacheContexts());
$this
->assertTrue($conditions
->isAlwaysFalse());
}
}