View source
<?php
namespace Drupal\Tests\field\Kernel\Migrate\d7;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
class MigrateFieldTest extends MigrateDrupal7TestBase {
protected static $modules = [
'comment',
'datetime',
'file',
'image',
'link',
'node',
'system',
'taxonomy',
'telephone',
'text',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig(static::$modules);
$this
->executeMigration('d7_field');
}
protected function assertEntity($id, $expected_type, $expected_translatable, $expected_cardinality) {
list($expected_entity_type, $expected_name) = explode('.', $id);
$field = FieldStorageConfig::load($id);
$this
->assertInstanceOf(FieldStorageConfigInterface::class, $field);
$this
->assertEquals($expected_name, $field
->getName());
$this
->assertEquals($expected_type, $field
->getType());
$this
->assertEquals($expected_translatable, $field
->isTranslatable());
$this
->assertEquals($expected_entity_type, $field
->getTargetEntityTypeId());
if ($expected_cardinality === 1) {
$this
->assertFalse($field
->isMultiple());
}
else {
$this
->assertTrue($field
->isMultiple());
}
$this
->assertEquals($expected_cardinality, $field
->getCardinality());
}
public function testFields() {
$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);
$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);
$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'));
$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'));
$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'));
$field = FieldStorageConfig::load('node.field_date_with_end_time');
$this
->assertNull($field
->getSetting('datetime_type'));
$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'));
$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'));
$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);
$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'));
$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('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('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('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('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]);
}
}