public function EntityQueryAlterTest::testMemberViewAnyAccess in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/EntityQueryAlterTest.php \Drupal\Tests\group\Kernel\EntityQueryAlterTest::testMemberViewAnyAccess()
Tests the viewing of any entities for members.
File
- tests/
src/ Kernel/ EntityQueryAlterTest.php, line 136
Class
- EntityQueryAlterTest
- Tests that Group properly checks access for grouped entities.
Namespace
Drupal\Tests\group\KernelCode
public function testMemberViewAnyAccess() {
$account = $this
->createUser([], [
'administer entity_test_with_owner content',
]);
$entity_1 = $this
->createTestEntity();
$entity_2 = $this
->createTestEntity();
$entity_3 = $this
->createTestEntity();
$this->groupTypeA
->getMemberRole()
->grantPermission('view any entity_test_as_content entity')
->save();
$this->groupTypeB
->getMemberRole()
->grantPermission('view any entity_test_as_content entity')
->save();
$group_a = $this
->createGroup([
'type' => $this->groupTypeA
->id(),
]);
$group_a
->addContent($entity_1, 'entity_test_as_content');
$group_a
->addMember($this
->getCurrentUser());
$group_a
->addMember($account);
$group_b = $this
->createGroup([
'type' => $this->groupTypeB
->id(),
]);
$group_b
->addContent($entity_3, 'entity_test_as_content');
$group_b
->addMember($this
->getCurrentUser());
$group_b
->addMember($account);
$this
->assertQueryAccessResult([
$entity_1
->id(),
$entity_2
->id(),
$entity_3
->id(),
], 'Members can see any test entities.');
$this
->setCurrentUser($account);
$this
->assertQueryAccessResult([
$entity_1
->id(),
$entity_2
->id(),
$entity_3
->id(),
], 'Members can see any test entities.');
$this
->setCurrentUser($this
->createUser([], [
'administer entity_test_with_owner content',
]));
$this
->assertQueryAccessResult([
$entity_2
->id(),
], 'Only the ungrouped test entity shows up.');
}