public function EntityQueryAlterTest::testMemberViewOwnAccess in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/EntityQueryAlterTest.php \Drupal\Tests\group\Kernel\EntityQueryAlterTest::testMemberViewOwnAccess()
Tests the viewing of own entities for members.
File
- tests/
src/ Kernel/ EntityQueryAlterTest.php, line 196
Class
- EntityQueryAlterTest
- Tests that Group properly checks access for grouped entities.
Namespace
Drupal\Tests\group\KernelCode
public function testMemberViewOwnAccess() {
$account = $this
->createUser([], [
'administer entity_test_with_owner content',
]);
$entity_1 = $this
->createTestEntity();
$entity_2 = $this
->createTestEntity();
$entity_3 = $this
->createTestEntity([
'uid' => $account
->id(),
]);
$this->groupTypeA
->getMemberRole()
->grantPermission('view own entity_test_as_content entity')
->save();
$this->groupTypeB
->getMemberRole()
->grantPermission('view own 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(),
], 'Members can see their own test entities.');
$this
->setCurrentUser($account);
$this
->assertQueryAccessResult([
$entity_2
->id(),
$entity_3
->id(),
], 'Members can see their own test entities.');
$this
->setCurrentUser($this
->createUser());
$this
->assertQueryAccessResult([
$entity_2
->id(),
], 'Only the ungrouped test entity shows up.');
}