Update to Drupal 8.2.4. For more information, see https://www.drupal.org/project/drupal/releases/8.2.4
This commit is contained in:
parent
0a95b8440e
commit
8544b60b39
284 changed files with 12980 additions and 3199 deletions
|
|
@ -0,0 +1,34 @@
|
|||
id: d6_language_negotiation_settings
|
||||
label: Language negotiation settings
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
- language_negotiation
|
||||
process:
|
||||
session/parameter:
|
||||
plugin: default_value
|
||||
default_value: 'language'
|
||||
selected_langcode:
|
||||
plugin: default_value
|
||||
default_value: 'site_default'
|
||||
url/source:
|
||||
plugin: static_map
|
||||
source: language_negotiation
|
||||
default_value: path_prefix
|
||||
map:
|
||||
# LANGUAGE_NEGOTIATION_NONE = 0
|
||||
# LANGUAGE_NEGOTIATION_PATH_DEFAULT = 1
|
||||
# LANGUAGE_NEGOTIATION_PATH = 2
|
||||
# LANGUAGE_NEGOTIATION_DOMAIN = 3
|
||||
0: path_prefix
|
||||
1: path_prefix
|
||||
2: path_prefix
|
||||
3: domain
|
||||
destination:
|
||||
plugin: config
|
||||
config_name: language.negotiation
|
||||
migration_dependencies:
|
||||
required:
|
||||
- language
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
id: d6_language_types
|
||||
label: Language types
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
- language_negotiation
|
||||
process:
|
||||
all:
|
||||
plugin: default_value
|
||||
default_value:
|
||||
- 'language_interface'
|
||||
- 'language_content'
|
||||
- 'language_url'
|
||||
configurable:
|
||||
plugin: default_value
|
||||
default_value:
|
||||
- 'language_interface'
|
||||
negotiation/language_content/enabled:
|
||||
plugin: default_value
|
||||
default_value:
|
||||
'language-interface': 0
|
||||
negotiation/language_url/enabled:
|
||||
plugin: default_value
|
||||
default_value:
|
||||
'language-url': 0
|
||||
'language-url-fallback': 1
|
||||
negotiation/language_interface/enabled:
|
||||
plugin: static_map
|
||||
source: language_negotiation
|
||||
map:
|
||||
# LANGUAGE_NEGOTIATION_NONE = 0
|
||||
# LANGUAGE_NEGOTIATION_PATH_DEFAULT = 1
|
||||
# LANGUAGE_NEGOTIATION_PATH = 2
|
||||
# LANGUAGE_NEGOTIATION_DOMAIN = 3
|
||||
0:
|
||||
'language-selected': 0
|
||||
1:
|
||||
'language-url': 0
|
||||
'language-selected': 1
|
||||
2:
|
||||
'language-url': 0
|
||||
'language-user': 1
|
||||
'language-browser': 2
|
||||
'language-selected': 3
|
||||
3:
|
||||
'language-url': 0
|
||||
'language-selected': 1
|
||||
destination:
|
||||
plugin: config
|
||||
config_name: language.types
|
||||
|
|
@ -8,8 +8,25 @@ source:
|
|||
- locale_language_negotiation_session_param
|
||||
- locale_language_negotiation_url_part
|
||||
process:
|
||||
'session/parameter': locale_language_negotiation_session_param
|
||||
'url/source': locale_language_negotiation_url_part
|
||||
session/parameter:
|
||||
plugin: default_value
|
||||
source: locale_language_negotiation_session_param
|
||||
default_value: 'language'
|
||||
selected_langcode:
|
||||
plugin: default_value
|
||||
default_value: 'site_default'
|
||||
url/source:
|
||||
plugin: static_map
|
||||
source: locale_language_negotiation_url_part
|
||||
default_value: path_prefix
|
||||
map:
|
||||
# LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX = 0
|
||||
# LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN = 1
|
||||
0: path_prefix
|
||||
1: domain
|
||||
destination:
|
||||
plugin: config
|
||||
config_name: language.negotiation
|
||||
migration_dependencies:
|
||||
required:
|
||||
- language
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
id: d7_language_types
|
||||
label: Language types
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
- language_types
|
||||
- language_negotiation_language
|
||||
- language_negotiation_language_content
|
||||
- language_negotiation_language_url
|
||||
- locale_language_providers_weight_language
|
||||
- locale_language_providers_weight_language_content
|
||||
- locale_language_providers_weight_language_url
|
||||
process:
|
||||
all:
|
||||
plugin: language_types
|
||||
source: language_types
|
||||
configurable:
|
||||
plugin: language_types
|
||||
source: language_types
|
||||
filter_configurable: true
|
||||
negotiation/language_content:
|
||||
plugin: language_negotiation
|
||||
source:
|
||||
- language_negotiation_language_content
|
||||
- locale_language_providers_weight_language_content
|
||||
negotiation/language_url:
|
||||
plugin: language_negotiation
|
||||
source:
|
||||
- language_negotiation_language_url
|
||||
- locale_language_providers_weight_language_url
|
||||
negotiation/language_interface:
|
||||
plugin: language_negotiation
|
||||
source:
|
||||
- language_negotiation_language
|
||||
- locale_language_providers_weight_language
|
||||
destination:
|
||||
plugin: config
|
||||
config_name: language.types
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
id: language_prefixes_and_domains
|
||||
label: Language prefixes and domains
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: language
|
||||
fetch_all: true
|
||||
domain_negotiation: true
|
||||
process:
|
||||
url/prefixes:
|
||||
plugin: array_build
|
||||
source: languages
|
||||
key: language
|
||||
value: prefix
|
||||
url/domains:
|
||||
plugin: language_domains
|
||||
source: languages
|
||||
key: language
|
||||
value: domain
|
||||
destination:
|
||||
plugin: config
|
||||
config_name: language.negotiation
|
||||
migration_dependencies:
|
||||
required:
|
||||
- language
|
||||
|
|
@ -192,6 +192,7 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
*/
|
||||
public function getLanguageSwitchLinks(Request $request, $type, Url $url) {
|
||||
$links = array();
|
||||
$query = $request->query->all();
|
||||
|
||||
foreach ($this->languageManager->getNativeLanguages() as $language) {
|
||||
$links[$language->getId()] = array(
|
||||
|
|
@ -202,6 +203,7 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
'title' => $language->getName(),
|
||||
'language' => $language,
|
||||
'attributes' => array('class' => array('language-link')),
|
||||
'query' => $query,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Plugin\migrate\process;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\ArrayBuild;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This plugin makes sure that no domain is empty if domain negotiation is used.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "language_domains",
|
||||
* handle_multiples = TRUE
|
||||
* )
|
||||
*/
|
||||
class LanguageDomains extends ArrayBuild {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if ($row->getSourceProperty('domain_negotiation')) {
|
||||
global $base_url;
|
||||
|
||||
foreach ($value as $old_key => $old_value) {
|
||||
if (empty($old_value['domain'])) {
|
||||
// The default language domain might be empty.
|
||||
// If it is, use the current domain.
|
||||
$value[$old_key]['domain'] = parse_url($base_url, PHP_URL_HOST);
|
||||
}
|
||||
else {
|
||||
// Ensure we have a protocol when checking for the hostname.
|
||||
$domain = 'http://' . str_replace(['http://', 'https://'], '', $old_value['domain']);
|
||||
// Only keep the host part of the domain.
|
||||
$value[$old_key]['domain'] = parse_url($domain, PHP_URL_HOST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::transform($value, $migrate_executable, $row, $destination_property);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Plugin\migrate\process;
|
||||
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Processes the arrays for the language types' negotiation methods and weights.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "language_negotiation",
|
||||
* handle_multiples = TRUE
|
||||
* )
|
||||
*/
|
||||
class LanguageNegotiation extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$new_value = [
|
||||
'enabled' => [],
|
||||
'method_weights' => [],
|
||||
];
|
||||
|
||||
if (!is_array($value)) {
|
||||
throw new MigrateException('The input should be an array');
|
||||
}
|
||||
|
||||
// If no weights are provided, use the keys by flipping the array.
|
||||
if (empty($value[1])) {
|
||||
$new_value['enabled'] = array_flip(array_map([$this, 'mapNewMethods'], array_keys($value[0])));
|
||||
unset($new_value['method_weights']);
|
||||
}
|
||||
else {
|
||||
foreach ($value[1] as $method => $weight) {
|
||||
$new_method = $this->mapNewMethods($method);
|
||||
$new_value['method_weights'][$new_method] = $weight;
|
||||
if (in_array($method, array_keys($value[0]))) {
|
||||
$new_value['enabled'][$new_method] = $weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps old negotiation method names to the new ones.
|
||||
*
|
||||
* @param string $value
|
||||
* The old negotiation method name.
|
||||
*
|
||||
* @return string
|
||||
* The new negotiation method name.
|
||||
*/
|
||||
protected function mapNewMethods($value) {
|
||||
switch ($value) {
|
||||
case 'language-default':
|
||||
return 'language-selected';
|
||||
case 'locale-browser':
|
||||
return 'language-browser';
|
||||
case 'locale-interface':
|
||||
return 'language-interface';
|
||||
case 'locale-session':
|
||||
return 'language-session';
|
||||
case 'locale-url':
|
||||
return 'language-url';
|
||||
case 'locale-url-fallback':
|
||||
return 'language-url-fallback';
|
||||
case 'locale-user':
|
||||
return 'language-user';
|
||||
default:
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\language\Plugin\migrate\process;
|
||||
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Processes the array for the language types.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "language_types",
|
||||
* handle_multiples = TRUE
|
||||
* )
|
||||
*/
|
||||
class LanguageTypes extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if (!is_array($value)) {
|
||||
throw new MigrateException('The input should be an array');
|
||||
}
|
||||
|
||||
if (array_key_exists('language', $value)) {
|
||||
$value['language_interface'] = $value['language'];
|
||||
unset($value['language']);
|
||||
}
|
||||
|
||||
if (!empty($this->configuration['filter_configurable'])) {
|
||||
$value = array_filter($value);
|
||||
}
|
||||
|
||||
return array_keys($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\language\Plugin\migrate\source;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
|
|
@ -49,4 +50,27 @@ class Language extends DrupalSqlBase {
|
|||
return $this->select('languages')->fields('languages');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
if (!empty($this->configuration['fetch_all'])) {
|
||||
// Get an array of all languages.
|
||||
$languages = $this->query()->execute()->fetchAll();
|
||||
$row->setSourceProperty('languages', $languages);
|
||||
}
|
||||
|
||||
if (!empty($this->configuration['domain_negotiation'])) {
|
||||
// Check if domain negotiation is used to be able to fill in the default
|
||||
// language domain, which may be empty. In D6, domain negotiation is used
|
||||
// when the 'language_negotiation' variable is set to '3', and in D7, when
|
||||
// the 'locale_language_negotiation_url_part' variable is set to '1'.
|
||||
if ($this->variableGet('language_negotiation', 0) == 3 || $this->variableGet('locale_language_negotiation_url_part', 0) == 1) {
|
||||
$row->setSourceProperty('domain_negotiation', TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,8 +118,9 @@ class LanguageSwitchingTest extends WebTestBase {
|
|||
protected function doTestLanguageBlockAnonymous($block_label) {
|
||||
$this->drupalLogout();
|
||||
|
||||
// Assert that the language switching block is displayed on the frontpage.
|
||||
$this->drupalGet('');
|
||||
// Assert that the language switching block is displayed on the frontpage
|
||||
// and ensure that the active class is added when query params are present.
|
||||
$this->drupalGet('', ['query' => ['foo' => 'bar']]);
|
||||
$this->assertText($block_label, 'Language switcher block found.');
|
||||
|
||||
// Assert that only the current language is marked as active.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration of language negotiation and language types.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests the migration with LANGUAGE_NEGOTIATION_PATH_DEFAULT.
|
||||
*/
|
||||
public function testLanguageNegotiationWithDefaultPathPrefix() {
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
'd6_language_types',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_prefixes = [
|
||||
'en' => '',
|
||||
'fr' => 'fr',
|
||||
'zu' => 'zu',
|
||||
];
|
||||
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_interface', 'language_content', 'language_url']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content.enabled'), ['language-interface' => 0]);
|
||||
$this->assertSame($config->get('negotiation.language_url.enabled'), ['language-url' => 0, 'language-url-fallback' => 1]);
|
||||
$expected_language_interface = [
|
||||
'language-url' => 0,
|
||||
'language-selected' => 1,
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with LANGUAGE_NEGOTIATION_NONE.
|
||||
*/
|
||||
public function testLanguageNegotiationWithNoNegotiation() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(0)))
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
'd6_language_types',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_interface', 'language_content', 'language_url']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content.enabled'), ['language-interface' => 0]);
|
||||
$this->assertSame($config->get('negotiation.language_url.enabled'), ['language-url' => 0, 'language-url-fallback' => 1]);
|
||||
$expected_language_interface = [
|
||||
'language-selected' => 0,
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with LANGUAGE_NEGOTIATION_PATH.
|
||||
*/
|
||||
public function testLanguageNegotiationWithPathPrefix() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(2)))
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
'd6_language_types',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_prefixes = [
|
||||
'en' => '',
|
||||
'fr' => 'fr',
|
||||
'zu' => 'zu',
|
||||
];
|
||||
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_interface', 'language_content', 'language_url']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content.enabled'), ['language-interface' => 0]);
|
||||
$this->assertSame($config->get('negotiation.language_url.enabled'), ['language-url' => 0, 'language-url-fallback' => 1]);
|
||||
$expected_language_interface = [
|
||||
'language-url' => 0,
|
||||
'language-user' => 1,
|
||||
'language-browser' => 2,
|
||||
'language-selected' => 3,
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with LANGUAGE_NEGOTIATION_DOMAIN.
|
||||
*/
|
||||
public function testLanguageNegotiationWithDomain() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(3)))
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
'd6_language_types',
|
||||
]);
|
||||
|
||||
global $base_url;
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_DOMAIN);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_domains = [
|
||||
'en' => parse_url($base_url, PHP_URL_HOST),
|
||||
'fr' => 'fr.drupal.org',
|
||||
'zu' => 'zu.drupal.org',
|
||||
];
|
||||
$this->assertSame($config->get('url.domains'), $expected_domains);
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_interface', 'language_content', 'language_url']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content.enabled'), ['language-interface' => 0]);
|
||||
$this->assertSame($config->get('negotiation.language_url.enabled'), ['language-url' => 0, 'language-url-fallback' => 1]);
|
||||
$expected_language_interface = [
|
||||
'language-url' => 0,
|
||||
'language-selected' => 1,
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,37 +2,124 @@
|
|||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of language negotiation variables.
|
||||
* Tests the migration of language negotiation.
|
||||
*
|
||||
* @group language
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Tests migration of language types variables to language.types.yml.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d7_language_negotiation_settings');
|
||||
public function testLanguageTypes() {
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_language_negotiation_settings',
|
||||
'd7_language_types',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.types');
|
||||
$this->assertSame($config->get('all'), ['language_content', 'language_url', 'language_interface']);
|
||||
$this->assertSame($config->get('configurable'), ['language_interface']);
|
||||
$this->assertSame($config->get('negotiation.language_content'), ['enabled' => ['language-interface' => 0]]);
|
||||
$this->assertSame($config->get('negotiation.language_url'), ['enabled' => ['language-url' => 0, 'language-url-fallback' => 1]]);
|
||||
$expected_language_interface = [
|
||||
'enabled' => [
|
||||
'language-url' => -9,
|
||||
'language-user' => -10,
|
||||
'language-selected' => -6,
|
||||
],
|
||||
'method_weights' => [
|
||||
'language-url' => -9,
|
||||
'language-session' => -8,
|
||||
'language-user' => -10,
|
||||
'language-browser' => -7,
|
||||
'language-selected' => -6,
|
||||
],
|
||||
];
|
||||
$this->assertSame($config->get('negotiation.language_interface'), $expected_language_interface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of language negotiation variables to language.negotiation.yml.
|
||||
* Tests the migration with prefix negotiation.
|
||||
*/
|
||||
public function testLanguageNegotiation() {
|
||||
public function testLanguageNegotiationWithPrefix() {
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertIdentical($config->get('session.parameter'), 'language');
|
||||
$this->assertIdentical($config->get('url.source'), 'domain');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_prefixes = [
|
||||
'en' => '',
|
||||
'is' => 'is',
|
||||
];
|
||||
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with domain negotiation.
|
||||
*/
|
||||
public function testLanguageNegotiationWithDomain() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(1)))
|
||||
->condition('name', 'locale_language_negotiation_url_part')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
]);
|
||||
|
||||
global $base_url;
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_DOMAIN);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_domains = [
|
||||
'en' => parse_url($base_url, PHP_URL_HOST),
|
||||
'is' => 'is.drupal.org',
|
||||
];
|
||||
$this->assertSame($config->get('url.domains'), $expected_domains);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with non-existent variables.
|
||||
*/
|
||||
public function testLanguageNegotiationWithNonExistentVariables() {
|
||||
$this->sourceDatabase->delete('variable')
|
||||
->condition('name', ['local_language_negotiation_url_part', 'local_language_negotiation_session_param'], 'IN')
|
||||
->execute();
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_negotiation_settings',
|
||||
'language_prefixes_and_domains',
|
||||
]);
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$this->assertSame($config->get('session.parameter'), 'language');
|
||||
$this->assertSame($config->get('url.source'), LanguageNegotiationUrl::CONFIG_PATH_PREFIX);
|
||||
$this->assertSame($config->get('selected_langcode'), 'site_default');
|
||||
$expected_prefixes = [
|
||||
'en' => '',
|
||||
'is' => 'is',
|
||||
];
|
||||
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\process;
|
||||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageDomains;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageDomains
|
||||
* @group language
|
||||
*/
|
||||
class LanguageDomainsTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $backupGlobalsBlacklist = ['base_url'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$configuration = [
|
||||
'key' => 'language',
|
||||
'value' => 'domain',
|
||||
];
|
||||
$this->plugin = new LanguageDomains($configuration, 'map', []);
|
||||
parent::setUp();
|
||||
|
||||
// The language_domains plugin calls getSourceProperty() to check if domain
|
||||
// negotiation is used. If it is the values will be processed so we need it
|
||||
// to return TRUE to be able to test the process.
|
||||
$this->row->expects($this->once())
|
||||
->method('getSourceProperty')
|
||||
->will($this->returnValue(TRUE));
|
||||
|
||||
// The language_domains plugin use $base_url to fill empty domains.
|
||||
global $base_url;
|
||||
$base_url = 'http://example.com';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::transform
|
||||
*/
|
||||
public function testTransform() {
|
||||
$source = [
|
||||
['language' => 'en', 'domain' => ''],
|
||||
['language' => 'fr', 'domain' => 'fr.example.com'],
|
||||
['language' => 'es', 'domain' => 'http://es.example.com'],
|
||||
['language' => 'hu', 'domain' => 'https://hu.example.com'],
|
||||
];
|
||||
$expected = [
|
||||
'en' => 'example.com',
|
||||
'fr' => 'fr.example.com',
|
||||
'es' => 'es.example.com',
|
||||
'hu' => 'hu.example.com',
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\process;
|
||||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageNegotiation;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageNegotiation
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new LanguageNegotiation([], 'map', []);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests successful transformation without weights.
|
||||
*/
|
||||
public function testTransformWithWeights() {
|
||||
$source = [
|
||||
[
|
||||
'locale-url' => [],
|
||||
'language-default' => [],
|
||||
],
|
||||
[
|
||||
'locale-url' => -10,
|
||||
'locale-session' => -9,
|
||||
'locale-user' => -8,
|
||||
'locale-browser' => -7,
|
||||
'language-default' => -6,
|
||||
],
|
||||
];
|
||||
$expected = [
|
||||
'enabled' => [
|
||||
'language-url' => -10,
|
||||
'language-selected' => -6,
|
||||
],
|
||||
'method_weights' => [
|
||||
'language-url' => -10,
|
||||
'language-session' => -9,
|
||||
'language-user' => -8,
|
||||
'language-browser' => -7,
|
||||
'language-selected' => -6,
|
||||
],
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests successful transformation without weights.
|
||||
*/
|
||||
public function testTransformWithoutWeights() {
|
||||
$source = [
|
||||
[
|
||||
'locale-url' => [],
|
||||
'locale-url-fallback' => [],
|
||||
],
|
||||
];
|
||||
$expected = [
|
||||
'enabled' => [
|
||||
'language-url' => 0,
|
||||
'language-url-fallback' => 1,
|
||||
],
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests string input.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The input should be an array
|
||||
*/
|
||||
public function testStringInput() {
|
||||
$this->plugin = new LanguageNegotiation([], 'map', []);
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\process;
|
||||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageTypes;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageTypes
|
||||
* @group language
|
||||
*/
|
||||
class LanguageTypesTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* Tests successful transformation of all language types.
|
||||
*/
|
||||
public function testTransformAll() {
|
||||
$this->plugin = new LanguageTypes([], 'map', []);
|
||||
$source = [
|
||||
'language' => TRUE,
|
||||
'language_url' => FALSE,
|
||||
'language_content' => FALSE,
|
||||
];
|
||||
$expected = [
|
||||
0 => 'language_url',
|
||||
1 => 'language_content',
|
||||
2 => 'language_interface',
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests successful transformation of configurable language types.
|
||||
*/
|
||||
public function testTransformConfigurable() {
|
||||
$this->plugin = new LanguageTypes(['filter_configurable' => TRUE], 'map', []);
|
||||
$source = [
|
||||
'language' => TRUE,
|
||||
'language_url' => FALSE,
|
||||
'language_content' => FALSE,
|
||||
];
|
||||
$expected = [
|
||||
0 => 'language_interface',
|
||||
];
|
||||
$value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests string input.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The input should be an array
|
||||
*/
|
||||
public function testStringInput() {
|
||||
$this->plugin = new LanguageTypes([], 'map', []);
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue