3 namespace Drupal\Tests\system\Functional\Update;
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
9 * Tests the upgrade path for adding the 'revision_default' field.
11 * @see https://www.drupal.org/project/drupal/issues/2891215
16 class EntityUpdateAddRevisionDefaultTest extends UpdatePathTestBase {
18 use EntityDefinitionTestTrait;
22 * The entity manager service.
24 * @var \Drupal\Core\Entity\EntityManagerInterface
26 protected $entityManager;
29 * The last installed schema repository service.
31 * @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
33 protected $lastInstalledSchemaRepository;
38 * @var \Drupal\Core\State\StateInterface
45 protected function setUp() {
48 $this->entityManager = \Drupal::entityManager();
49 $this->lastInstalledSchemaRepository = \Drupal::service('entity.last_installed_schema.repository');
50 $this->state = \Drupal::state();
56 protected function setDatabaseDumpFiles() {
57 $this->databaseDumpFiles = [
58 __DIR__ . '/../../../fixtures/update/drupal-8.0.0-rc1-filled.standard.entity_test_update_mul_rev.php.gz',
63 * Tests the addition of the 'revision_default' base field.
65 * @see system_update_8501()
67 public function testAddingTheRevisionDefaultField() {
68 // Make the entity type revisionable and translatable prior to running the
70 $this->updateEntityTypeToRevisionableAndTranslatable();
72 // Check that the test entity type does not have the 'revision_default'
73 // field before running the updates.
74 $field_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update');
75 $this->assertFalse(isset($field_storage_definitions['revision_default']));
79 // Check that the 'revision_default' field has been added by
80 // system_update_8501().
81 $field_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update');
82 $this->assertTrue(isset($field_storage_definitions['revision_default']));
84 // Check that the correct initial value was set when the field was
86 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
87 $entity = $this->entityManager->getStorage('entity_test_update')->load(1);
88 $this->assertTrue($entity->wasDefaultRevision());