public function EntityCrudHookTest::testBlockHooks

Tests hook invocations for CRUD operations on blocks.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php, line 79
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 testBlockHooks() {
  $entity = entity_create('block', array(
    'id' => 'stark.test_html_id',
    'plugin' => 'test_html_id',
  ));
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_block_create called',
    'entity_crud_hook_test_entity_create called for type block',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $entity
    ->save();
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_block_presave called',
    'entity_crud_hook_test_entity_presave called for type block',
    'entity_crud_hook_test_block_insert called',
    'entity_crud_hook_test_entity_insert called for type block',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $entity = entity_load('block', $entity
    ->id());
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type block',
    'entity_crud_hook_test_block_load called',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $entity->label = 'New label';
  $entity
    ->save();
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_block_presave called',
    'entity_crud_hook_test_entity_presave called for type block',
    'entity_crud_hook_test_block_update called',
    'entity_crud_hook_test_entity_update called for type block',
  ));
  $_SESSION['entity_crud_hook_test'] = array();
  $entity
    ->delete();
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_block_predelete called',
    'entity_crud_hook_test_entity_predelete called for type block',
    'entity_crud_hook_test_block_delete called',
    'entity_crud_hook_test_entity_delete called for type block',
  ));
}