public function EntityCrudHookTest::testTaxonomyTermHooks in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Entity/EntityCrudHookTest.php \Drupal\system\Tests\Entity\EntityCrudHookTest::testTaxonomyTermHooks()
 
Tests hook invocations for CRUD operations on taxonomy terms.
File
- core/
modules/ system/ src/ Tests/ Entity/ EntityCrudHookTest.php, line 356  - 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\EntityCode
public function testTaxonomyTermHooks() {
  $this
    ->installEntitySchema('taxonomy_term');
  $vocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => 'Test vocabulary',
    'vid' => 'test',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'description' => NULL,
    'module' => 'entity_crud_hook_test',
  ));
  $vocabulary
    ->save();
  $GLOBALS['entity_crud_hook_test'] = array();
  $term = entity_create('taxonomy_term', array(
    'vid' => $vocabulary
      ->id(),
    'name' => 'Test term',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'description' => NULL,
    'format' => 1,
  ));
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_taxonomy_term_create called',
    'entity_crud_hook_test_entity_create called for type taxonomy_term',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $term
    ->save();
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_taxonomy_term_presave called',
    'entity_crud_hook_test_entity_presave called for type taxonomy_term',
    'entity_crud_hook_test_taxonomy_term_insert called',
    'entity_crud_hook_test_entity_insert called for type taxonomy_term',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $term = Term::load($term
    ->id());
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_entity_load called for type taxonomy_term',
    'entity_crud_hook_test_taxonomy_term_load called',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $term
    ->setName('New name');
  $term
    ->save();
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_taxonomy_term_presave called',
    'entity_crud_hook_test_entity_presave called for type taxonomy_term',
    'entity_crud_hook_test_taxonomy_term_update called',
    'entity_crud_hook_test_entity_update called for type taxonomy_term',
  ));
  $GLOBALS['entity_crud_hook_test'] = array();
  $term
    ->delete();
  $this
    ->assertHookMessageOrder(array(
    'entity_crud_hook_test_taxonomy_term_predelete called',
    'entity_crud_hook_test_entity_predelete called for type taxonomy_term',
    'entity_crud_hook_test_taxonomy_term_delete called',
    'entity_crud_hook_test_entity_delete called for type taxonomy_term',
  ));
}