3 namespace Drupal\Tests\field\Kernel\Migrate\d6;
5 use Drupal\field\Entity\FieldStorageConfig;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
11 * @group migrate_drupal_6
13 class MigrateFieldTest extends MigrateDrupal6TestBase {
18 protected function setUp() {
20 $this->executeMigration('d6_field');
24 * Tests the Drupal 6 field to Drupal 8 migration.
26 public function testFields() {
28 /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
29 $field_storage = FieldStorageConfig::load('node.field_test');
30 $this->assertSame('text_long', $field_storage->getType());
31 // text_long fields do not have settings.
32 $this->assertSame([], $field_storage->getSettings());
35 $field_storage = FieldStorageConfig::load('node.field_test_two');
36 $this->assertSame("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', ['@fieldtype' => $field_storage->getType()]));
39 $field_storage = FieldStorageConfig::load('node.field_test_three');
40 $this->assertSame("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', ['@fieldtype' => $field_storage->getType()]));
43 $field_storage = FieldStorageConfig::load('node.field_test_link');
44 $this->assertSame("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', ['@fieldtype' => $field_storage->getType()]));
47 $field_storage = FieldStorageConfig::load('node.field_test_filefield');
48 $this->assertSame("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', ['@fieldtype' => $field_storage->getType()]));
50 $field_storage = FieldStorageConfig::load('node.field_test_imagefield');
51 $this->assertSame("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', ['@fieldtype' => $field_storage->getType()]));
52 $settings = $field_storage->getSettings();
53 $this->assertSame('file', $settings['target_type']);
54 $this->assertSame('public', $settings['uri_scheme']);
55 $this->assertSame([], array_filter($settings['default_image']));
58 $field_storage = FieldStorageConfig::load('node.field_test_phone');
59 $this->assertSame("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', ['@fieldtype' => $field_storage->getType()]));
62 $field_storage = FieldStorageConfig::load('node.field_test_datetime');
63 $this->assertSame("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()]));
66 $field_storage = FieldStorageConfig::load('node.field_test_datetime');
67 $this->assertSame("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()]));
68 $field_storage = FieldStorageConfig::load('node.field_test_datestamp');
69 $this->assertSame("timestamp", $field_storage->getType(), t('Field type is @fieldtype. It should be timestamp.', ['@fieldtype' => $field_storage->getType()]));
70 $field_storage = FieldStorageConfig::load('node.field_test_date');
71 $this->assertSame("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()]));
73 // Decimal field with radio buttons.
74 $field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons');
75 $this->assertSame("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', ['@fieldtype' => $field_storage->getType()]));
76 $this->assertNotNull($field_storage->getSetting('allowed_values')['1.2'], t('First allowed value key is set to 1.2'));
77 $this->assertNotNull($field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value key is set to 2.1'));
78 $this->assertSame('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2'));
79 $this->assertSame('2.1', $field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value is set to 1.2'));
82 $field_storage = FieldStorageConfig::load('node.field_test_email');
83 $this->assertSame("email", $field_storage->getType(), t('Field type is @fieldtype. It should be email.', ['@fieldtype' => $field_storage->getType()]));
85 // Float field with a single checkbox.
86 $field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox');
87 $this->assertSame("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()]));
89 // Integer field with a select list.
90 $field_storage = FieldStorageConfig::load('node.field_test_integer_selectlist');
91 $this->assertSame("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', ['@fieldtype' => $field_storage->getType()]));
92 $this->assertNotNull($field_storage->getSetting('allowed_values')['1234'], t('First allowed value key is set to 1234'));
93 $this->assertNotNull($field_storage->getSetting('allowed_values')['2341'], t('Second allowed value key is set to 2341'));
94 $this->assertNotNull($field_storage->getSetting('allowed_values')['3412'], t('Third allowed value key is set to 3412'));
95 $this->assertNotNull($field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value key is set to 4123'));
96 $this->assertSame('1234', $field_storage->getSetting('allowed_values')['1234'], t('First allowed value is set to 1234'));
97 $this->assertSame('2341', $field_storage->getSetting('allowed_values')['2341'], t('Second allowed value is set to 2341'));
98 $this->assertSame('3412', $field_storage->getSetting('allowed_values')['3412'], t('Third allowed value is set to 3412'));
99 $this->assertSame('4123', $field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value is set to 4123'));
101 // Text field with a single checkbox.
102 $field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox');
103 $this->assertSame("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()]));
105 // Test a node reference field.
106 $field_storage = FieldStorageConfig::load('node.field_company');
107 $this->assertInstanceOf(FieldStorageConfig::class, $field_storage);
108 $this->assertSame('entity_reference', $field_storage->getType());
109 $this->assertSame('node', $field_storage->getSetting('target_type'));
111 // Test a user reference field.
112 $field_storage = FieldStorageConfig::load('node.field_commander');
113 $this->assertInstanceOf(FieldStorageConfig::class, $field_storage);
114 $this->assertSame('entity_reference', $field_storage->getType());
115 $this->assertSame('user', $field_storage->getSetting('target_type'));
117 // Validate that the source count and processed count match up.
118 /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
119 $migration = $this->getMigration('d6_field');
120 $this->assertSame($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
122 // Check that we've reported on a conflict in widget_types.
124 foreach ($migration->getIdMap()->getMessageIterator() as $message_row) {
125 $messages[] = $message_row->message;
127 $this->assertCount(1, $messages);
128 $this->assertSame($messages[0], 'Widget types optionwidgets_onoff, text_textfield are used in Drupal 6 field instances: widget type optionwidgets_onoff applied to the Drupal 8 base field');