function EntityCrudHookTest::testTaxonomyVocabularyHooks

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testTaxonomyVocabularyHooks()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::testTaxonomyVocabularyHooks()
  3. 11.x 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 438

Class

EntityCrudHookTest
Tests entity CRUD via hooks.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testTaxonomyVocabularyHooks() : 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',
  ]);
  $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',
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.