function MigrateFieldTest::testFields
Same name in this branch
- 10 core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d6\MigrateFieldTest::testFields()
Same name in other branches
- 9 core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d6\MigrateFieldTest::testFields()
- 9 core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d7\MigrateFieldTest::testFields()
- 8.9.x core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d6\MigrateFieldTest::testFields()
- 8.9.x core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d7\MigrateFieldTest::testFields()
- 11.x core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d6\MigrateFieldTest::testFields()
- 11.x core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d7\MigrateFieldTest::testFields()
Tests migrating D7 fields to field_storage_config entities.
1 method overrides MigrateFieldTest::testFields()
- RollbackFieldTest::testFields in core/
modules/ field/ tests/ src/ Kernel/ Migrate/ d7/ RollbackFieldTest.php - Tests migrating D7 fields to field_storage_config entities, then rolling back.
File
-
core/
modules/ field/ tests/ src/ Kernel/ Migrate/ d7/ MigrateFieldTest.php, line 73
Class
- MigrateFieldTest
- Migrates Drupal 7 fields.
Namespace
Drupal\Tests\field\Kernel\Migrate\d7Code
public function testFields() : void {
\Drupal::service('module_installer')->install([
'datetime_range',
]);
$this->installConfig(static::$modules);
$this->executeMigration('d7_field');
$this->assertEntity('node.body', 'text_with_summary', TRUE, 1);
$this->assertEntity('node.field_long_text', 'text_with_summary', TRUE, 1);
$this->assertEntity('comment.comment_body', 'text_long', TRUE, 1);
$this->assertEntity('node.field_file', 'file', TRUE, 1);
$this->assertEntity('user.field_file', 'file', TRUE, 1);
$this->assertEntity('node.field_float', 'float', TRUE, 1);
$this->assertEntity('node.field_image', 'image', TRUE, 1);
$this->assertEntity('node.field_images', 'image', TRUE, 1);
$this->assertEntity('node.field_integer', 'integer', TRUE, 1);
$this->assertEntity('comment.field_integer', 'integer', TRUE, 1);
$this->assertEntity('node.field_integer_list', 'list_integer', TRUE, 1);
$this->assertEntity('node.field_link', 'link', TRUE, 1);
$this->assertEntity('node.field_tags', 'entity_reference', TRUE, -1);
$this->assertEntity('node.field_term_reference', 'entity_reference', TRUE, 1);
$this->assertEntity('node.taxonomy_forums', 'entity_reference', TRUE, 1);
$this->assertEntity('node.field_text', 'string', TRUE, 1);
$this->assertEntity('node.field_text_list', 'list_string', TRUE, 3);
$this->assertEntity('node.field_float_list', 'list_float', TRUE, 1);
$this->assertEntity('node.field_boolean', 'boolean', TRUE, 1);
$this->assertEntity('node.field_email', 'email', TRUE, -1);
$this->assertEntity('node.field_phone', 'telephone', TRUE, 1);
$this->assertEntity('node.field_date', 'datetime', TRUE, 1);
$this->assertEntity('node.field_date_with_end_time', 'timestamp', TRUE, 1);
$this->assertEntity('node.field_node_entityreference', 'entity_reference', TRUE, -1);
$this->assertEntity('node.field_user_entityreference', 'entity_reference', TRUE, 1);
$this->assertEntity('node.field_term_entityreference', 'entity_reference', TRUE, -1);
$this->assertEntity('node.field_date_without_time', 'datetime', TRUE, 1);
$this->assertEntity('node.field_datetime_without_time', 'datetime', TRUE, 1);
$this->assertEntity('node.field_file_mfw', 'file', TRUE, 1);
$this->assertEntity('node.field_image_miw', 'image', TRUE, 1);
// Tests that fields created by the Title module are not migrated.
$title_field = FieldStorageConfig::load('node.title_field');
$this->assertNull($title_field);
$subject_field = FieldStorageConfig::load('comment.subject_field');
$this->assertNull($subject_field);
$name_field = FieldStorageConfig::load('taxonomy_term.name_field');
$this->assertNull($name_field);
$description_field = FieldStorageConfig::load('taxonomy_term.description_field');
$this->assertNull($description_field);
// Assert that the taxonomy term reference fields are referencing the
// correct entity type.
$field = FieldStorageConfig::load('node.field_term_reference');
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.taxonomy_forums');
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
// Assert that the entityreference fields are referencing the correct
// entity type.
$field = FieldStorageConfig::load('node.field_node_entityreference');
$this->assertEquals('node', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_user_entityreference');
$this->assertEquals('user', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_term_entityreference');
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
// Make sure that datetime fields get the right datetime_type setting
$field = FieldStorageConfig::load('node.field_date');
$this->assertEquals('datetime', $field->getSetting('datetime_type'));
$field = FieldStorageConfig::load('node.field_date_without_time');
$this->assertEquals('date', $field->getSetting('datetime_type'));
$field = FieldStorageConfig::load('node.field_datetime_without_time');
$this->assertEquals('date', $field->getSetting('datetime_type'));
// Except for field_date_with_end_time which is a timestamp and so does not
// have a datetime_type setting.
$field = FieldStorageConfig::load('node.field_date_with_end_time');
$this->assertNull($field->getSetting('datetime_type'));
// Assert node and user reference fields.
$field = FieldStorageConfig::load('node.field_node_reference');
$this->assertEquals('node', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_user_reference');
$this->assertEquals('user', $field->getSetting('target_type'));
// Make sure a datetime field with a todate is now a daterange type.
$field = FieldStorageConfig::load('node.field_event');
$this->assertSame('daterange', $field->getType());
$this->assertSame('datetime_range', $field->getTypeProvider());
$this->assertEquals('datetime', $field->getSetting('datetime_type'));
// Test the migration of text fields with different text processing.
// All text and text_long field bases that have only plain text instances
// should be migrated to string and string_long fields.
// All text_with_summary field bases that have only plain text instances
// should not have been migrated since there's no such thing as a
// string_with_summary field.
$this->assertEntity('node.field_text_plain', 'string', TRUE, 1);
$this->assertEntity('node.field_text_long_plain', 'string_long', TRUE, 1);
$this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain'));
// All text, text_long and text_with_summary field bases that have only
// filtered text instances should be migrated to text, text_long and
// text_with_summary fields.
$this->assertEntity('node.field_text_filtered', 'text', TRUE, 1);
$this->assertEntity('node.field_text_long_filtered', 'text_long', TRUE, 1);
$this->assertEntity('node.field_text_sum_filtered', 'text_with_summary', TRUE, 1);
// All text, text_long and text_with_summary field bases that have both
// plain text and filtered text instances should not have been migrated.
$this->assertNull(FieldStorageConfig::load('node.field_text_plain_filtered'));
$this->assertNull(FieldStorageConfig::load('node.field_text_long_plain_filtered'));
$this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain_filtered'));
// For each text field bases that were skipped, there should be a log
// message with the required steps to fix this.
$migration = $this->getMigration('d7_field');
$errors = array_map(function ($message) {
return $message->message;
}, iterator_to_array($migration->getIdMap()
->getMessages()));
sort($errors);
$this->assertCount(4, $errors);
$this->assertEquals('d7_field:type: Can\'t migrate source field field_text_long_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text', $errors[0]);
$this->assertEquals('d7_field:type: Can\'t migrate source field field_text_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text', $errors[1]);
$this->assertEquals('d7_field:type: Can\'t migrate source field field_text_sum_plain of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text', $errors[2]);
$this->assertEquals('d7_field:type: Can\'t migrate source field field_text_sum_plain_filtered of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text', $errors[3]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.