public function GroupQueryAccessHandlerTest::testCombinedViewAccess in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/GroupQueryAccessHandlerTest.php \Drupal\Tests\group\Kernel\GroupQueryAccessHandlerTest::testCombinedViewAccess()
Tests the conditions for people with view access in both scopes.
@covers ::getConditions
File
- tests/
src/ Kernel/ GroupQueryAccessHandlerTest.php, line 274
Class
- GroupQueryAccessHandlerTest
- Tests the behavior of group query access handler.
Namespace
Drupal\Tests\group\KernelCode
public function testCombinedViewAccess() {
$user = $this
->getCurrentUser();
$group = $this
->createGroup();
$group
->addMember($user);
$conditions = $this->handler
->getConditions('view', $user);
$expected_conditions = [
(new ConditionGroup('AND'))
->addCondition('status', 1)
->addCondition((new ConditionGroup('OR'))
->addCondition((new ConditionGroup())
->addCondition('type', [
'default',
])
->addCondition('id', [
$group
->id(),
], 'NOT IN'))
->addCondition('id', [
$group
->id(),
])),
];
$this
->assertEquals(1, $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 ([
'update',
'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());
}
}