You are here

public function EntityCrudHookTestCase::testUserHooks in Drupal 7

Tests hook invocations for CRUD operations on users.

File

modules/simpletest/tests/entity_crud_hook_test.test, line 299
CRUD hook tests for the Entity CRUD API.

Class

EntityCrudHookTestCase
Tests invocation of hooks when performing an action.

Code

public function testUserHooks() {
  $edit = array(
    'name' => 'Test user',
    'mail' => 'test@example.com',
    'created' => REQUEST_TIME,
    'status' => 1,
    'language' => 'en',
  );
  $account = (object) $edit;
  $_SESSION['entity_crud_hook_test'] = array();
  $account = user_save($account, $edit);
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_presave called for type user');
  $this
    ->assertHookMessage('entity_crud_hook_test_user_presave called');
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_insert called for type user');
  $this
    ->assertHookMessage('entity_crud_hook_test_user_insert called');
  $_SESSION['entity_crud_hook_test'] = array();
  $account = user_load($account->uid);
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_load called for type user');
  $this
    ->assertHookMessage('entity_crud_hook_test_user_load called');
  $_SESSION['entity_crud_hook_test'] = array();
  $edit['name'] = 'New name';
  $account = user_save($account, $edit);
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_presave called for type user');
  $this
    ->assertHookMessage('entity_crud_hook_test_user_presave called');
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_update called for type user');
  $this
    ->assertHookMessage('entity_crud_hook_test_user_update called');
  $_SESSION['entity_crud_hook_test'] = array();
  user_delete($account->uid);
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_delete called for type user');
  $this
    ->assertHookMessage('entity_crud_hook_test_user_delete called');
}