public function EntityCrudHookTest::testUserHooks

Tests hook invocations for CRUD operations on users.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php, line 365
Definition of Drupal\system\Tests\Entity\EntityCrudHookTest.

Class

EntityCrudHookTest
Tests invocation of hooks when performing an action.

Namespace

Drupal\system\Tests\Entity

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',
  ));
}