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 314
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() {
  $vocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => 'Test vocabulary',
    'machine_name' => 'test',
    'langcode' => LANGUAGE_NOT_SPECIFIED,
    'description' => NULL,
    'module' => 'entity_crud_hook_test',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  taxonomy_vocabulary_save($vocabulary);
  $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->vid);
  $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';
  taxonomy_vocabulary_save($vocabulary);
  $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();
  taxonomy_vocabulary_delete($vocabulary->vid);
  $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',
  ));
}