3 namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
9 * Vocabulary field instance migration.
11 * @group migrate_drupal_6
13 class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
18 public static $modules = ['taxonomy', 'menu_ui'];
23 protected function setUp() {
26 // Execute Dependency Migrations.
27 $this->migrateContentTypes();
28 $this->installEntitySchema('taxonomy_term');
29 $this->executeMigrations([
31 'd6_taxonomy_vocabulary',
32 'd6_vocabulary_field',
37 * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
39 public function testVocabularyFieldInstance() {
40 $this->executeMigration('d6_vocabulary_field_instance');
42 // Test that the field exists. Tags has a multilingual option of 'None'.
43 $field_id = 'node.article.field_tags';
44 $field = FieldConfig::load($field_id);
45 $this->assertSame($field_id, $field->id(), 'Field instance exists on article bundle.');
46 $this->assertSame('Tags', $field->label());
47 $this->assertTrue($field->isRequired(), 'Field is required');
48 $this->assertFalse($field->isTranslatable());
50 // Test the page bundle as well. Tags has a multilingual option of 'None'.
51 $field_id = 'node.page.field_tags';
52 $field = FieldConfig::load($field_id);
53 $this->assertSame($field_id, $field->id(), 'Field instance exists on page bundle.');
54 $this->assertSame('Tags', $field->label());
55 $this->assertTrue($field->isRequired(), 'Field is required');
56 $this->assertFalse($field->isTranslatable());
58 $settings = $field->getSettings();
59 $this->assertSame('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
60 $this->assertSame(['field_tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
61 $this->assertSame(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
63 $this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationId([4, 'article']));
65 // Test the the field vocabulary_1_i_0_ with multilingual option,
66 // 'per language terms'.
67 $field_id = 'node.story.field_vocabulary_1_i_0_';
68 $field = FieldConfig::load($field_id);
69 $this->assertFalse($field->isRequired(), 'Field is not required');
70 $this->assertTrue($field->isTranslatable());
72 // Test the the field vocabulary_2_i_0_ with multilingual option,
73 // 'Set language to vocabulary'.
74 $field_id = 'node.story.field_vocabulary_2_i_1_';
75 $field = FieldConfig::load($field_id);
76 $this->assertFalse($field->isRequired(), 'Field is not required');
77 $this->assertFalse($field->isTranslatable());
79 // Test the the field vocabulary_3_i_0_ with multilingual option,
81 $field_id = 'node.story.field_vocabulary_3_i_2_';
82 $field = FieldConfig::load($field_id);
83 $this->assertFalse($field->isRequired(), 'Field is not required');
84 $this->assertFalse($field->isTranslatable());
86 // Tests that a vocabulary named like a D8 base field will be migrated and
87 // prefixed with 'field_' to avoid conflicts.
88 $field_type = FieldConfig::load('node.sponsor.field_type');
89 $this->assertInstanceOf(FieldConfig::class, $field_type);
90 $this->assertFalse($field->isTranslatable());
94 * Tests that vocabulary field instances are ignored appropriately.
96 * Vocabulary field instances should be ignored when they belong to node
97 * types which were not migrated.
99 public function testSkipNonExistentNodeType() {
100 // The "story" node type is migrated by d6_node_type but we need to pretend
101 // that it didn't occur, so record that in the map table.
102 $this->mockFailure('d6_node_type', ['type' => 'story']);
104 // d6_vocabulary_field_instance should skip over the "story" node type
105 // config because, according to the map table, it didn't occur.
106 $migration = $this->getMigration('d6_vocabulary_field_instance');
108 $this->executeMigration($migration);
109 $this->assertNull($migration->getIdMap()->lookupDestinationIds(['type' => 'story'])[0][0]);