1 entity_crud_hook_test.test public EntityCrudHookTestCase::testUserHooks()

Tests hook invocations for CRUD operations on users.

File

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

Class

EntityCrudHookTestCase
Tests invocation of hooks when performing an action.

Code

public function testUserHooks() {
  $account = entity_create('user', array(
    'name' => 'Test user',
    'mail' => 'test@example.com',
    'created' => REQUEST_TIME,
    'status' => 1,
    'language' => 'en',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $account->save();

  $this->assertHookMessageOrder(array(
    'entity_crud_hook_test_user_presave called',
    'entity_crud_hook_test_entity_presave called for type user',
    'entity_crud_hook_test_user_insert called',
    'entity_crud_hook_test_entity_insert called for type user',
  ));

  $_SESSION['entity_crud_hook_test'] = array();
  user_load($account->uid);

  $this->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type user',
    'entity_crud_hook_test_user_load called',
  ));

  $_SESSION['entity_crud_hook_test'] = array();
  $account->name = 'New name';
  $account->save();

  $this->assertHookMessageOrder(array(
    'entity_crud_hook_test_user_presave called',
    'entity_crud_hook_test_entity_presave called for type user',
    'entity_crud_hook_test_user_update called',
    'entity_crud_hook_test_entity_update called for type user',
  ));

  $_SESSION['entity_crud_hook_test'] = array();
  user_delete($account->uid);

  $this->assertHookMessageOrder(array(
    'entity_crud_hook_test_user_predelete called',
    'entity_crud_hook_test_entity_predelete called for type user',
    'entity_crud_hook_test_user_delete called',
    'entity_crud_hook_test_entity_delete called for type user',
  ));
}