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