function EntityCrudHookTest::testTaxonomyTermHooks
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testTaxonomyTermHooks()
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testTaxonomyTermHooks()
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testTaxonomyTermHooks()
Tests hook invocations for CRUD operations on taxonomy terms.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityCrudHookTest.php, line 369
Class
- EntityCrudHookTest
- Tests entity CRUD via hooks.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testTaxonomyTermHooks() : void {
$this->installEntitySchema('taxonomy_term');
$vocabulary = Vocabulary::create([
'name' => 'Test vocabulary',
'vid' => 'test',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'description' => NULL,
'module' => 'entity_crud_hook_test',
]);
$vocabulary->save();
$GLOBALS['entity_crud_hook_test'] = [];
$term = Term::create([
'vid' => $vocabulary->id(),
'name' => 'Test term',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'description' => NULL,
'format' => 1,
]);
$this->assertHookMessageOrder([
'entity_crud_hook_test_taxonomy_term_create called',
'entity_crud_hook_test_entity_create called for type taxonomy_term',
]);
$GLOBALS['entity_crud_hook_test'] = [];
$term->save();
$this->assertHookMessageOrder([
'entity_crud_hook_test_taxonomy_term_presave called',
'entity_crud_hook_test_entity_presave called for type taxonomy_term',
'entity_crud_hook_test_taxonomy_term_insert called',
'entity_crud_hook_test_entity_insert called for type taxonomy_term',
]);
$GLOBALS['entity_crud_hook_test'] = [];
$term = Term::load($term->id());
$this->assertHookMessageOrder([
'entity_crud_hook_test_entity_load called for type taxonomy_term',
'entity_crud_hook_test_taxonomy_term_load called',
]);
$GLOBALS['entity_crud_hook_test'] = [];
$term->setName('New name');
$term->save();
$this->assertHookMessageOrder([
'entity_crud_hook_test_taxonomy_term_presave called',
'entity_crud_hook_test_entity_presave called for type taxonomy_term',
'entity_crud_hook_test_taxonomy_term_update called',
'entity_crud_hook_test_entity_update called for type taxonomy_term',
]);
$GLOBALS['entity_crud_hook_test'] = [];
$term->delete();
$this->assertHookMessageOrder([
'entity_crud_hook_test_taxonomy_term_predelete called',
'entity_crud_hook_test_entity_predelete called for type taxonomy_term',
'entity_crud_hook_test_taxonomy_term_delete called',
'entity_crud_hook_test_entity_delete called for type taxonomy_term',
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.