1 entity_crud_hook_test.test public EntityCrudHookTestCase::testTaxonomyTermHooks()

Tests hook invocations for CRUD operations on taxonomy terms.

File

core/modules/entity/tests/entity_crud_hook_test.test, line 239
CRUD hook tests for the Entity CRUD API.

Class

EntityCrudHookTestCase
Tests invocation of hooks when performing an action.

Code

public function testTaxonomyTermHooks() {
  $vocabulary = new TaxonomyVocabulary(array(
    'name' => 'Test vocabulary',
    'machine_name' => 'test',
    'description' => NULL,
    'module' => 'entity_crud_hook_test',
  ));
  taxonomy_vocabulary_save($vocabulary);

  $term = entity_create('taxonomy_term', array(
    'name' => 'Test term',
    'vocabulary' => $vocabulary->machine_name,
    'description' => NULL,
    'format' => 1,
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  taxonomy_term_save($term);

  $this->assertHookMessageOrder(array(
    'entity_crud_hook_test_taxonomy_term_presave called',
    'entity_crud_hook_test_entity_presave called for type taxonomy_term',
    'entity_crud_hook_test_taxonomy_term_insert called',
    'entity_crud_hook_test_entity_insert called for type taxonomy_term',
  ));

  $_SESSION['entity_crud_hook_test'] = array();
  $term = taxonomy_term_load($term->tid);

  $this->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type taxonomy_term',
    'entity_crud_hook_test_taxonomy_term_load called',
  ));

  $_SESSION['entity_crud_hook_test'] = array();
  $term->name = 'New name';
  taxonomy_term_save($term);

  $this->assertHookMessageOrder(array(
    'entity_crud_hook_test_taxonomy_term_presave called',
    'entity_crud_hook_test_entity_presave called for type taxonomy_term',
    'entity_crud_hook_test_taxonomy_term_update called',
    'entity_crud_hook_test_entity_update called for type taxonomy_term',
  ));

  $_SESSION['entity_crud_hook_test'] = array();
  taxonomy_term_delete($term->tid);

  $this->assertHookMessageOrder(array(
    'entity_crud_hook_test_taxonomy_term_predelete called',
    'entity_crud_hook_test_entity_predelete called for type taxonomy_term',
    'entity_crud_hook_test_taxonomy_term_delete called',
    'entity_crud_hook_test_entity_delete called for type taxonomy_term',
  ));
}