diff --git a/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php b/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php index be60ac2..ff5965a 100644 --- a/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php +++ b/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php @@ -7,10 +7,11 @@ namespace Drupal\language\Tests\Migrate\d6; -use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; +use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; /** - * Tests language default variable migration. + * Tests the default language variable migration. * * @group migrate_drupal_6 */ @@ -22,22 +23,40 @@ class MigrateDefaultLanguageTest extends MigrateDrupal6TestBase { public static $modules = ['language']; /** - * Tests migration of the language_default variable to the - * system.site.default_langcode config key. + * Tests the migration of the language_default variable to the + * system.site.default_langcode config key, with an existing language. */ - public function testMigration() { - // The default language of the test fixture is English. Change it to French - // before migrating, to be sure that the source site default language is - // migrated. - $value = 'O:8:"stdClass":11:{s:8:"language";s:2:"fr";s:4:"name";s:6:"French";s:6:"native";s:6:"French";s:9:"direction";s:1:"0";s:7:"enabled";i:1;s:7:"plurals";s:1:"0";s:7:"formula";s:0:"";s:6:"domain";s:0:"";s:6:"prefix";s:0:"";s:6:"weight";s:1:"0";s:10:"javascript";s:0:"";}'; + public function testMigrationWithExistingLanguage() { + $this->doTestMigration('fr'); + } + + /** + * Tests the migration of the language_default variable to the + * system.site.default_langcode config key, with a non-existent language. + */ + public function testMigrationWithNonExistentLanguage() { + $this->doTestMigration('tv'); + } + + /** + * Helper method to test the migration. + */ + protected function doTestMigration($langcode) { + // The default language of the test fixture is English. Change it to + // something else before migrating, to be sure that the source site + // default language is migrated. + $value = 'O:8:"stdClass":11:{s:8:"language";s:2:"' . $langcode . '";s:4:"name";s:6:"French";s:6:"native";s:6:"French";s:9:"direction";s:1:"0";s:7:"enabled";i:1;s:7:"plurals";s:1:"0";s:7:"formula";s:0:"";s:6:"domain";s:0:"";s:6:"prefix";s:0:"";s:6:"weight";s:1:"0";s:10:"javascript";s:0:"";}'; $this->sourceDatabase->update('variable') ->fields(array( 'value' => $value )) ->condition('name', 'language_default' ) ->execute(); + $this->executeMigration('language'); $this->executeMigration('d6_default_language'); - $this->assertIdentical('fr', $this->config('system.site')->get('default_langcode')); + $default_language = ConfigurableLanguage::load($langcode); + $this->assertNotNull($default_language); + $this->assertIdentical($langcode, $this->config('system.site')->get('default_langcode')); } }