public function GroupContentQueryAccessHandlerTest::testGroupAccess in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/GroupContentQueryAccessHandlerTest.php \Drupal\Tests\group\Kernel\GroupContentQueryAccessHandlerTest::testGroupAccess()
Tests the conditions for people with access in just the group scope.
@covers ::getConditions
File
- tests/
src/ Kernel/ GroupContentQueryAccessHandlerTest.php, line 135
Class
- GroupContentQueryAccessHandlerTest
- Tests the behavior of group content query access handler.
Namespace
Drupal\Tests\group\KernelCode
public function testGroupAccess() {
$user = $this
->createUser();
$group = $this
->createGroup([
'type' => $this->groupType
->id(),
]);
$group
->addMember($user);
// Allow members to update any content.
$group_role = $this->groupType
->getMemberRole();
$group_role
->grantPermission('update any user_as_content content')
->save();
$conditions = $this->handler
->getConditions('update', $user);
$expected_conditions = [
new Condition('gid', [
$group
->id(),
]),
];
$this
->assertEquals(1, $conditions
->count());
$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());
}
}