function EntityCrudHookTest::testEntityRollback
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testEntityRollback()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testEntityRollback()
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testEntityRollback()
Tests rollback from failed entity save.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityCrudHookTest.php, line 553
Class
- EntityCrudHookTest
- Tests entity CRUD via hooks.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testEntityRollback() {
// Create a block.
try {
EntityTest::create([
'name' => 'fail_insert',
])->save();
$this->fail('Expected exception has not been thrown.');
} catch (\Exception $e) {
// Expected exception; just continue testing.
}
// Check that the block does not exist in the database.
$ids = \Drupal::entityQuery('entity_test')->accessCheck(FALSE)
->condition('name', 'fail_insert')
->execute();
$this->assertEmpty($ids);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.