function EndOfTransactionQueriesTest::entityTestInsert
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php \Drupal\KernelTests\Core\Cache\EndOfTransactionQueriesTest::entityTestInsert()
Implements hook_ENTITY_TYPE_insert().
Attributes
#[Hook('entity_test_insert')]
See also
\Drupal\KernelTests\Core\Cache\EndOfTransactionQueriesTest::testEntitySave()
\Drupal\KernelTests\Core\Cache\EndOfTransactionQueriesTest::testEntitySaveRollback()
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Cache/ EndOfTransactionQueriesTest.php, line 171
Class
- EndOfTransactionQueriesTest
- Tests delaying of cache tag invalidation queries to the end of transactions.
Namespace
Drupal\KernelTests\Core\CacheCode
public function entityTestInsert(EntityTest $entity) : void {
if (\Drupal::state()->get('delay_cache_tags_invalidation_exception')) {
throw new \Exception('Abort entity save to trigger transaction rollback.');
}
// Read the pre-transaction cache writes.
// @see \Drupal\KernelTests\Core\Cache\EndOfTransactionQueriesTest::testEntitySave()
\Drupal::state()->set('delay_cache_tags_invalidation_entity_test_insert__pre-transaction_foobar', \Drupal::cache()->get('test_cache_pre-transaction_foobar'));
\Drupal::state()->set('delay_cache_tags_invalidation_entity_test_insert__pre-transaction_entity_test_list', \Drupal::cache()->get('test_cache_pre-transaction_entity_test_list'));
// Write during the transaction.
\Drupal::cache()->set('delay_cache_tags_invalidation_entity_test_insert__during_transaction_foobar', 'something', Cache::PERMANENT, [
'foobar',
]);
\Drupal::cache()->set('delay_cache_tags_invalidation_entity_test_insert__during_transaction_entity_test_list', 'something', Cache::PERMANENT, [
'entity_test_list',
]);
// Trigger a nested entity save and hence a nested transaction.
User::create([
'name' => 'john doe',
'status' => 1,
])->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.