Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / taxonomy / tests / src / Kernel / Migrate / d6 / MigrateVocabularyFieldInstanceTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
7
8 /**
9  * Vocabulary field instance migration.
10  *
11  * @group migrate_drupal_6
12  */
13 class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['taxonomy', 'menu_ui'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     parent::setUp();
25
26     // Execute Dependency Migrations.
27     $this->migrateContentTypes();
28     $this->installEntitySchema('taxonomy_term');
29     $this->executeMigrations([
30       'd6_node_type',
31       'd6_taxonomy_vocabulary',
32       'd6_vocabulary_field',
33     ]);
34   }
35
36   /**
37    * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
38    */
39   public function testVocabularyFieldInstance() {
40     $this->executeMigration('d6_vocabulary_field_instance');
41
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());
49
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());
57
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.');
62
63     $this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationId([4, 'article']));
64
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());
71
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());
78
79     // Test the the field vocabulary_3_i_0_ with multilingual option,
80     // 'Localize terms'.
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());
85
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());
91   }
92
93   /**
94    * Tests that vocabulary field instances are ignored appropriately.
95    *
96    * Vocabulary field instances should be ignored when they belong to node
97    * types which were not migrated.
98    */
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']);
103
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');
107
108     $this->executeMigration($migration);
109     $this->assertNull($migration->getIdMap()->lookupDestinationIds(['type' => 'story'])[0][0]);
110   }
111
112 }