You are here

public function EntityCrudHookTest::testNodeHooks 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::testNodeHooks()

Tests hook invocations for CRUD operations on nodes.

File

core/modules/system/src/Tests/Entity/EntityCrudHookTest.php, line 293
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 testNodeHooks() {
  $account = $this
    ->createUser();
  $node = entity_create('node', array(
    'uid' => $account
      ->id(),
    'type' => 'article',
    'title' => 'Test node',
    'status' => 1,
    'promote' => 0,
    'sticky' => 0,
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'created' => REQUEST_TIME,
    'changed' => REQUEST_TIME,
  ));
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_node_create called',
    'entity_crud_hook_test_entity_create called for type node',
  ));
  $GLOBALS['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',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $node = Node::load($node
    ->id());
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type node',
    'entity_crud_hook_test_node_load called',
  ));
  $GLOBALS['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',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $node
    ->delete();
  $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',
  ));
}