mirrored from http://git.drupal.org/project/drupal.git
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2248983 by hchonov, amateescu, paranojik, timmillwood, tstoeck…
…ler, catch, Berdir, alexpott: Define the revision metadata base fields in the entity annotation in order for the storage to create them only in the revision table
- Loading branch information
Nathaniel Catchpole
committed
Feb 23, 2017
1 parent
801f6ca
commit 4b325ae
Showing
23 changed files
with
1,650 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
core/modules/system/src/Tests/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Drupal\system\Tests\Entity\Update; | ||
|
||
use Drupal\system\Tests\Update\UpdatePathTestBase; | ||
use Drupal\views\Entity\View; | ||
|
||
/** | ||
* Tests the upgrade path for moving the revision metadata fields. | ||
* | ||
* @group Update | ||
*/ | ||
class MoveRevisionMetadataFieldsUpdateTest extends UpdatePathTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setDatabaseDumpFiles() { | ||
$this->databaseDumpFiles = [ | ||
__DIR__ . '/../../../../tests/fixtures/update/drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gz', | ||
__DIR__ . '/../../../../tests/fixtures/update/drupal-8.entity-data-revision-metadata-fields-2248983.php', | ||
__DIR__ . '/../../../../tests/fixtures/update/drupal-8.views-revision-metadata-fields-2248983.php', | ||
]; | ||
} | ||
|
||
/** | ||
* Tests that the revision metadata fields are moved correctly. | ||
*/ | ||
public function testSystemUpdate3000() { | ||
$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()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.