You are here

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

Tests hook invocations for CRUD operations on blocks.

File

core/modules/system/src/Tests/Entity/EntityCrudHookTest.php, line 88
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 testBlockHooks() {
  $entity = entity_create('block', array(
    'id' => 'stark_test_html',
    'plugin' => 'test_html',
    'theme' => 'stark',
  ));
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_block_create called',
    'entity_crud_hook_test_entity_create called for type block',
  ));
  $GLOBALS['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',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $entity = Block::load($entity
    ->id());
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type block',
    'entity_crud_hook_test_block_load called',
  ));
  $GLOBALS['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',
  ));
  $GLOBALS['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',
  ));
}