Tests hook invocations for CRUD operations on taxonomy terms.
public function testTaxonomyTermHooks() {
$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',
));
$vocabulary
->save();
$_SESSION['entity_crud_hook_test'] = array();
$term = entity_create('taxonomy_term', array(
'vid' => $vocabulary
->id(),
'name' => 'Test term',
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
'description' => NULL,
'format' => 1,
));
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_taxonomy_term_create called',
'entity_crud_hook_test_entity_create called for type taxonomy_term',
));
$_SESSION['entity_crud_hook_test'] = array();
$term
->save();
$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
->id());
$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';
$term
->save();
$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();
$term
->delete();
$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',
));
}