You are here

public function EntityCrudHookTest::testTaxonomyVocabularyHooks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityCrudHookTest.php \Drupal\system\Tests\Entity\EntityCrudHookTest::testTaxonomyVocabularyHooks()

Tests hook invocations for CRUD operations on taxonomy vocabularies.

File

core/modules/system/src/Tests/Entity/EntityCrudHookTest.php, line 425
Contains \Drupal\system\Tests\Entity\EntityCrudHookTest.

Class

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

Namespace

Drupal\system\Tests\Entity

Code

public function testTaxonomyVocabularyHooks() {
  $this
    ->installEntitySchema('taxonomy_term');
  $vocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => 'Test vocabulary',
    'vid' => 'test',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'description' => NULL,
    'module' => 'entity_crud_hook_test',
  ));
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_taxonomy_vocabulary_create called',
    'entity_crud_hook_test_entity_create called for type taxonomy_vocabulary',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $vocabulary
    ->save();
  $this
    ->assertHookMessageOrder(array(
    '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'] = array();
  $vocabulary = Vocabulary::load($vocabulary
    ->id());
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type taxonomy_vocabulary',
    'entity_crud_hook_test_taxonomy_vocabulary_load called',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $vocabulary
    ->set('name', 'New name');
  $vocabulary
    ->save();
  $this
    ->assertHookMessageOrder(array(
    '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'] = array();
  $vocabulary
    ->delete();
  $this
    ->assertHookMessageOrder(array(
    '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',
  ));
}