3 namespace Drupal\Tests\language\Kernel\Migrate\d7;
5 use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
6 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
9 * Tests the migration of language negotiation.
11 * @group migrate_drupal_7
13 class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
18 public static $modules = ['language'];
21 * Tests migration of language types variables to language.types.yml.
23 public function testLanguageTypes() {
24 $this->executeMigrations([
26 'd7_language_negotiation_settings',
30 $config = $this->config('language.types');
31 $this->assertSame(['language_content', 'language_url', 'language_interface'], $config->get('all'));
32 $this->assertSame(['language_interface'], $config->get('configurable'));
33 $this->assertSame(['enabled' => ['language-interface' => 0]], $config->get('negotiation.language_content'));
34 $this->assertSame(['enabled' => ['language-url' => 0, 'language-url-fallback' => 1]], $config->get('negotiation.language_url'));
35 $expected_language_interface = [
38 'language-user' => -10,
39 'language-selected' => -6,
43 'language-session' => -8,
44 'language-user' => -10,
45 'language-browser' => -7,
46 'language-selected' => -6,
49 $this->assertSame($expected_language_interface, $config->get('negotiation.language_interface'));
53 * Tests the migration with prefix negotiation.
55 public function testLanguageNegotiationWithPrefix() {
56 $this->sourceDatabase->update('languages')
57 ->fields(['domain' => ''])
60 $this->executeMigrations([
62 'd7_language_negotiation_settings',
63 'language_prefixes_and_domains',
66 $config = $this->config('language.negotiation');
67 $this->assertSame('language', $config->get('session.parameter'));
68 $this->assertSame(LanguageNegotiationUrl::CONFIG_PATH_PREFIX, $config->get('url.source'));
69 $this->assertSame('site_default', $config->get('selected_langcode'));
70 $expected_prefixes = [
75 $this->assertSame($expected_prefixes, $config->get('url.prefixes'));
77 // If prefix negotiation is used, make sure that no domains are migrated.
78 // Otherwise there will be validation errors when trying to save URL
79 // language detection configuration from the UI.
85 $this->assertSame($expected_domains, $config->get('url.domains'));
89 * Tests the migration with domain negotiation.
91 public function testLanguageNegotiationWithDomain() {
92 $this->sourceDatabase->update('variable')
93 ->fields(['value' => serialize(1)])
94 ->condition('name', 'locale_language_negotiation_url_part')
97 $this->executeMigrations([
99 'd7_language_negotiation_settings',
100 'language_prefixes_and_domains',
104 $config = $this->config('language.negotiation');
105 $this->assertSame('language', $config->get('session.parameter'));
106 $this->assertSame(LanguageNegotiationUrl::CONFIG_DOMAIN, $config->get('url.source'));
107 $this->assertSame('site_default', $config->get('selected_langcode'));
108 $expected_domains = [
109 'en' => parse_url($base_url, PHP_URL_HOST),
110 'fr' => 'fr.drupal.org',
111 'is' => 'is.drupal.org',
113 $this->assertSame($expected_domains, $config->get('url.domains'));
117 * Tests the migration with non-existent variables.
119 public function testLanguageNegotiationWithNonExistentVariables() {
120 $this->sourceDatabase->delete('variable')
121 ->condition('name', ['local_language_negotiation_url_part', 'local_language_negotiation_session_param'], 'IN')
124 $this->executeMigrations([
126 'd6_language_negotiation_settings',
127 'language_prefixes_and_domains',
130 $config = $this->config('language.negotiation');
131 $this->assertSame('language', $config->get('session.parameter'));
132 $this->assertSame(LanguageNegotiationUrl::CONFIG_PATH_PREFIX, $config->get('url.source'));
133 $this->assertSame('site_default', $config->get('selected_langcode'));
134 $expected_prefixes = [
139 $this->assertSame($expected_prefixes, $config->get('url.prefixes'));