You are here

public function EntityUpdateAddRevisionDefaultTest::testAddingTheRevisionDefaultField in Drupal 8

Tests the addition of the 'revision_default' base field.

See also

system_update_8501()

File

core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionDefaultTest.php, line 57

Class

EntityUpdateAddRevisionDefaultTest
Tests the upgrade path for adding the 'revision_default' field.

Namespace

Drupal\Tests\system\Functional\Update

Code

public function testAddingTheRevisionDefaultField() {

  // Make the entity type revisionable and translatable prior to running the
  // updates.
  $this
    ->updateEntityTypeToRevisionableAndTranslatable();

  // Check that the test entity type does not have the 'revision_default'
  // field before running the updates.
  $field_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')
    ->getLastInstalledFieldStorageDefinitions('entity_test_update');
  $this
    ->assertFalse(isset($field_storage_definitions['revision_default']));
  $this
    ->runUpdates();

  // Check that the 'revision_default' field has been added by
  // system_update_8501().
  $field_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')
    ->getLastInstalledFieldStorageDefinitions('entity_test_update');
  $this
    ->assertTrue(isset($field_storage_definitions['revision_default']));

  // Check that the correct initial value was set when the field was
  // installed.

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = \Drupal::entityTypeManager()
    ->getStorage('entity_test_update')
    ->load(1);
  $this
    ->assertTrue($entity
    ->wasDefaultRevision());
}