Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / taxonomy / tests / src / Kernel / Migrate / d6 / MigrateVocabularyEntityDisplayTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
4
5 use Drupal\Core\Entity\Entity\EntityViewDisplay;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
7
8 /**
9  * Vocabulary entity display migration.
10  *
11  * @group migrate_drupal_6
12  */
13 class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['field', '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       'd6_vocabulary_field_instance',
34     ]);
35   }
36
37   /**
38    * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
39    */
40   public function testVocabularyEntityDisplay() {
41     $this->executeMigration('d6_vocabulary_entity_display');
42
43     // Test that the field exists.
44     $component = EntityViewDisplay::load('node.page.default')->getComponent('field_tags');
45     $this->assertSame('entity_reference_label', $component['type']);
46     $this->assertSame(20, $component['weight']);
47     // Test the Id map.
48     $this->assertSame(['node', 'article', 'default', 'field_tags'], $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID([4, 'article']));
49
50     // Tests that a vocabulary named like a D8 base field will be migrated and
51     // prefixed with 'field_' to avoid conflicts.
52     $field_type = EntityViewDisplay::load('node.sponsor.default')->getComponent('field_type');
53     $this->assertTrue(is_array($field_type));
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_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_display');
70
71     $this->executeMigration($migration);
72     $this->assertNull($migration->getIdMap()->lookupDestinationIds(['type' => 'story'])[0][0]);
73   }
74
75 }