Tests rollback from failed insert in EntityNG.
function testEntityNGRollback() {
// Create a block.
try {
$entity = entity_create('entity_test', array(
'name' => 'fail_insert',
))
->save();
$this
->fail('Expected exception has not been thrown.');
} catch (\Exception $e) {
$this
->pass('Expected exception has been thrown.');
}
if (Database::getConnection()
->supportsTransactions()) {
// Check that the block does not exist in the database.
$ids = \Drupal::entityQuery('entity_test')
->condition('name', 'fail_insert')
->execute();
$this
->assertTrue(empty($ids), 'Transactions supported, and entity not found in database.');
}
else {
// Check that the block exists in the database.
$ids = \Drupal::entityQuery('entity_test')
->condition('name', 'fail_insert')
->execute();
$this
->assertFalse(empty($ids), 'Transactions not supported, and entity found in database.');
}
}