You are here

public function EntityCrudHookTest::testTaxonomyVocabularyHooks in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testTaxonomyVocabularyHooks()

Tests hook invocations for CRUD operations on taxonomy vocabularies.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php, line 430

Class

EntityCrudHookTest
Tests the invocation of hooks when creating, inserting, loading, updating or deleting an entity.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testTaxonomyVocabularyHooks() {
  $this
    ->installEntitySchema('taxonomy_term');
  $vocabulary = Vocabulary::create([
    'name' => 'Test vocabulary',
    'vid' => 'test',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'description' => NULL,
    'module' => 'entity_crud_hook_test',
  ]);
  $this
    ->assertHookMessageOrder([
    'entity_crud_hook_test_taxonomy_vocabulary_create called',
    'entity_crud_hook_test_entity_create called for type taxonomy_vocabulary',
  ]);
  $GLOBALS['entity_crud_hook_test'] = [];
  $vocabulary
    ->save();
  $this
    ->assertHookMessageOrder([
    'entity_crud_hook_test_taxonomy_vocabulary_presave called',
    'entity_crud_hook_test_entity_presave called for type taxonomy_vocabulary',
    'entity_crud_hook_test_taxonomy_vocabulary_insert called',
    'entity_crud_hook_test_entity_insert called for type taxonomy_vocabulary',
  ]);
  $GLOBALS['entity_crud_hook_test'] = [];
  $vocabulary = Vocabulary::load($vocabulary
    ->id());
  $this
    ->assertHookMessageOrder([
    'entity_crud_hook_test_entity_load called for type taxonomy_vocabulary',
    'entity_crud_hook_test_taxonomy_vocabulary_load called',
  ]);
  $GLOBALS['entity_crud_hook_test'] = [];
  $vocabulary
    ->set('name', 'New name');
  $vocabulary
    ->save();
  $this
    ->assertHookMessageOrder([
    'entity_crud_hook_test_taxonomy_vocabulary_presave called',
    'entity_crud_hook_test_entity_presave called for type taxonomy_vocabulary',
    'entity_crud_hook_test_taxonomy_vocabulary_update called',
    'entity_crud_hook_test_entity_update called for type taxonomy_vocabulary',
  ]);
  $GLOBALS['entity_crud_hook_test'] = [];
  $vocabulary
    ->delete();
  $this
    ->assertHookMessageOrder([
    'entity_crud_hook_test_taxonomy_vocabulary_predelete called',
    'entity_crud_hook_test_entity_predelete called for type taxonomy_vocabulary',
    'entity_crud_hook_test_taxonomy_vocabulary_delete called',
    'entity_crud_hook_test_entity_delete called for type taxonomy_vocabulary',
  ]);
}