Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / migrate_drupal / tests / src / Kernel / d7 / FollowUpMigrationsTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate_drupal\Kernel\d7;
4
5 use Drupal\node\Entity\Node;
6 use Drupal\Tests\file\Kernel\Migrate\d7\FileMigrationSetupTrait;
7
8 /**
9  * Tests follow-up migrations.
10  *
11  * @group migrate_drupal
12  */
13 class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
14
15   use FileMigrationSetupTrait;
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = [
21     'content_translation',
22     'comment',
23     'datetime',
24     'file',
25     'image',
26     'language',
27     'link',
28     'menu_ui',
29     // A requirement for translation migrations.
30     'migrate_drupal_multilingual',
31     'node',
32     'taxonomy',
33     'telephone',
34     'text',
35   ];
36
37   /**
38    * {@inheritdoc}
39    */
40   protected function setUp() {
41     parent::setUp();
42
43     $this->fileMigrationSetup();
44
45     $this->installEntitySchema('node');
46     $this->installEntitySchema('comment');
47     $this->installEntitySchema('taxonomy_term');
48     $this->installConfig(static::$modules);
49     $this->installSchema('node', ['node_access']);
50
51     $this->executeMigrations([
52       'language',
53       'd7_user_role',
54       'd7_user',
55       'd7_node_type',
56       'd7_language_content_settings',
57       'd7_comment_type',
58       'd7_taxonomy_vocabulary',
59       'd7_field',
60       'd7_field_instance',
61       'd7_node',
62       'd7_node_translation',
63     ]);
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   protected function getFileMigrationInfo() {
70     return [
71       'path' => 'public://sites/default/files/cube.jpeg',
72       'size' => '3620',
73       'base_path' => 'public://',
74       'plugin_id' => 'd7_file',
75     ];
76   }
77
78   /**
79    * Test entity reference translations.
80    */
81   public function testEntityReferenceTranslations() {
82     // Test the entity reference field before the follow-up migrations.
83     $node = Node::load(2);
84     $this->assertSame('5', $node->get('field_reference')->target_id);
85     $this->assertSame('5', $node->get('field_reference_2')->target_id);
86     $translation = $node->getTranslation('is');
87     $this->assertSame('4', $translation->get('field_reference')->target_id);
88     $this->assertSame('4', $translation->get('field_reference_2')->target_id);
89
90     $node = Node::load(4);
91     $this->assertSame('3', $node->get('field_reference')->target_id);
92     $this->assertSame('3', $node->get('field_reference_2')->target_id);
93     $translation = $node->getTranslation('en');
94     $this->assertSame('2', $translation->get('field_reference')->target_id);
95     $this->assertSame('2', $translation->get('field_reference_2')->target_id);
96
97     // Run the follow-up migrations.
98     $migration_plugin_manager = $this->container->get('plugin.manager.migration');
99     $migration_plugin_manager->clearCachedDefinitions();
100     $follow_up_migrations = $migration_plugin_manager->createInstances('d7_entity_reference_translation');
101     $this->executeMigrations(array_keys($follow_up_migrations));
102
103     // Test the entity reference field after the follow-up migrations.
104     $node = Node::load(2);
105     $this->assertSame('4', $node->get('field_reference')->target_id);
106     $this->assertSame('4', $node->get('field_reference_2')->target_id);
107     $translation = $node->getTranslation('is');
108     $this->assertSame('4', $translation->get('field_reference')->target_id);
109     $this->assertSame('4', $translation->get('field_reference_2')->target_id);
110
111     $node = Node::load(4);
112     $this->assertSame('2', $node->get('field_reference')->target_id);
113     $this->assertSame('2', $node->get('field_reference_2')->target_id);
114     $translation = $node->getTranslation('en');
115     $this->assertSame('2', $translation->get('field_reference')->target_id);
116     $this->assertSame('2', $translation->get('field_reference_2')->target_id);
117   }
118
119 }