Update to Drupal 8.1.9. For more information, see https://www.drupal.org/project/drupal/releases/8.1.9
This commit is contained in:
parent
f9f23cdf38
commit
09b113657a
125 changed files with 2307 additions and 385 deletions
|
@ -210,6 +210,98 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
$this->assertFalse(array_diff($found, array_keys($this->entities)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that recreating a field with the name as a deleted field works.
|
||||
*/
|
||||
public function testPurgeWithDeletedAndActiveField() {
|
||||
$bundle = reset($this->bundles);
|
||||
// Create another field storage.
|
||||
$field_name = 'bf_3';
|
||||
$deleted_field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1
|
||||
));
|
||||
$deleted_field_storage->save();
|
||||
// Create the field.
|
||||
FieldConfig::create([
|
||||
'field_storage' => $deleted_field_storage,
|
||||
'bundle' => $bundle,
|
||||
])->save();
|
||||
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId)
|
||||
->create(array('type' => $bundle));
|
||||
$entity->{$field_name}->setValue($this->_generateTestFieldValues(1));
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
// Delete the field.
|
||||
$deleted_field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name);
|
||||
$deleted_field->delete();
|
||||
$deleted_field_uuid = $deleted_field->uuid();
|
||||
|
||||
// Reload the field storage.
|
||||
$field_storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $deleted_field_storage->uuid(), 'include_deleted' => TRUE));
|
||||
$deleted_field_storage = reset($field_storages);
|
||||
|
||||
// Create the field again.
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1
|
||||
));
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => $bundle,
|
||||
])->save();
|
||||
|
||||
// The field still exists, deleted, with the same field name.
|
||||
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $deleted_field_uuid, 'include_deleted' => TRUE));
|
||||
$this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->isDeleted(), 'The field exists and is deleted');
|
||||
$this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->getName() == $field_name);
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId)
|
||||
->create(array('type' => $bundle));
|
||||
$entity->{$field_name}->setValue($this->_generateTestFieldValues(1));
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
// Check that the two field storages have different tables.
|
||||
$storage = \Drupal::entityManager()->getStorage($this->entityTypeId);
|
||||
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
|
||||
$table_mapping = $storage->getTableMapping();
|
||||
$deleted_table_name = $table_mapping->getDedicatedDataTableName($deleted_field_storage, TRUE);
|
||||
$active_table_name = $table_mapping->getDedicatedDataTableName($field_storage);
|
||||
|
||||
field_purge_batch(50);
|
||||
|
||||
// Ensure the new field still has its table and the deleted one has been
|
||||
// removed.
|
||||
$this->assertTrue(\Drupal::database()->schema()->tableExists($active_table_name));
|
||||
$this->assertFalse(\Drupal::database()->schema()->tableExists($deleted_table_name));
|
||||
|
||||
// The field has been removed from the system.
|
||||
$fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $deleted_field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE));
|
||||
$this->assertEqual(count($fields), 0, 'The field is gone');
|
||||
|
||||
// Verify there are still 10 entries in the main table.
|
||||
$count = \Drupal::database()
|
||||
->select('entity_test__' . $field_name, 'f')
|
||||
->fields('f', array('entity_id'))
|
||||
->condition('bundle', $bundle)
|
||||
->countQuery()
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertEqual($count, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that field data items and fields are purged when a field storage is
|
||||
* deleted.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\field\Kernel\EntityReference\Views;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTestMulChanged;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\entity_test\Entity\EntityTestMul;
|
||||
|
@ -27,6 +28,7 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
*/
|
||||
public static $testViews = array(
|
||||
'test_entity_reference_entity_test_view',
|
||||
'test_entity_reference_entity_test_view_long',
|
||||
'test_entity_reference_reverse_entity_test_view',
|
||||
'test_entity_reference_entity_test_mul_view',
|
||||
'test_entity_reference_reverse_entity_test_mul_view',
|
||||
|
@ -55,6 +57,7 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('entity_test');
|
||||
$this->installEntitySchema('entity_test_mul');
|
||||
$this->installEntitySchema('entity_test_mul_changed');
|
||||
|
||||
// Create reference from entity_test to entity_test_mul.
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_data', 'field_test_data', 'entity_test_mul');
|
||||
|
@ -62,6 +65,12 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
// Create reference from entity_test_mul to entity_test.
|
||||
$this->createEntityReferenceField('entity_test_mul', 'entity_test_mul', 'field_data_test', 'field_data_test', 'entity_test');
|
||||
|
||||
// Create another field for testing with a long name. So it's storage name
|
||||
// will become hashed. Use entity_test_mul_changed, so the resulting field
|
||||
// tables created will be greater than 48 chars long.
|
||||
// @see \Drupal\Core\Entity\Sql\DefaultTableMapping::generateFieldTableName()
|
||||
$this->createEntityReferenceField('entity_test_mul_changed', 'entity_test_mul_changed', 'field_test_data_with_a_long_name', 'field_test_data_with_a_long_name', 'entity_test');
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('entity_reference_test_views'));
|
||||
}
|
||||
|
||||
|
@ -124,7 +133,6 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
// Test that the correct relationship entity is on the row.
|
||||
$this->assertEqual($row->_relationship_entities['field_test_data']->id(), 1);
|
||||
$this->assertEqual($row->_relationship_entities['field_test_data']->bundle(), 'entity_test_mul');
|
||||
|
||||
}
|
||||
|
||||
// Check the backwards reference view.
|
||||
|
@ -225,4 +233,47 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests views data generated for relationship.
|
||||
*
|
||||
* @see entity_reference_field_views_data()
|
||||
*/
|
||||
public function testDataTableRelationshipWithLongFieldName() {
|
||||
// Create some test entities which link each other.
|
||||
$referenced_entity = EntityTest::create();
|
||||
$referenced_entity->save();
|
||||
|
||||
$entity = EntityTestMulChanged::create();
|
||||
$entity->field_test_data_with_a_long_name->target_id = $referenced_entity->id();
|
||||
$entity->save();
|
||||
$this->entities[] = $entity;
|
||||
|
||||
$entity = EntityTestMulChanged::create();
|
||||
$entity->field_test_data_with_a_long_name->target_id = $referenced_entity->id();
|
||||
$entity->save();
|
||||
$this->entities[] = $entity;
|
||||
|
||||
Views::viewsData()->clear();
|
||||
|
||||
// Check an actual test view.
|
||||
$view = Views::getView('test_entity_reference_entity_test_view_long');
|
||||
$this->executeView($view);
|
||||
/** @var \Drupal\views\ResultRow $row */
|
||||
foreach ($view->result as $index => $row) {
|
||||
// Check that the actual ID of the entity is the expected one.
|
||||
$this->assertEqual($row->id, $this->entities[$index]->id());
|
||||
|
||||
// Also check that we have the correct result entity.
|
||||
$this->assertEqual($row->_entity->id(), $this->entities[$index]->id());
|
||||
|
||||
// Test the forward relationship.
|
||||
//$this->assertEqual($row->entity_test_entity_test_mul__field_data_test_id, 1);
|
||||
|
||||
// Test that the correct relationship entity is on the row.
|
||||
$this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->id(), 1);
|
||||
$this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->bundle(), 'entity_test');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
|
||||
/**
|
||||
* Migrates and rolls back Drupal 7 fields.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class RollbackFieldInstanceTest extends MigrateFieldInstanceTest {
|
||||
|
||||
/**
|
||||
* Tests migrating D7 fields to field_storage_config entities, then rolling back.
|
||||
*/
|
||||
public function testFieldInstances() {
|
||||
// Test that the field instances have migrated (prior to rollback).
|
||||
parent::testFieldInstances();
|
||||
|
||||
$this->executeRollback('d7_field_instance');
|
||||
$this->executeRollback('d7_field');
|
||||
|
||||
// Check that field instances have been rolled back.
|
||||
$field_instance_ids = [
|
||||
'comment.comment_node_page.comment_body',
|
||||
'node.page.body',
|
||||
'comment.comment_node_article.comment_body',
|
||||
'node.article.body',
|
||||
'node.article.field_tags',
|
||||
'node.article.field_image',
|
||||
'comment.comment_node_blog.comment_body',
|
||||
'node.blog.body',
|
||||
'comment.comment_node_book.comment_body',
|
||||
'node.book.body',
|
||||
'node.forum.taxonomy_forums',
|
||||
'comment.comment_node_forum.comment_body',
|
||||
'node.forum.body',
|
||||
'comment.comment_node_test_content_type.comment_body',
|
||||
'node.test_content_type.field_boolean',
|
||||
'node.test_content_type.field_email',
|
||||
'node.test_content_type.field_phone',
|
||||
'node.test_content_type.field_date',
|
||||
'node.test_content_type.field_date_with_end_time',
|
||||
'node.test_content_type.field_file',
|
||||
'node.test_content_type.field_float',
|
||||
'node.test_content_type.field_images',
|
||||
'node.test_content_type.field_integer',
|
||||
'node.test_content_type.field_link',
|
||||
'node.test_content_type.field_text_list',
|
||||
'node.test_content_type.field_integer_list',
|
||||
'node.test_content_type.field_long_text',
|
||||
'node.test_content_type.field_term_reference',
|
||||
'node.test_content_type.field_text',
|
||||
'comment.comment_node_test_content_type.field_integer',
|
||||
'user.user.field_file',
|
||||
];
|
||||
foreach ($field_instance_ids as $field_instance_id) {
|
||||
$this->assertNull(FieldConfig::load($field_instance_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a single rollback.
|
||||
*
|
||||
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to rollback, or its ID.
|
||||
*/
|
||||
protected function executeRollback($migration) {
|
||||
if (is_string($migration)) {
|
||||
$this->migration = $this->getMigration($migration);
|
||||
}
|
||||
else {
|
||||
$this->migration = $migration;
|
||||
}
|
||||
(new MigrateExecutable($this->migration, $this))->rollback();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
|
||||
/**
|
||||
* Migrates and rolls back Drupal 7 fields.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class RollbackFieldTest extends MigrateFieldTest {
|
||||
|
||||
/**
|
||||
* Tests migrating D7 fields to field_storage_config entities, then rolling back.
|
||||
*/
|
||||
public function testFields() {
|
||||
// Test that the fields have migrated (prior to rollback).
|
||||
parent::testFields();
|
||||
|
||||
$this->executeRollback('d7_field');
|
||||
|
||||
// Check that fields have been rolled back.
|
||||
$rolled_back_field_ids = [
|
||||
'comment.field_integer',
|
||||
'node.taxonomy_forums',
|
||||
'node.field_integer',
|
||||
'node.field_tags',
|
||||
'node.field_term_reference',
|
||||
'node.field_text_list',
|
||||
'node.field_text',
|
||||
'node.field_phone',
|
||||
'node.field_file',
|
||||
'node.field_images',
|
||||
'node.field_image',
|
||||
'node.field_long_text',
|
||||
'node.field_date_with_end_time',
|
||||
'node.field_integer_list',
|
||||
'node.field_date',
|
||||
'node.field_link',
|
||||
'node.field_float',
|
||||
'node.field_boolean',
|
||||
'node.field_email',
|
||||
'user.field_file',
|
||||
];
|
||||
foreach ($rolled_back_field_ids as $field_id) {
|
||||
$this->assertNull(FieldStorageConfig::load($field_id));
|
||||
}
|
||||
|
||||
// Check that fields that should persist have not been rolled back.
|
||||
$non_rolled_back_field_ids = [
|
||||
'node.body',
|
||||
'comment.comment_body',
|
||||
];
|
||||
foreach ($non_rolled_back_field_ids as $field_id) {
|
||||
$this->assertNotNull(FieldStorageConfig::load($field_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a single rollback.
|
||||
*
|
||||
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to rollback, or its ID.
|
||||
*/
|
||||
protected function executeRollback($migration) {
|
||||
if (is_string($migration)) {
|
||||
$this->migration = $this->getMigration($migration);
|
||||
}
|
||||
else {
|
||||
$this->migration = $migration;
|
||||
}
|
||||
(new MigrateExecutable($this->migration, $this))->rollback();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewMode;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
|
||||
/**
|
||||
* Migrates and rolls back Drupal 7 view modes.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class RollbackViewModesTest extends MigrateViewModesTest {
|
||||
|
||||
/**
|
||||
* Tests migrating D7 view modes, then rolling back.
|
||||
*/
|
||||
public function testMigration() {
|
||||
// Test that the view modes have migrated (prior to rollback).
|
||||
parent::testMigration();
|
||||
|
||||
$this->executeRollback('d7_view_modes');
|
||||
|
||||
// Check that view modes have been rolled back.
|
||||
$view_mode_ids = [
|
||||
'comment.full',
|
||||
'node.teaser',
|
||||
'node.full',
|
||||
'user.full',
|
||||
];
|
||||
foreach ($view_mode_ids as $view_mode_id) {
|
||||
$this->assertNull(EntityViewMode::load($view_mode_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a single rollback.
|
||||
*
|
||||
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to rollback, or its ID.
|
||||
*/
|
||||
protected function executeRollback($migration) {
|
||||
if (is_string($migration)) {
|
||||
$this->migration = $this->getMigration($migration);
|
||||
}
|
||||
else {
|
||||
$this->migration = $migration;
|
||||
}
|
||||
(new MigrateExecutable($this->migration, $this))->rollback();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue