You are here

public function EntityDefinitionUpdateTest::testEntityTypeUpdateWithoutData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest::testEntityTypeUpdateWithoutData()

Tests updating entity schema when there are no existing entities.

File

core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php, line 97
Contains \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest.

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\system\Tests\Entity

Code

public function testEntityTypeUpdateWithoutData() {

  // The 'entity_test_update' entity type starts out non-revisionable, so
  // ensure the revision table hasn't been created during setUp().
  $this
    ->assertFalse($this->database
    ->schema()
    ->tableExists('entity_test_update_revision'), 'Revision table not created for entity_test_update.');

  // Update it to be revisionable and ensure the definition update manager
  // reports that an update is needed.
  $this
    ->updateEntityTypeToRevisionable();
  $this
    ->assertTrue($this->entityDefinitionUpdateManager
    ->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
  $expected = array(
    'entity_test_update' => array(
      t('Update the %entity_type entity type.', array(
        '%entity_type' => $this->entityManager
          ->getDefinition('entity_test_update')
          ->getLabel(),
      )),
    ),
  );
  $this
    ->assertEqual($this->entityDefinitionUpdateManager
    ->getChangeSummary(), $expected);

  //, 'EntityDefinitionUpdateManager reports the expected change summary.');

  // Run the update and ensure the revision table is created.
  $this->entityDefinitionUpdateManager
    ->applyUpdates();
  $this
    ->assertTrue($this->database
    ->schema()
    ->tableExists('entity_test_update_revision'), 'Revision table created for entity_test_update.');
}