public function EntityAccessComplexTest::testNonMemberUpdateAnyAccess in Group 2.0.x
Same name and namespace in other branches
- 8 tests/src/Kernel/EntityAccessComplexTest.php \Drupal\Tests\group\Kernel\EntityAccessComplexTest::testNonMemberUpdateAnyAccess()
Tests the updating of any grouped entities for non-members.
File
- tests/
src/ Kernel/ EntityAccessComplexTest.php, line 665
Class
- EntityAccessComplexTest
- Tests that Group properly checks access for "complex" grouped entities.
Namespace
Drupal\Tests\group\KernelCode
public function testNonMemberUpdateAnyAccess() {
$account = $this
->createUser([], $this->permissions);
$node_1 = $this
->createNode([
'type' => 'page',
]);
$node_2 = $this
->createNode([
'type' => 'page',
'status' => 0,
]);
$node_3 = $this
->createNode([
'type' => 'page',
]);
$this->groupTypeA
->getOutsiderRole()
->grantPermission('update any node_as_content:page entity')
->save();
$this->groupTypeB
->getOutsiderRole()
->grantPermission('update any node_as_content:page entity')
->save();
$group_a = $this
->createGroup([
'type' => $this->groupTypeA
->id(),
]);
$group_a
->addContent($node_1, '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
->assertTrue($this->accessControlHandler
->access($node_1, 'update'), 'Non-members can update any published grouped nodes.');
$this
->assertTrue($this->accessControlHandler
->access($node_2, 'update'), 'Non-members can update any unpublished grouped nodes.');
$this
->assertTrue($this->accessControlHandler
->access($node_3, 'update'), 'The ungrouped node can be updated.');
$this
->setCurrentUser($this
->createUser([], $this->permissions));
$this
->assertTrue($this->accessControlHandler
->access($node_1, 'update'), 'Non-members can update any published grouped nodes.');
$this
->assertTrue($this->accessControlHandler
->access($node_2, 'update'), 'Non-members can update any unpublished grouped nodes.');
$this
->assertTrue($this->accessControlHandler
->access($node_3, 'update'), 'The ungrouped node can be updated.');
$this
->setCurrentUser($account);
$this
->assertFalse($this->accessControlHandler
->access($node_1, 'update'), 'Members cannot update published grouped nodes.');
$this
->assertFalse($this->accessControlHandler
->access($node_2, 'update'), 'Members cannot update unpublished grouped nodes.');
$this
->assertTrue($this->accessControlHandler
->access($node_3, 'update'), 'The ungrouped node can be updated.');
}