function EntityCrudHookTestCase::testTaxonomyTermHooks

Tests hook invocations for CRUD operations on taxonomy terms.

File

modules/simpletest/tests/entity_crud_hook_test.test, line 211

Class

EntityCrudHookTestCase
Tests invocation of hooks when performing an action.

Code

public function testTaxonomyTermHooks() {
    $vocabulary = (object) array(
        'name' => 'Test vocabulary',
        'machine_name' => 'test',
        'description' => NULL,
        'module' => 'entity_crud_hook_test',
    );
    taxonomy_vocabulary_save($vocabulary);
    $term = (object) array(
        'vid' => $vocabulary->vid,
        'name' => 'Test term',
        'description' => NULL,
        'format' => 1,
    );
    $_SESSION['entity_crud_hook_test'] = array();
    taxonomy_term_save($term);
    $this->assertHookMessage('entity_crud_hook_test_entity_presave called for type taxonomy_term');
    $this->assertHookMessage('entity_crud_hook_test_taxonomy_term_presave called');
    $this->assertHookMessage('entity_crud_hook_test_entity_insert called for type taxonomy_term');
    $this->assertHookMessage('entity_crud_hook_test_taxonomy_term_insert called');
    $_SESSION['entity_crud_hook_test'] = array();
    $term = taxonomy_term_load($term->tid);
    $this->assertHookMessage('entity_crud_hook_test_entity_load called for type taxonomy_term');
    $this->assertHookMessage('entity_crud_hook_test_taxonomy_term_load called');
    $_SESSION['entity_crud_hook_test'] = array();
    $term->name = 'New name';
    taxonomy_term_save($term);
    $this->assertHookMessage('entity_crud_hook_test_entity_presave called for type taxonomy_term');
    $this->assertHookMessage('entity_crud_hook_test_taxonomy_term_presave called');
    $this->assertHookMessage('entity_crud_hook_test_entity_update called for type taxonomy_term');
    $this->assertHookMessage('entity_crud_hook_test_taxonomy_term_update called');
    $_SESSION['entity_crud_hook_test'] = array();
    taxonomy_term_delete($term->tid);
    $this->assertHookMessage('entity_crud_hook_test_entity_delete called for type taxonomy_term');
    $this->assertHookMessage('entity_crud_hook_test_taxonomy_term_delete called');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.