3 namespace Drupal\Tests\language\Kernel\Migrate\d6;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\migrate\Plugin\MigrationInterface;
7 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
10 * Tests the default language variable migration.
12 * @group migrate_drupal_6
14 class MigrateDefaultLanguageTest extends MigrateDrupal6TestBase {
19 public static $modules = ['language'];
22 * Tests language_default migration with an existing language.
24 public function testMigrationWithExistingLanguage() {
25 $this->setDefaultLanguage('fr');
26 $this->startCollectingMessages();
27 $this->executeMigrations(['language', 'default_language']);
29 // Tests the language is loaded and is the default language.
30 $default_language = ConfigurableLanguage::load('fr');
31 $this->assertNotNull($default_language);
32 $this->assertSame('fr', $this->config('system.site')->get('default_langcode'));
36 * Tests language_default migration with a non-existing language.
38 public function testMigrationWithNonExistentLanguage() {
39 $this->setDefaultLanguage('tv');
40 $this->startCollectingMessages();
41 $this->executeMigrations(['language', 'default_language']);
43 // Tests the migration log contains an error message.
44 $messages = $this->migration->getIdMap()->getMessageIterator();
46 foreach ($messages as $message) {
48 $this->assertSame("The language 'tv' does not exist on this site.", $message->message);
49 $this->assertSame(MigrationInterface::MESSAGE_ERROR, (int) $message->level);
51 $this->assertSame(1, $count);
55 * Tests language_default migration with unset default language variable.
57 public function testMigrationWithUnsetVariable() {
58 // Delete the language_default variable.
59 $this->sourceDatabase->delete('variable')
60 ->condition('name', 'language_default')
62 $this->startCollectingMessages();
63 $this->executeMigrations(['language', 'default_language']);
65 $messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll();
66 // Make sure there's no migration exceptions.
67 $this->assertEmpty($messages);
68 // Make sure the default langcode is 'en', as it was the default on D6 & D7.
69 $this->assertSame('en', $this->config('system.site')->get('default_langcode'));
73 * Helper method to test the migration.
75 * @param string $langcode
76 * The langcode of the default language.
78 protected function setDefaultLanguage($langcode) {
79 // The default language of the test fixture is English. Change it to
80 // something else before migrating, to be sure that the source site
81 // default language is migrated.
82 $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:"";}';
83 $this->sourceDatabase->update('variable')
84 ->fields(['value' => $value])
85 ->condition('name', 'language_default')