public function EntityAccessComplexTest::testNonMemberViewOwnPublishedAccess in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/EntityAccessComplexTest.php \Drupal\Tests\group\Kernel\EntityAccessComplexTest::testNonMemberViewOwnPublishedAccess()
Tests the viewing of own published grouped entities for non-members.
File
- tests/
src/ Kernel/ EntityAccessComplexTest.php, line 348
Class
- EntityAccessComplexTest
- Tests that Group properly checks access for "complex" grouped entities.
Namespace
Drupal\Tests\group\KernelCode
public function testNonMemberViewOwnPublishedAccess() {
$account = $this
->createUser([], $this->permissions);
$node_1 = $this
->createNode([
'type' => 'page',
]);
$node_2 = $this
->createNode([
'type' => 'page',
'uid' => $account
->id(),
]);
$node_3 = $this
->createNode([
'type' => 'page',
]);
// Sanity check: Verify that we don't touch unpublished nodes.
$node_4 = $this
->createNode([
'type' => 'page',
'status' => 0,
]);
$group_a = $this
->createGroup([
'type' => $this->groupTypeA
->id(),
]);
$group_a
->addContent($node_1, 'node_as_content:page');
$group_a
->addContent($node_4, 'node_as_content:page');
$group_a
->addMember($account);
$group_b = $this
->createGroup([
'type' => $this->groupTypeB
->id(),
]);
$group_b
->addContent($node_2, 'node_as_content:page');
$group_b
->addMember($account);
$this
->assertFalse($this->accessControlHandler
->access($node_1, 'view'), 'Non-members cannot see their own published grouped nodes without permission.');
$this
->assertFalse($this->accessControlHandler
->access($node_2, 'view'), 'Non-members cannot see published grouped nodes they do not own.');
$this
->assertTrue($this->accessControlHandler
->access($node_3, 'view'), 'The published node can be viewed.');
$this
->assertFalse($this->accessControlHandler
->access($node_4, 'view'), 'The unpublished grouped node cannot be viewed.');
$this->groupTypeA
->getOutsiderRole()
->grantPermission('view own node_as_content:page entity')
->save();
$this->groupTypeB
->getOutsiderRole()
->grantPermission('view own node_as_content:page entity')
->save();
$this->accessControlHandler
->resetCache();
$this
->assertTrue($this->accessControlHandler
->access($node_1, 'view'), 'Non-members can see their own published grouped nodes.');
$this
->assertFalse($this->accessControlHandler
->access($node_2, 'view'), 'Non-members cannot see published grouped nodes they do not own.');
$this
->assertTrue($this->accessControlHandler
->access($node_3, 'view'), 'The published node can be viewed.');
$this
->assertFalse($this->accessControlHandler
->access($node_4, 'view'), 'The unpublished grouped node cannot be viewed.');
$this
->setCurrentUser($this
->createUser([], $this->permissions));
$this
->assertFalse($this->accessControlHandler
->access($node_1, 'view'), 'Non-members cannot see published grouped nodes they do not own.');
$this
->assertFalse($this->accessControlHandler
->access($node_2, 'view'), 'Non-members cannot see published grouped nodes they do not own.');
$this
->assertTrue($this->accessControlHandler
->access($node_3, 'view'), 'The published node can be viewed.');
$this
->assertFalse($this->accessControlHandler
->access($node_4, 'view'), 'The unpublished grouped node cannot be viewed.');
$this
->setCurrentUser($account);
$this
->assertFalse($this->accessControlHandler
->access($node_1, 'view'), 'Members cannot see published grouped nodes.');
$this
->assertFalse($this->accessControlHandler
->access($node_2, 'view'), 'Members cannot see published grouped nodes.');
$this
->assertTrue($this->accessControlHandler
->access($node_3, 'view'), 'The published node can be viewed.');
$this
->assertFalse($this->accessControlHandler
->access($node_4, 'view'), 'The unpublished grouped node cannot be viewed.');
}