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.
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');
49 // Test the page bundle as well.
50 $field_id = 'node.page.field_tags';
51 $field = FieldConfig::load($field_id);
52 $this->assertSame($field_id, $field->id(), 'Field instance exists on page bundle.');
53 $this->assertSame('Tags', $field->label());
54 $this->assertTrue($field->isRequired(), 'Field is required');
56 $settings = $field->getSettings();
57 $this->assertSame('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
58 $this->assertSame(['field_tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
59 $this->assertSame(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
61 $this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID([4, 'article']));
63 // Test the the field vocabulary_1_i_0_.
64 $field_id = 'node.story.field_vocabulary_1_i_0_';
65 $field = FieldConfig::load($field_id);
66 $this->assertFalse($field->isRequired(), 'Field is not required');
68 // Tests that a vocabulary named like a D8 base field will be migrated and
69 // prefixed with 'field_' to avoid conflicts.
70 $field_type = FieldConfig::load('node.sponsor.field_type');
71 $this->assertInstanceOf(FieldConfig::class, $field_type);
75 * Tests that vocabulary field instances are ignored appropriately.
77 * Vocabulary field instances should be ignored when they belong to node
78 * types which were not migrated.
80 public function testSkipNonExistentNodeType() {
81 // The "story" node type is migrated by d6_node_type but we need to pretend
82 // that it didn't occur, so record that in the map table.
83 $this->mockFailure('d6_node_type', ['type' => 'story']);
85 // d6_vocabulary_field_instance should skip over the "story" node type
86 // config because, according to the map table, it didn't occur.
87 $migration = $this->getMigration('d6_vocabulary_field_instance');
89 $this->executeMigration($migration);
90 $this->assertNull($migration->getIdMap()->lookupDestinationIds(['type' => 'story'])[0][0]);