93ac64369fac60af09867efe81b1f07133a05757
[yaffs-website] / web / core / modules / taxonomy / tests / src / Kernel / Migrate / d6 / MigrateVocabularyEntityFormDisplayTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
4
5 use Drupal\Core\Entity\Entity\EntityFormDisplay;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
7
8 /**
9  * Vocabulary entity form display migration.
10  *
11  * @group migrate_drupal_6
12  */
13 class MigrateVocabularyEntityFormDisplayTest 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_taxonomy_vocabulary',
31       'd6_vocabulary_field',
32       'd6_vocabulary_field_instance',
33       'd6_vocabulary_entity_display',
34     ]);
35   }
36
37   /**
38    * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
39    */
40   public function testVocabularyEntityFormDisplay() {
41     $this->executeMigration('d6_vocabulary_entity_form_display');
42
43     // Test that the field exists.
44     $component = EntityFormDisplay::load('node.page.default')->getComponent('tags');
45     $this->assertIdentical('options_select', $component['type']);
46     $this->assertIdentical(20, $component['weight']);
47     // Test the Id map.
48     $this->assertIdentical(['node', 'article', 'default', 'tags'], $this->getMigration('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID([4, 'article']));
49
50     // Test the term widget tags setting.
51     $entity_form_display = EntityFormDisplay::load('node.story.default');
52     $this->assertIdentical($entity_form_display->getComponent('vocabulary_1_i_0_')['type'], 'options_select');
53     $this->assertIdentical($entity_form_display->getComponent('vocabulary_2_i_1_')['type'], 'entity_reference_autocomplete_tags');
54   }
55
56   /**
57    * Tests that vocabulary displays are ignored appropriately.
58    *
59    * Vocabulary displays should be ignored when they belong to node types which
60    * were not migrated.
61    */
62   public function testSkipNonExistentNodeType() {
63     // The "story" node type is migrated by d6_node_type but we need to pretend
64     // that it didn't occur, so record that in the map table.
65     $this->mockFailure('d6_node_type', ['type' => 'story']);
66
67     // d6_vocabulary_entity_form_display should skip over the "story" node type
68     // config because, according to the map table, it didn't occur.
69     $migration = $this->getMigration('d6_vocabulary_entity_form_display');
70
71     $this->executeMigration($migration);
72     $this->assertNull($migration->getIdMap()->lookupDestinationIds(['type' => 'story'])[0][0]);
73   }
74
75 }