protected function EnforcedIntegrityTest::assertDeleteThrowsException in Entity Reference Integrity 8
Assert that deleting an entity throws an exception.
1 call to EnforcedIntegrityTest::assertDeleteThrowsException()
- EnforcedIntegrityTest::assertEntityDeleteProtected in modules/
entity_reference_integrity_enforce/ tests/ src/ Functional/ EnforcedIntegrityTest.php - Check that the delete form of an entity is protected.
File
- modules/
entity_reference_integrity_enforce/ tests/ src/ Functional/ EnforcedIntegrityTest.php, line 104
Class
- EnforcedIntegrityTest
- Test enforcing referential integrity.
Namespace
Drupal\Tests\entity_reference_integrity_enforce\FunctionalCode
protected function assertDeleteThrowsException(EntityInterface $entity, $message) {
try {
$entity
->delete();
} catch (\Exception $e) {
// SqlContentEntityStorage catches exceptions to rollback the transaction
// and throws its own exception.
if ($e instanceof EntityStorageException) {
$this
->assertInstanceOf(ProtectedEntityException::class, $e
->getPrevious());
$this
->assertEquals($message, $e
->getPrevious()
->getMessage());
}
else {
$this
->assertInstanceOf(ProtectedEntityException::class, $e);
$this
->assertEquals($message, $e
->getMessage());
}
return;
}
$this
->fail('An exception was not thrown when attempting to delete a protected entity.');
}