aa8ba00461b152496f4a032c8b7a1bfd89684339
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / EntityUpdateAddRevisionDefaultTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
7
8 /**
9  * Tests the upgrade path for adding the 'revision_default' field.
10  *
11  * @see https://www.drupal.org/project/drupal/issues/2891215
12  *
13  * @group Update
14  * @group legacy
15  */
16 class EntityUpdateAddRevisionDefaultTest extends UpdatePathTestBase {
17
18   use EntityDefinitionTestTrait;
19   use DbUpdatesTrait;
20
21   /**
22    * The entity manager service.
23    *
24    * @var \Drupal\Core\Entity\EntityManagerInterface
25    */
26   protected $entityManager;
27
28   /**
29    * The last installed schema repository service.
30    *
31    * @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
32    */
33   protected $lastInstalledSchemaRepository;
34
35   /**
36    * The state service.
37    *
38    * @var \Drupal\Core\State\StateInterface
39    */
40   protected $state;
41
42   /**
43    * {@inheritdoc}
44    */
45   protected function setUp() {
46     parent::setUp();
47
48     $this->entityManager = \Drupal::entityManager();
49     $this->lastInstalledSchemaRepository = \Drupal::service('entity.last_installed_schema.repository');
50     $this->state = \Drupal::state();
51   }
52
53   /**
54    * {@inheritdoc}
55    */
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',
59     ];
60   }
61
62   /**
63    * Tests the addition of the 'revision_default' base field.
64    *
65    * @see system_update_8501()
66    */
67   public function testAddingTheRevisionDefaultField() {
68     // Make the entity type revisionable and translatable prior to running the
69     // updates.
70     $this->updateEntityTypeToRevisionableAndTranslatable();
71
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']));
76
77     $this->runUpdates();
78
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']));
83
84     // Check that the correct initial value was set when the field was
85     // installed.
86     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
87     $entity = $this->entityManager->getStorage('entity_test_update')->load(1);
88     $this->assertTrue($entity->wasDefaultRevision());
89   }
90
91 }