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