function EntityApiInfoTest::testEntityInfoChanges

Ensures entity info cache is updated after changes.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityApiInfoTest.php, line 28
Definition of Drupal\system\Tests\Entity\EntityApiInfoTest.

Class

EntityApiInfoTest
Tests Entity API base functionality.

Namespace

Drupal\system\Tests\Entity

Code

function testEntityInfoChanges() {
  module_enable(array(
    'entity_cache_test',
  ));
  $entity_info = entity_get_info();
  $this
    ->assertTrue(isset($entity_info['entity_cache_test']), 'Test entity type found.');

  // Change the label of the test entity type and make sure changes appear
  // after flushing caches.
  \Drupal::state()
    ->set('entity_cache_test.label', 'New label.');
  $info = entity_get_info('entity_cache_test');
  $this
    ->assertEqual($info['label'], 'Entity Cache Test', 'Original label appears in cached entity info.');
  $this
    ->resetAll();
  $info = entity_get_info('entity_cache_test');
  $this
    ->assertEqual($info['label'], 'New label.', 'New label appears in entity info.');

  // Disable the providing module and make sure the entity type is gone.
  module_disable(array(
    'entity_cache_test',
    'entity_cache_test_dependency',
  ));
  $entity_info = entity_get_info();
  $this
    ->assertFalse(isset($entity_info['entity_cache_test']), 'Entity type of the providing module is gone.');
}