function EntityCrudHookTestCase::testNodeHooks

Tests hook invocations for CRUD operations on nodes.

File

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

Class

EntityCrudHookTestCase
Tests invocation of hooks when performing an action.

Code

public function testNodeHooks() {
    $node = (object) array(
        'uid' => 1,
        'type' => 'article',
        'title' => 'Test node',
        'status' => 1,
        'comment' => 2,
        'promote' => 0,
        'sticky' => 0,
        'language' => LANGUAGE_NONE,
        'created' => REQUEST_TIME,
        'changed' => REQUEST_TIME,
    );
    $_SESSION['entity_crud_hook_test'] = array();
    node_save($node);
    $this->assertHookMessage('entity_crud_hook_test_entity_presave called for type node');
    $this->assertHookMessage('entity_crud_hook_test_node_presave called');
    $this->assertHookMessage('entity_crud_hook_test_entity_insert called for type node');
    $this->assertHookMessage('entity_crud_hook_test_node_insert called');
    $_SESSION['entity_crud_hook_test'] = array();
    $node = node_load($node->nid);
    $this->assertHookMessage('entity_crud_hook_test_entity_load called for type node');
    $this->assertHookMessage('entity_crud_hook_test_node_load called');
    $_SESSION['entity_crud_hook_test'] = array();
    $node->title = 'New title';
    node_save($node);
    $this->assertHookMessage('entity_crud_hook_test_entity_presave called for type node');
    $this->assertHookMessage('entity_crud_hook_test_node_presave called');
    $this->assertHookMessage('entity_crud_hook_test_entity_update called for type node');
    $this->assertHookMessage('entity_crud_hook_test_node_update called');
    $_SESSION['entity_crud_hook_test'] = array();
    node_delete($node->nid);
    $this->assertHookMessage('entity_crud_hook_test_entity_delete called for type node');
    $this->assertHookMessage('entity_crud_hook_test_node_delete called');
}

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