Updated to Drupal 8.5. Core Media not yet in use.
[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\system\Tests\Entity\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  */
15 class EntityUpdateAddRevisionDefaultTest extends UpdatePathTestBase {
16
17   use EntityDefinitionTestTrait;
18   use DbUpdatesTrait;
19
20   /**
21    * The entity manager service.
22    *
23    * @var \Drupal\Core\Entity\EntityManagerInterface
24    */
25   protected $entityManager;
26
27   /**
28    * The last installed schema repository service.
29    *
30    * @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
31    */
32   protected $lastInstalledSchemaRepository;
33
34   /**
35    * The state service.
36    *
37    * @var \Drupal\Core\State\StateInterface
38    */
39   protected $state;
40
41   /**
42    * {@inheritdoc}
43    */
44   protected function setUp() {
45     parent::setUp();
46
47     $this->entityManager = \Drupal::entityManager();
48     $this->lastInstalledSchemaRepository = \Drupal::service('entity.last_installed_schema.repository');
49     $this->state = \Drupal::state();
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   protected function setDatabaseDumpFiles() {
56     $this->databaseDumpFiles = [
57       __DIR__ . '/../../../fixtures/update/drupal-8.0.0-rc1-filled.standard.entity_test_update_mul_rev.php.gz',
58     ];
59   }
60
61   /**
62    * Tests the addition of the 'revision_default' base field.
63    *
64    * @see system_update_8501()
65    */
66   public function testAddingTheRevisionDefaultField() {
67     // Make the entity type revisionable and translatable prior to running the
68     // updates.
69     $this->updateEntityTypeToRevisionableAndTranslatable();
70
71     // Check that the test entity type does not have the 'revision_default'
72     // field before running the updates.
73     $field_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update');
74     $this->assertFalse(isset($field_storage_definitions['revision_default']));
75
76     $this->runUpdates();
77
78     // Check that the 'revision_default' field has been added by
79     // system_update_8501().
80     $field_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update');
81     $this->assertTrue(isset($field_storage_definitions['revision_default']));
82
83     // Check that the correct initial value was set when the field was
84     // installed.
85     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
86     $entity = $this->entityManager->getStorage('entity_test_update')->load(1);
87     $this->assertTrue($entity->wasDefaultRevision());
88   }
89
90 }