public function DeleteActionTest::testDeleteAction in Entity Reference Integrity 8
Test that delete action denies access to protected entities.
File
- modules/
entity_reference_integrity_enforce/ tests/ src/ Kernel/ DeleteActionTest.php, line 125
Class
- DeleteActionTest
- Test behavior of the DeleteAction plugin.
Namespace
Drupal\Tests\entity_reference_integrity_enforce\KernelCode
public function testDeleteAction() {
// Ensure the DeleteAction exists and is using the extended class.
$actions = $this->actionManager
->getDefinitions();
$this
->assertArrayHasKey('entity:delete_action:node', $actions);
$this
->assertEquals(DeleteAction::class, $actions['entity:delete_action:node']['class']);
$action = $this->actionManager
->createInstance('entity:delete_action:node');
// The referencedNode has dependents, the action should deny access.
$this
->assertTrue($this->dependencyManager
->hasDependents($this->referencedNode));
$this
->assertFalse($action
->access($this->referencedNode, $this->testUser));
// Unset the node reference.
$this->testNode->test_reference_field = [];
$this->testNode
->save();
// The referencedNode has no dependents, the action should allow access.
$this
->assertFalse($this->dependencyManager
->hasDependents($this->referencedNode));
$this
->assertTrue($action
->access($this->referencedNode, $this->testUser));
}