public function EntityCrudHookTest::testTaxonomyVocabularyHooks

Tests hook invocations for CRUD operations on taxonomy vocabularies.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php, line 409
Definition of Drupal\system\Tests\Entity\EntityCrudHookTest.

Class

EntityCrudHookTest
Tests invocation of hooks when performing an action.

Namespace

Drupal\system\Tests\Entity

Code

public function testTaxonomyVocabularyHooks() {
  $this
    ->installSchema('taxonomy', array(
    'taxonomy_term_data',
    'taxonomy_term_hierarchy',
  ));
  $vocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => 'Test vocabulary',
    'vid' => 'test',
    'langcode' => Language::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',
  ));
  $_SESSION['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',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $vocabulary = taxonomy_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',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $vocabulary->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',
  ));
  $_SESSION['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',
  ));
}