public function EntityCrudHookTest::testNodeHooks

Tests hook invocations for CRUD operations on nodes.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php, line 198
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 testNodeHooks() {
  $node = entity_create('node', array(
    'uid' => 1,
    'type' => 'article',
    'title' => 'Test node',
    'status' => 1,
    'comment' => 2,
    'promote' => 0,
    'sticky' => 0,
    'langcode' => LANGUAGE_NOT_SPECIFIED,
    'created' => REQUEST_TIME,
    'changed' => REQUEST_TIME,
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $node
    ->save();
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_node_presave called',
    'entity_crud_hook_test_entity_presave called for type node',
    'entity_crud_hook_test_node_insert called',
    'entity_crud_hook_test_entity_insert called for type node',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $node = node_load($node->nid);
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type node',
    'entity_crud_hook_test_node_load called',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $node->title = 'New title';
  $node
    ->save();
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_node_presave called',
    'entity_crud_hook_test_entity_presave called for type node',
    'entity_crud_hook_test_node_update called',
    'entity_crud_hook_test_entity_update called for type node',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  node_delete($node->nid);
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_node_predelete called',
    'entity_crud_hook_test_entity_predelete called for type node',
    'entity_crud_hook_test_node_delete called',
    'entity_crud_hook_test_entity_delete called for type node',
  ));
}