From 82c63a2a9935fafdbe5b58396fbd7a24409b27d5 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Mon, 8 Feb 2021 23:36:18 +0000 Subject: [PATCH] Issue #3192900 by quietone, Matroskeen: Combine some migration kernel tests --- .../Kernel/Migrate/d7/MigrateCommentTest.php | 6 +- .../d6/MigrateUserConfigsTranslationTest.php | 6 +- .../d6/MigrateLanguageContentSettingsTest.php | 7 +- .../src/Kernel/Migrate/d7/MigrateNodeTest.php | 7 +- .../Kernel/Migrate/d6/MigrateUrlAliasTest.php | 7 +- .../Migrate/d6/MigrateTermNodeComplete.php | 6 +- .../Migrate/d7/MigrateTaxonomyTermTest.php | 80 +++++++++---------- .../Migrate/d6/MigrateUserConfigsTest.php | 6 +- .../d6/MigrateUserPictureD6FileTest.php | 22 +++-- .../src/Kernel/Migrate/d7/MigrateUserTest.php | 6 +- 10 files changed, 55 insertions(+), 98 deletions(-) diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php index a0a8aa8e5138..da27687cf101 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php @@ -123,12 +123,8 @@ public function testMigration() { $node = $comment->getCommentedEntity(); $this->assertInstanceOf(NodeInterface::class, $node); $this->assertSame('1', $node->id()); - } - /** - * Tests the migration of comment entity translations. - */ - public function testCommentEntityTranslations() { + // Tests the migration of comment entity translations. $manager = $this->container->get('content_translation.manager'); // Get the comment and its translations. diff --git a/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTranslationTest.php b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTranslationTest.php index 1db1c4fc0fc5..04b642243b29 100644 --- a/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTranslationTest.php +++ b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTranslationTest.php @@ -59,12 +59,8 @@ public function testUserMail() { $config = \Drupal::service('language_manager')->getLanguageConfigOverride('zu', 'user.mail'); $this->assertSame('zu - An administrator created an account for you at [site:name]', $config->get('register_admin_created.subject')); $this->assertSame("zu - [user:name],\r\n\r\nA site administrator at [site:name] has created an account for you. You may now log in to [site:login-url] using the following username and password:\r\n\r\nusername: [user:name]\r\npassword: \r\n\r\nYou may also log in by clicking on this link or copying and pasting it in your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis is a one-time login, so it can be used only once.\r\n\r\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.\r\n\r\n\r\n-- [site:name] team", $config->get('register_admin_created.body')); - } - /** - * Tests migration of i18n user variables to user.settings.yml. - */ - public function testUserSettings() { + // Tests migration of i18n user variables to user.settings.yml. $config = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'user.settings'); $this->assertSame(1, $config->get('notify.status_blocked')); $this->assertSame(0, $config->get('notify.status_activated')); diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php index a5b23485093f..1c17d3dedf63 100644 --- a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php +++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php @@ -51,13 +51,8 @@ public function testLanguageContent() { $this->assertTrue($config->isDefaultConfiguration()); $this->assertFalse($config->isLanguageAlterable()); $this->assertSame($config->getDefaultLangcode(), 'site_default'); - } - /** - * Tests migration of content language settings when there is no language lock. - */ - public function testLanguageContentWithNoLanguageLock() { - // Assert that a we can assign a language. + // Assert that a we can assign a language when there is no language lock. $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'employee'); $this->assertSame($config->getDefaultLangcode(), 'current_interface'); $this->assertTrue($config->isLanguageAlterable()); diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php index fb61c3c62104..65b1ad85e304 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php @@ -250,12 +250,7 @@ public function testNode() { $node = $node->getTranslation('is'); $this->assertSame($value, $node->field_text_plain->value); - } - - /** - * Test node entity translations migration from Drupal 7 to 8. - */ - public function testNodeEntityTranslations() { + // Test node entity translations migration from Drupal 7 to 8. $manager = $this->container->get('content_translation.manager'); // Get the node and its translations. diff --git a/core/modules/path/tests/src/Kernel/Migrate/d6/MigrateUrlAliasTest.php b/core/modules/path/tests/src/Kernel/Migrate/d6/MigrateUrlAliasTest.php index 974cfd54e0b1..984014476c49 100644 --- a/core/modules/path/tests/src/Kernel/Migrate/d6/MigrateUrlAliasTest.php +++ b/core/modules/path/tests/src/Kernel/Migrate/d6/MigrateUrlAliasTest.php @@ -122,14 +122,9 @@ public function testUrlAlias() { 'langcode' => 'und', ]; $this->assertPath(8, $conditions, $path_alias); - } - /** - * Test the URL alias migration with translated nodes. - */ - public function testUrlAliasWithTranslatedNodes() { + // Test the URL alias migration with translated nodes. // Alias for the 'The Real McCoy' node in English. - $path_alias = $this->loadPathAliasByConditions(['alias' => '/the-real-mccoy']); $this->assertSame('/node/10', $path_alias->getPath()); $this->assertSame('en', $path_alias->get('langcode')->value); diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeComplete.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeComplete.php index be2d04497648..97beb2de1960 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeComplete.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeComplete.php @@ -62,12 +62,8 @@ public function testTermNode() { $this->assertCount(2, $node->field_vocabulary_2_i_1_); $this->assertSame('2', $node->field_vocabulary_2_i_1_[0]->target_id); $this->assertSame('3', $node->field_vocabulary_2_i_1_[1]->target_id); - } - /** - * Tests the Drupal 6 term-node association to Drupal 8 node revisions. - */ - public function testTermNodeRevision() { + // Tests the Drupal 6 term-node association to Drupal 8 node revisions. $this->executeMigrations(['d6_term_node_revision']); $node = \Drupal::entityTypeManager()->getStorage('node')->loadRevision(2001); diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php index 0855ba095750..ab2afce6e1f5 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -154,49 +154,8 @@ public function testTaxonomyTerms() { // Fixed. $this->assertEntity(24, 'fr', 'FR - Crewman', 'vocabfixed', NULL, NULL, '0', []); - } - - /** - * Retrieves the parent term IDs for a given term. - * - * @param $tid - * ID of the term to check. - * - * @return array - * List of parent term IDs. - */ - protected function getParentIDs($tid) { - return array_keys(\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadParents($tid)); - } - /** - * Assert that a term is present in the tree storage, with the right parents. - * - * @param string $vid - * Vocabulary ID. - * @param int $tid - * ID of the term to check. - * @param array $parent_ids - * The expected parent term IDs. - */ - protected function assertHierarchy($vid, $tid, array $parent_ids) { - if (!isset($this->treeData[$vid])) { - $tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid); - $this->treeData[$vid] = []; - foreach ($tree as $item) { - $this->treeData[$vid][$item->tid] = $item; - } - } - - $this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree"); - $term = $this->treeData[$vid][$tid]; - $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree"); - } - - /** - * Tests the migration of taxonomy term entity translations. - */ - public function testTaxonomyTermEntityTranslations() { + // Tests the migration of taxonomy term entity translations. $manager = $this->container->get('content_translation.manager'); // Get the term and its translations. @@ -245,4 +204,41 @@ public function testTaxonomyTermEntityTranslations() { $this->assertSame($term->parent->terget_id, $term_is->parent->terget_id); } + /** + * Retrieves the parent term IDs for a given term. + * + * @param $tid + * ID of the term to check. + * + * @return array + * List of parent term IDs. + */ + protected function getParentIDs($tid) { + return array_keys(\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadParents($tid)); + } + + /** + * Assert that a term is present in the tree storage, with the right parents. + * + * @param string $vid + * Vocabulary ID. + * @param int $tid + * ID of the term to check. + * @param array $parent_ids + * The expected parent term IDs. + */ + protected function assertHierarchy($vid, $tid, array $parent_ids) { + if (!isset($this->treeData[$vid])) { + $tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid); + $this->treeData[$vid] = []; + foreach ($tree as $item) { + $this->treeData[$vid][$item->tid] = $item; + } + } + + $this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree"); + $term = $this->treeData[$vid][$tid]; + $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree"); + } + } diff --git a/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTest.php b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTest.php index 9c85befcd6fb..1708dbb43e57 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTest.php @@ -46,12 +46,8 @@ public function testUserMail() { $this->assertSame('Account details for [user:name] at [site:name] (blocked)', $config->get('status_blocked.subject')); $this->assertSame("[user:name],\n\nYour account on [site:name] has been blocked.", $config->get('status_blocked.body')); $this->assertConfigSchema(\Drupal::service('config.typed'), 'user.mail', $config->get()); - } - /** - * Tests migration of user variables to user.settings.yml. - */ - public function testUserSettings() { + // Tests migration of user variables to user.settings.yml. $config = $this->config('user.settings'); $this->assertTrue($config->get('notify.status_blocked')); $this->assertFalse($config->get('notify.status_activated')); diff --git a/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserPictureD6FileTest.php b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserPictureD6FileTest.php index 27d2da148545..ffeb2442ba7a 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserPictureD6FileTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserPictureD6FileTest.php @@ -48,6 +48,15 @@ public function testUserPictures() { $this->assertSame('public://image-test.png', $file->getFileUri()); $this->assertSame('8', $file->getOwnerId()); $this->assertEmpty($files); + + // Tests the D6 user pictures migration in combination with D6 file. + $this->setUpMigratedFiles(); + $this->assertEntity(1, 'image-test.jpg', '1901', 'public://image-test.jpg', 'image/jpeg', '2'); + $this->assertEntity(2, 'image-test.png', '125', 'public://image-test.png', 'image/png', '8'); + $this->assertEntity(3, 'Image1.png', '39325', 'public://image-1.png', 'image/png', '1'); + $this->assertEntity(4, 'Image2.jpg', '1831', 'public://image-2.jpg', 'image/jpeg', '1'); + $this->assertEntity(5, 'Image-test.gif', '183', 'public://image-test.gif', 'image/jpeg', '1'); + $this->assertEntity(6, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1'); } /** @@ -77,17 +86,4 @@ protected function assertEntity($fid, $name, $size, $uri, $type, $uid) { $this->assertSame($uid, $file->getOwnerId()); } - /** - * Tests the D6 user pictures migration in combination with D6 file. - */ - public function testUserPicturesWithD6File() { - $this->setUpMigratedFiles(); - $this->assertEntity(1, 'image-test.jpg', '1901', 'public://image-test.jpg', 'image/jpeg', '2'); - $this->assertEntity(2, 'image-test.png', '125', 'public://image-test.png', 'image/png', '8'); - $this->assertEntity(3, 'Image1.png', '39325', 'public://image-1.png', 'image/png', '1'); - $this->assertEntity(4, 'Image2.jpg', '1831', 'public://image-2.jpg', 'image/jpeg', '1'); - $this->assertEntity(5, 'Image-test.gif', '183', 'public://image-test.gif', 'image/jpeg', '1'); - $this->assertEntity(6, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1'); - } - } diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php index 179d80e0c807..8f40bea87ce0 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php @@ -217,12 +217,8 @@ public function testUser() { $user = User::load($source->uid); $this->assertEquals($rehash, $user->getPassword()); } - } - /** - * Tests the Drupal 7 user entity translations to Drupal 8 migration. - */ - public function testUserEntityTranslations() { + // Tests the Drupal 7 user entity translations to Drupal 8 migration. $manager = $this->container->get('content_translation.manager'); // Get the user and its translations. -- GitLab