Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / Entity / Update / MoveRevisionMetadataFieldsUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Entity\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\views\Entity\View;
7
8 /**
9  * Tests the upgrade path for moving the revision metadata fields.
10  *
11  * @group Update
12  */
13 class MoveRevisionMetadataFieldsUpdateTest extends UpdatePathTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function setDatabaseDumpFiles() {
19     $this->databaseDumpFiles = [
20       __DIR__ . '/../../../../../tests/fixtures/update/drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gz',
21       __DIR__ . '/../../../../../tests/fixtures/update/drupal-8.entity-data-revision-metadata-fields-2248983.php',
22       __DIR__ . '/../../../../../tests/fixtures/update/drupal-8.views-revision-metadata-fields-2248983.php',
23     ];
24   }
25
26   /**
27    * Tests that the revision metadata fields are moved correctly.
28    */
29   public function testSystemUpdate8400() {
30     $this->runUpdates();
31
32     foreach (['entity_test_revlog', 'entity_test_mul_revlog'] as $entity_type_id) {
33       /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
34       $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id);
35       /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
36       $entity_type = $storage->getEntityType();
37       $revision_metadata_field_names = $entity_type->getRevisionMetadataKeys();
38
39       $database_schema = \Drupal::database()->schema();
40
41       // Test that the revision metadata fields are present only in the
42       // revision table.
43       foreach ($revision_metadata_field_names as $revision_metadata_field_name) {
44         if ($entity_type->isTranslatable()) {
45           $this->assertFalse($database_schema->fieldExists($entity_type->getDataTable(), $revision_metadata_field_name));
46           $this->assertFalse($database_schema->fieldExists($entity_type->getRevisionDataTable(), $revision_metadata_field_name));
47         }
48         else {
49           $this->assertFalse($database_schema->fieldExists($entity_type->getBaseTable(), $revision_metadata_field_name));
50         }
51         $this->assertTrue($database_schema->fieldExists($entity_type->getRevisionTable(), $revision_metadata_field_name));
52       }
53
54       // Test that the revision metadata values have been transferred correctly
55       // and that the moved fields are accessible.
56       /** @var \Drupal\Core\Entity\RevisionLogInterface $entity_rev_first */
57       $entity_rev_first = $storage->loadRevision(1);
58       $this->assertEqual($entity_rev_first->getRevisionUserId(), '1');
59       $this->assertEqual($entity_rev_first->getRevisionLogMessage(), 'first revision');
60       $this->assertEqual($entity_rev_first->getRevisionCreationTime(), '1476268517');
61
62       /** @var \Drupal\Core\Entity\RevisionLogInterface $entity_rev_second */
63       $entity_rev_second = $storage->loadRevision(2);
64       $this->assertEqual($entity_rev_second->getRevisionUserId(), '1');
65       $this->assertEqual($entity_rev_second->getRevisionLogMessage(), 'second revision');
66       $this->assertEqual($entity_rev_second->getRevisionCreationTime(), '1476268518');
67
68       // Test that the views using revision metadata fields are updated
69       // properly.
70       $view = View::load($entity_type_id . '_for_2248983');
71       $displays = $view->get('display');
72       foreach ($displays as $display => $display_data) {
73         foreach ($display_data['display_options']['fields'] as $property_data) {
74           if (in_array($property_data['field'], $revision_metadata_field_names)) {
75             $this->assertEqual($property_data['table'], $entity_type->getRevisionTable());
76           }
77         }
78       }
79     }
80   }
81
82 }