diff --git a/core/modules/language/migration_templates/default_language.yml b/core/modules/language/migration_templates/default_language.yml index d7e52adf1072a6f25e5fb4c1b160f400b21d5875..6d7604deed381d80306ef1f20c78379640d1625b 100644 --- a/core/modules/language/migration_templates/default_language.yml +++ b/core/modules/language/migration_templates/default_language.yml @@ -10,9 +10,22 @@ source: process: default_langcode: - - plugin: callback - callable: get_object_vars + plugin: default_value source: language_default + default_value: + 'language': 'en' + # Encode and decode to turn the default_language variable, which is + # an stdClass, into an array so it can be passed to extract. + - + plugin: callback + callable: + - '\Drupal\Component\Serialization\Json' + - 'encode' + - + plugin: callback + callable: + - '\Drupal\Component\Serialization\Json' + - 'decode' - plugin: extract index: diff --git a/core/modules/language/tests/src/Kernel/Migrate/MigrateDefaultLanguageTrait.php b/core/modules/language/tests/src/Kernel/Migrate/MigrateDefaultLanguageTrait.php index deb60206ea2c9f6f95c0c18c099c12acf2dc299a..94bb02d33965d9dab4911fe4da2bbb1d9cee557d 100644 --- a/core/modules/language/tests/src/Kernel/Migrate/MigrateDefaultLanguageTrait.php +++ b/core/modules/language/tests/src/Kernel/Migrate/MigrateDefaultLanguageTrait.php @@ -38,7 +38,7 @@ protected function doTestMigration($langcode, $existing = TRUE) { // default_langcode config should be set. $default_language = ConfigurableLanguage::load($langcode); $this->assertNotNull($default_language); - $this->assertIdentical($langcode, $this->config('system.site')->get('default_langcode')); + $this->assertSame($langcode, $this->config('system.site')->get('default_langcode')); } else { // Otherwise, the migration log should contain an error message. @@ -46,11 +46,31 @@ protected function doTestMigration($langcode, $existing = TRUE) { $count = 0; foreach ($messages as $message) { $count++; - $this->assertEqual($message->message, "The language '$langcode' does not exist on this site."); - $this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR); + $this->assertSame($message->message, "The language '$langcode' does not exist on this site."); + $this->assertSame((int) $message->level, MigrationInterface::MESSAGE_ERROR); } - $this->assertEqual($count, 1); + $this->assertSame($count, 1); } } + /** + * Helper method to test migrating the default language when no default language is set. + */ + protected function doTestMigrationWithUnsetVariable() { + // Delete the language_default variable. + $this->sourceDatabase->delete('variable') + ->condition('name', 'language_default' ) + ->execute(); + + $this->startCollectingMessages(); + $this->executeMigrations(['language', 'default_language']); + $messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll(); + + // Make sure there's no migration exceptions. + $this->assertEmpty($messages); + + // Make sure the default langcode is 'en', since it was the default on D6 & D7. + $this->assertSame('en', $this->config('system.site')->get('default_langcode')); + } + } diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php index 20beb96bf7e3a59cd035397d979a98d2288197f8..645af29fe57b9e3b27ea9f8bbd46dbd03a257090 100644 --- a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php +++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php @@ -33,4 +33,11 @@ public function testMigrationWithNonExistentLanguage() { $this->doTestMigration('tv', FALSE); } + /** + * Tests language_default migration with unset variable. + */ + public function testMigrationWithUnsetVariable() { + $this->doTestMigrationWithUnsetVariable(); + } + } diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php index 0e584e53b2311a056cd8b15931aae0bd971d582f..79769bc00d135d6c7631f0c556711e232b66f9fc 100644 --- a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php +++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php @@ -33,4 +33,11 @@ public function testMigrationWithNonExistentLanguage() { $this->doTestMigration('tv', FALSE); } + /** + * Tests language_default migration with unset variable. + */ + public function testMigrationWithUnsetVariable() { + $this->doTestMigrationWithUnsetVariable(); + } + }