Security update for Core, with self-updated composer
[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.
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
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');
55
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.');
60
61     $this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID([4, 'article']));
62
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');
67
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);
72   }
73
74   /**
75    * Tests that vocabulary field instances are ignored appropriately.
76    *
77    * Vocabulary field instances should be ignored when they belong to node
78    * types which were not migrated.
79    */
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']);
84
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');
88
89     $this->executeMigration($migration);
90     $this->assertNull($migration->getIdMap()->lookupDestinationIds(['type' => 'story'])[0][0]);
91   }
92
93 }