You are here

public function EntityCrudHookTest::testUserHooks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityCrudHookTest.php \Drupal\system\Tests\Entity\EntityCrudHookTest::testUserHooks()

Tests hook invocations for CRUD operations on users.

File

core/modules/system/src/Tests/Entity/EntityCrudHookTest.php, line 484
Contains \Drupal\system\Tests\Entity\EntityCrudHookTest.

Class

EntityCrudHookTest
Tests the invocation of hooks when creating, inserting, loading, updating or deleting an entity.

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',
  ));
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_user_create called',
    'entity_crud_hook_test_entity_create called for type user',
  ));
  $GLOBALS['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',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  User::load($account
    ->id());
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type user',
    'entity_crud_hook_test_user_load called',
  ));
  $GLOBALS['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',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  user_delete($account
    ->id());
  $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',
  ));
}