Newer
Older
Alex Bronstein
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Drupal\Tests\system\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
/**
* Tests the upgrade path for adding the 'revision_default' field.
*
* @see https://www.drupal.org/project/drupal/issues/2891215
*
* @group Update
*/
class EntityUpdateAddRevisionDefaultTest extends UpdatePathTestBase {
use EntityDefinitionTestTrait;
use DbUpdatesTrait;
/**
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The last installed schema repository service.
*
* @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
*/
protected $lastInstalledSchemaRepository;
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->entityManager = \Drupal::entityManager();
$this->lastInstalledSchemaRepository = \Drupal::service('entity.last_installed_schema.repository');
$this->state = \Drupal::state();
}
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../fixtures/update/drupal-8.0.0-rc1-filled.standard.entity_test_update_mul_rev.php.gz',
];
}
/**
* Tests the addition of the 'revision_default' base field.
*
* @see system_update_8501()
*/
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 = $this->lastInstalledSchemaRepository->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 = $this->lastInstalledSchemaRepository->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 = $this->entityManager->getStorage('entity_test_update')->load(1);
$this->assertTrue($entity->wasDefaultRevision());
}
}