MigrateDefaultLanguageTest.php in Drupal 10
File
core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php
View source
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d7;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
class MigrateDefaultLanguageTest extends MigrateDrupal7TestBase {
protected static $modules = [
'language',
];
public function testMigrationWithExistingLanguage() {
$this
->setDefaultLanguage('is');
$this
->startCollectingMessages();
$this
->executeMigrations([
'language',
'default_language',
]);
$default_language = ConfigurableLanguage::load('is');
$this
->assertNotNull($default_language);
$this
->assertSame('is', $this
->config('system.site')
->get('default_langcode'));
}
public function testMigrationWithNonExistentLanguage() {
$this
->setDefaultLanguage('tv');
$this
->startCollectingMessages();
$this
->executeMigrations([
'language',
'default_language',
]);
$messages = $this->migration
->getIdMap()
->getMessages();
$count = 0;
foreach ($messages as $message) {
$count++;
$this
->assertSame("The language 'tv' does not exist on this site.", $message->message);
$this
->assertSame(MigrationInterface::MESSAGE_ERROR, (int) $message->level);
}
$this
->assertSame(1, $count);
}
public function testMigrationWithUnsetVariable() {
$this->sourceDatabase
->delete('variable')
->condition('name', 'language_default')
->execute();
$this
->startCollectingMessages();
$this
->executeMigrations([
'language',
'default_language',
]);
$messages = $this->migration
->getIdMap()
->getMessages()
->fetchAll();
$this
->assertEmpty($messages);
$this
->assertSame('en', $this
->config('system.site')
->get('default_langcode'));
}
protected function setDefaultLanguage($langcode) {
$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([
'value' => $value,
])
->condition('name', 'language_default')
->execute();
}
}