function MoveRevisionMetadataFieldsUpdateTest::testSystemUpdate8400

Tests that the revision metadata fields are moved correctly.

@expectedDeprecation The revision_user revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499 @expectedDeprecation The revision_created revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499 @expectedDeprecation The revision_log_message revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499 @expectedDeprecation Support for pre-8.3.0 revision table names in imported views is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Imported views must reference the correct tables. See https://www.drupal.org/node/2831499

File

core/modules/system/tests/src/Functional/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php, line 39

Class

MoveRevisionMetadataFieldsUpdateTest
Tests the upgrade path for moving the revision metadata fields.

Namespace

Drupal\Tests\system\Functional\Entity\Update

Code

public function testSystemUpdate8400() {
    $this->runUpdates();
    foreach ([
        'entity_test_revlog',
        'entity_test_mul_revlog',
    ] as $entity_type_id) {
        
        /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
        $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id);
        
        /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
        $entity_type = $storage->getEntityType();
        $revision_metadata_field_names = $entity_type->getRevisionMetadataKeys();
        $database_schema = \Drupal::database()->schema();
        // Test that the revision metadata fields are present only in the
        // revision table.
        foreach ($revision_metadata_field_names as $revision_metadata_field_name) {
            if ($entity_type->isTranslatable()) {
                $this->assertFalse($database_schema->fieldExists($entity_type->getDataTable(), $revision_metadata_field_name));
                $this->assertFalse($database_schema->fieldExists($entity_type->getRevisionDataTable(), $revision_metadata_field_name));
            }
            else {
                $this->assertFalse($database_schema->fieldExists($entity_type->getBaseTable(), $revision_metadata_field_name));
            }
            $this->assertTrue($database_schema->fieldExists($entity_type->getRevisionTable(), $revision_metadata_field_name));
        }
        // Test that the revision metadata values have been transferred correctly
        // and that the moved fields are accessible.
        
        /** @var \Drupal\Core\Entity\RevisionLogInterface $entity_rev_first */
        $entity_rev_first = $storage->loadRevision(1);
        $this->assertEqual($entity_rev_first->getRevisionUserId(), '1');
        $this->assertEqual($entity_rev_first->getRevisionLogMessage(), 'first revision');
        $this->assertEqual($entity_rev_first->getRevisionCreationTime(), '1476268517');
        
        /** @var \Drupal\Core\Entity\RevisionLogInterface $entity_rev_second */
        $entity_rev_second = $storage->loadRevision(2);
        $this->assertEqual($entity_rev_second->getRevisionUserId(), '1');
        $this->assertEqual($entity_rev_second->getRevisionLogMessage(), 'second revision');
        $this->assertEqual($entity_rev_second->getRevisionCreationTime(), '1476268518');
        // Test that the views using revision metadata fields are updated
        // properly.
        $view = View::load($entity_type_id . '_for_2248983');
        $displays = $view->get('display');
        foreach ($displays as $display => $display_data) {
            foreach ($display_data['display_options']['fields'] as $property_data) {
                if (in_array($property_data['field'], $revision_metadata_field_names)) {
                    $this->assertEqual($property_data['table'], $entity_type->getRevisionTable());
                }
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.