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.tags';
44 $field = FieldConfig::load($field_id);
45 $this->assertIdentical($field_id, $field->id(), 'Field instance exists on article bundle.');
46 $this->assertIdentical('Tags', $field->label());
47 $this->assertTrue($field->isRequired(), 'Field is required');
49 // Test the page bundle as well.
50 $field_id = 'node.page.tags';
51 $field = FieldConfig::load($field_id);
52 $this->assertIdentical($field_id, $field->id(), 'Field instance exists on page bundle.');
53 $this->assertIdentical('Tags', $field->label());
54 $this->assertTrue($field->isRequired(), 'Field is required');
56 $settings = $field->getSettings();
57 $this->assertIdentical('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
58 $this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
59 $this->assertIdentical(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
61 $this->assertIdentical(['node', 'article', '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.vocabulary_1_i_0_';
65 $field = FieldConfig::load($field_id);
66 $this->assertFalse($field->isRequired(), 'Field is not required');
70 * Tests that vocabulary field instances are ignored appropriately.
72 * Vocabulary field instances should be ignored when they belong to node
73 * types which were not migrated.
75 public function testSkipNonExistentNodeType() {
76 // The "story" node type is migrated by d6_node_type but we need to pretend
77 // that it didn't occur, so record that in the map table.
78 $this->mockFailure('d6_node_type', ['type' => 'story']);
80 // d6_vocabulary_field_instance should skip over the "story" node type
81 // config because, according to the map table, it didn't occur.
82 $migration = $this->getMigration('d6_vocabulary_field_instance');
84 $this->executeMigration($migration);
85 $this->assertNull($migration->getIdMap()->lookupDestinationIds(['type' => 'story'])[0][0]);