function EntityUpdateAddRevisionTranslationAffectedTest::testAddingTheRevisionTranslationAffectedField

Tests the addition of the 'revision_translation_affected' base field.

See also

system_update_8402()

system_update_8702()

File

core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php, line 63

Class

EntityUpdateAddRevisionTranslationAffectedTest
Tests the upgrade path for adding the 'revision_translation_affected' field.

Namespace

Drupal\Tests\system\Functional\Update

Code

public function testAddingTheRevisionTranslationAffectedField() {
    // 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_translation_affected' 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_translation_affected']));
    $this->runUpdates();
    // Check that the 'revision_translation_affected' field has been added by
    // system_update_8402().
    $field_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions('entity_test_update');
    $this->assertTrue(isset($field_storage_definitions['revision_translation_affected']));
    // Check that the entity type has the 'revision_translation_affected' key.
    $entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('entity_test_update');
    $this->assertEquals('revision_translation_affected', $entity_type->getKey('revision_translation_affected'));
    // Check that the correct initial value was set when the field was
    // installed.
    $entity = \Drupal::entityTypeManager()->getStorage('entity_test_update')
        ->load(1);
    $this->assertNotEmpty($entity->revision_translation_affected->value);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.