first commit
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
name: 'Deutsch'
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
name: 'Language config overridetest'
|
||||
type: module
|
||||
description: 'Support module for the language config override test.'
|
||||
# core: 8.x
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-19
|
||||
version: '8.3.1'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1492622988
|
||||
@@ -0,0 +1,14 @@
|
||||
name: 'Language form elements test'
|
||||
type: module
|
||||
description: 'Support module for the language form elements tests.'
|
||||
# core: 8.x
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
dependencies:
|
||||
- entity_test
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-19
|
||||
version: '8.3.1'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1492622988
|
||||
@@ -0,0 +1,15 @@
|
||||
language_elements_test.config_element:
|
||||
path: '/language-tests/language_configuration_element'
|
||||
defaults:
|
||||
_form: '\Drupal\language_elements_test\Form\LanguageConfigurationElement'
|
||||
_title: 'Language configuration form element'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
language_elements_test.config_element_test:
|
||||
path: '/language-tests/language_configuration_element_test'
|
||||
defaults:
|
||||
_form: '\Drupal\language_elements_test\Form\LanguageConfigurationElementTest'
|
||||
_title: 'Language configuration form element'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\language_elements_test\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
|
||||
/**
|
||||
* A form containing a language configuration element.
|
||||
*/
|
||||
class LanguageConfigurationElement extends FormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'language_elements_configuration_element';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle');
|
||||
|
||||
$form['lang_configuration'] = [
|
||||
'#type' => 'language_configuration',
|
||||
'#entity_information' => [
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'some_bundle',
|
||||
],
|
||||
'#default_value' => $conf,
|
||||
];
|
||||
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Save',
|
||||
];
|
||||
$form['#submit'][] = 'language_configuration_element_submit';
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\language_elements_test\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* A form containing a language select element.
|
||||
*/
|
||||
class LanguageConfigurationElementTest extends FormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'language_elements_configuration_element_test';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['langcode'] = [
|
||||
'#title' => t('Language select'),
|
||||
'#type' => 'language_select',
|
||||
'#default_value' => language_get_default_langcode('entity_test', 'some_bundle'),
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
}
|
||||
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- language_test
|
||||
id: no_entity_translation_view
|
||||
label: 'No Entity Translation View'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: no_language_entity_test
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: full
|
||||
options:
|
||||
items_per_page: 10
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
first: '« First'
|
||||
last: 'Last »'
|
||||
quantity: 9
|
||||
style:
|
||||
type: default
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
default_field_elements: true
|
||||
inline:
|
||||
operations: operations
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
fields:
|
||||
uuid:
|
||||
id: uuid
|
||||
table: no_language_entity_test
|
||||
field: uuid
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings:
|
||||
link_to_entity: false
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
entity_type: no_language_entity_test
|
||||
entity_field: uuid
|
||||
plugin_id: field
|
||||
filters: { }
|
||||
sorts: { }
|
||||
title: 'No Entity Translation View'
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
||||
page_1:
|
||||
display_plugin: page
|
||||
id: page_1
|
||||
display_title: Page
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
path: no-entity-translation-view
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
||||
@@ -0,0 +1,12 @@
|
||||
name: 'Language test'
|
||||
type: module
|
||||
description: 'Support module for the language layer tests.'
|
||||
# core: 8.x
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-19
|
||||
version: '8.3.1'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1492622988
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Mock module for language layer tests.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
|
||||
|
||||
/**
|
||||
* Implements hook_page_top().
|
||||
*/
|
||||
function language_test_page_top() {
|
||||
if (\Drupal::moduleHandler()->moduleExists('language')) {
|
||||
language_test_store_language_negotiation();
|
||||
drupal_set_message(t('Language negotiation method: @name', ['@name' => \Drupal::languageManager()->getNegotiatedLanguageMethod()]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_types_info().
|
||||
*/
|
||||
function language_test_language_types_info() {
|
||||
if (\Drupal::state()->get('language_test.language_types')) {
|
||||
return [
|
||||
'test_language_type' => [
|
||||
'name' => t('Test'),
|
||||
'description' => t('A test language type.'),
|
||||
],
|
||||
'fixed_test_language_type' => [
|
||||
'fixed' => ['test_language_negotiation_method'],
|
||||
'locked' => TRUE,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_types_info_alter().
|
||||
*/
|
||||
function language_test_language_types_info_alter(array &$language_types) {
|
||||
if (\Drupal::state()->get('language_test.content_language_type')) {
|
||||
$language_types[LanguageInterface::TYPE_CONTENT]['locked'] = FALSE;
|
||||
unset($language_types[LanguageInterface::TYPE_CONTENT]['fixed']);
|
||||
// By default languages are not configurable. Make
|
||||
// LanguageInterface::TYPE_CONTENT configurable.
|
||||
$config = \Drupal::configFactory()->getEditable('language.types');
|
||||
$configurable = $config->get('configurable');
|
||||
if (!in_array(LanguageInterface::TYPE_CONTENT, $configurable)) {
|
||||
$configurable[] = LanguageInterface::TYPE_CONTENT;
|
||||
$config->set('configurable', $configurable)->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_negotiation_info_alter().
|
||||
*/
|
||||
function language_test_language_negotiation_info_alter(array &$negotiation_info) {
|
||||
if (\Drupal::state()->get('language_test.language_negotiation_info_alter')) {
|
||||
unset($negotiation_info[LanguageNegotiationUI::METHOD_ID]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the last negotiated languages.
|
||||
*/
|
||||
function language_test_store_language_negotiation() {
|
||||
$last = [];
|
||||
foreach (\Drupal::languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$last[$type] = \Drupal::languageManager()->getCurrentLanguage($type)->getId();
|
||||
}
|
||||
\Drupal::state()->set('language_test.language_negotiation_last', $last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_fallback_candidates_alter().
|
||||
*/
|
||||
function language_test_language_fallback_candidates_alter(array &$candidates, array $context) {
|
||||
if (Drupal::state()->get('language_test.fallback_alter.candidates')) {
|
||||
unset($candidates[LanguageInterface::LANGCODE_NOT_SPECIFIED]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_fallback_candidates_OPERATION_alter().
|
||||
*/
|
||||
function language_test_language_fallback_candidates_test_alter(array &$candidates, array $context) {
|
||||
if (Drupal::state()->get('language_test.fallback_operation_alter.candidates')) {
|
||||
$langcode = LanguageInterface::LANGCODE_NOT_APPLICABLE;
|
||||
$candidates[$langcode] = $langcode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_module_preinstall().
|
||||
*/
|
||||
function language_test_module_preinstall() {
|
||||
\Drupal::state()->set('language_test.language_count_preinstall', count(\Drupal::languageManager()->getLanguages()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_switch_links_alter().
|
||||
*/
|
||||
function language_test_language_switch_links_alter(array &$links, $type, Url $url) {
|
||||
// I'll just sit here and wait to be called with the right arguments.
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
language_test.l_active_class:
|
||||
path: '/language_test/type-link-active-class'
|
||||
defaults:
|
||||
_controller: '\Drupal\language_test\Controller\LanguageTestController::typeLinkActiveClass'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
language_test.subrequest:
|
||||
path: '/language_test/subrequest'
|
||||
defaults:
|
||||
_controller: '\Drupal\language_test\Controller\LanguageTestController::testSubRequest'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
language_test.entity_using_original_language:
|
||||
path: '/admin/language_test/entity_using_original_language/{configurable_language}'
|
||||
defaults:
|
||||
_controller: '\Drupal\language_test\Controller\LanguageTestController::testEntity'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
language_test.entity_using_current_language:
|
||||
path: '/admin/language_test/entity_using_current_language/{configurable_language}'
|
||||
defaults:
|
||||
_controller: '\Drupal\language_test\Controller\LanguageTestController::testEntity'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
options:
|
||||
parameters:
|
||||
configurable_language:
|
||||
type: entity:configurable_language
|
||||
# Force load in the interface text language selected for page.
|
||||
with_config_overrides: TRUE
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\language_test\Controller;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\ConfigurableLanguageInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* Controller routines for language_test routes.
|
||||
*/
|
||||
class LanguageTestController implements ContainerInjectionInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The HTTP kernel service.
|
||||
*
|
||||
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
|
||||
*/
|
||||
protected $httpKernel;
|
||||
|
||||
/**
|
||||
* The language manager service.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new LanguageTestController object.
|
||||
*
|
||||
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel
|
||||
* An HTTP kernel.
|
||||
*/
|
||||
public function __construct(HttpKernelInterface $httpKernel, LanguageManagerInterface $language_manager) {
|
||||
$this->httpKernel = $httpKernel;
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('http_kernel'), $container->get('language_manager'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Route entity upcasting test helper.
|
||||
*
|
||||
* @param \Drupal\language\ConfigurableLanguageInterface $language
|
||||
* The ConfigurableLanguage object from the route.
|
||||
*
|
||||
* @return string
|
||||
* Testing feedback based on (translated) entity title.
|
||||
*/
|
||||
public function testEntity(ConfigurableLanguageInterface $configurable_language) {
|
||||
return ['#markup' => $this->t('Loaded %label.', ['%label' => $configurable_language->label()])];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns links to the current page with different langcodes.
|
||||
*
|
||||
* Using #type 'link' causes these links to be rendered with the link
|
||||
* generator.
|
||||
*/
|
||||
public function typeLinkActiveClass() {
|
||||
// We assume that 'en' and 'fr' have been configured.
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
return [
|
||||
'no_language' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to the current path with no langcode provided.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => [
|
||||
'attributes' => [
|
||||
'id' => 'no_lang_link',
|
||||
],
|
||||
'set_active_class' => TRUE,
|
||||
],
|
||||
],
|
||||
'fr' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to a French version of the current path.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => [
|
||||
'language' => $languages['fr'],
|
||||
'attributes' => [
|
||||
'id' => 'fr_link',
|
||||
],
|
||||
'set_active_class' => TRUE,
|
||||
],
|
||||
],
|
||||
'en' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to an English version of the current path.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => [
|
||||
'language' => $languages['en'],
|
||||
'attributes' => [
|
||||
'id' => 'en_link',
|
||||
],
|
||||
'set_active_class' => TRUE,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a sub request to retrieve the 'user' page.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* The kernels response to the sub request.
|
||||
*/
|
||||
public function testSubRequest() {
|
||||
$request = Request::createFromGlobals();
|
||||
$server = $request->server->all();
|
||||
if (basename($server['SCRIPT_FILENAME']) != basename($server['SCRIPT_NAME'])) {
|
||||
// We need this for when the test is executed by run-tests.sh.
|
||||
// @todo Remove this once run-tests.sh has been converted to use a Request
|
||||
// object.
|
||||
$server['SCRIPT_FILENAME'] = $server['SCRIPT_NAME'];
|
||||
$base_path = ltrim($server['REQUEST_URI'], '/');
|
||||
}
|
||||
else {
|
||||
$base_path = $request->getBasePath();
|
||||
}
|
||||
$sub_request = Request::create($base_path . '/user', 'GET', $request->query->all(), $request->cookies->all(), [], $server);
|
||||
return $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\language_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
|
||||
/**
|
||||
* Defines the test entity class.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "no_language_entity_test",
|
||||
* label = @Translation("Test entity without language support"),
|
||||
* handlers = {
|
||||
* "views_data" = "Drupal\entity_test\EntityTestViewsData"
|
||||
* },
|
||||
* base_table = "no_language_entity_test",
|
||||
* persistent_cache = FALSE,
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class NoLanguageEntityTest extends ContentEntityBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields['id'] = BaseFieldDefinition::create('integer')
|
||||
->setLabel(t('ID'))
|
||||
->setDescription(t('The ID of the test entity.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setSetting('unsigned', TRUE);
|
||||
|
||||
$fields['uuid'] = BaseFieldDefinition::create('uuid')
|
||||
->setLabel(t('UUID'))
|
||||
->setDescription(t('The UUID of the test entity.'))
|
||||
->setReadOnly(TRUE);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\language_test\Plugin\LanguageNegotiation;
|
||||
|
||||
use Drupal\language\LanguageNegotiationMethodBase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Class for identifying language from a selected language.
|
||||
*
|
||||
* @LanguageNegotiation(
|
||||
* id = "test_language_negotiation_method",
|
||||
* weight = -10,
|
||||
* name = @Translation("Test"),
|
||||
* description = @Translation("This is a test language negotiation method."),
|
||||
* types = {Drupal\Core\Language\LanguageInterface::TYPE_CONTENT,
|
||||
* "test_language_type", "fixed_test_language_type"}
|
||||
* )
|
||||
*/
|
||||
class LanguageNegotiationTest extends LanguageNegotiationMethodBase {
|
||||
|
||||
/**
|
||||
* The language negotiation method id.
|
||||
*/
|
||||
const METHOD_ID = 'test_language_negotiation_method';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLangcode(Request $request = NULL) {
|
||||
return 'it';
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\language_test\Plugin\LanguageNegotiation;
|
||||
|
||||
/**
|
||||
* Class for identifying language from a selected language.
|
||||
*
|
||||
* @LanguageNegotiation(
|
||||
* id = "test_language_negotiation_method_ts",
|
||||
* weight = -10,
|
||||
* name = @Translation("Type-specific test"),
|
||||
* description = @Translation("This is a test language negotiation method."),
|
||||
* types = {"test_language_type"}
|
||||
* )
|
||||
*/
|
||||
class LanguageNegotiationTestTs extends LanguageNegotiationTest {
|
||||
|
||||
/**
|
||||
* The language negotiation method id.
|
||||
*/
|
||||
const METHOD_ID = 'test_language_negotiation_method_ts';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Test administration path based conversion of entities.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class AdminPathEntityConverterLanguageTest extends BrowserTestBase {
|
||||
|
||||
public static $modules = ['language', 'language_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$permissions = [
|
||||
'access administration pages',
|
||||
'administer site configuration',
|
||||
];
|
||||
$this->drupalLogin($this->drupalCreateUser($permissions));
|
||||
ConfigurableLanguage::createFromLangcode('es')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the translated and untranslated config entities are loaded properly.
|
||||
*/
|
||||
public function testConfigUsingCurrentLanguage() {
|
||||
\Drupal::languageManager()
|
||||
->getLanguageConfigOverride('es', 'language.entity.es')
|
||||
->set('label', 'Español')
|
||||
->save();
|
||||
|
||||
$this->drupalGet('es/admin/language_test/entity_using_current_language/es');
|
||||
$this->assertNoRaw(t('Loaded %label.', ['%label' => 'Spanish']));
|
||||
$this->assertRaw(t('Loaded %label.', ['%label' => 'Español']));
|
||||
|
||||
$this->drupalGet('es/admin/language_test/entity_using_original_language/es');
|
||||
$this->assertRaw(t('Loaded %label.', ['%label' => 'Spanish']));
|
||||
$this->assertNoRaw(t('Loaded %label.', ['%label' => 'Español']));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the language settings on block config appears correctly.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageBlockSettingsVisibilityTest extends BrowserTestBase {
|
||||
|
||||
public static $modules = ['block', 'language'];
|
||||
|
||||
public function testUnnecessaryLanguageSettingsVisibility() {
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer blocks']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'hu'], t('Add language'));
|
||||
$this->drupalGet('admin/structure/block/add/system_menu_block:admin/stark');
|
||||
$this->assertNoFieldByXPath('//input[@id="edit-visibility-language-langcodes-und"]', NULL, '\'Not specified\' option does not appear at block config, language settings section.');
|
||||
$this->assertNoFieldByXpath('//input[@id="edit-visibility-language-langcodes-zxx"]', NULL, '\'Not applicable\' option does not appear at block config, language settings section.');
|
||||
$this->assertFieldByXPath('//input[@id="edit-visibility-language-langcodes-en"]', NULL, '\'English\' option appears at block config, language settings section.');
|
||||
$this->assertFieldByXpath('//input[@id="edit-visibility-language-langcodes-hu"]', NULL, '\'Hungarian\' option appears at block config, language settings section.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests browser language detection.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageBrowserDetectionTest extends BrowserTestBase {
|
||||
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests for adding, editing and deleting mappings between browser language
|
||||
* codes and Drupal language codes.
|
||||
*/
|
||||
public function testUIBrowserLanguageMappings() {
|
||||
// User to manage languages.
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Check that the configure link exists.
|
||||
$this->drupalGet('admin/config/regional/language/detection');
|
||||
$this->assertLinkByHref('admin/config/regional/language/detection/browser');
|
||||
|
||||
// Check that defaults are loaded from language.mappings.yml.
|
||||
$this->drupalGet('admin/config/regional/language/detection/browser');
|
||||
$this->assertField('edit-mappings-zh-cn-browser-langcode', 'zh-cn', 'Chinese browser language code found.');
|
||||
$this->assertField('edit-mappings-zh-cn-drupal-langcode', 'zh-hans-cn', 'Chinese Drupal language code found.');
|
||||
|
||||
// Delete zh-cn language code.
|
||||
$browser_langcode = 'zh-cn';
|
||||
$this->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode);
|
||||
$message = t('Are you sure you want to delete @browser_langcode?', [
|
||||
'@browser_langcode' => $browser_langcode,
|
||||
]);
|
||||
$this->assertRaw($message);
|
||||
|
||||
// Confirm the delete.
|
||||
$edit = [];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm'));
|
||||
|
||||
// We need raw here because %browser will add HTML.
|
||||
$t_args = [
|
||||
'%browser' => $browser_langcode,
|
||||
];
|
||||
$this->assertRaw(t('The mapping for the %browser browser language code has been deleted.', $t_args), 'The test browser language code has been deleted.');
|
||||
|
||||
// Check we went back to the browser negotiation mapping overview.
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
// Check that ch-zn no longer exists.
|
||||
$this->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.');
|
||||
|
||||
// Add a new custom mapping.
|
||||
$edit = [
|
||||
'new_mapping[browser_langcode]' => 'xx',
|
||||
'new_mapping[drupal_langcode]' => 'en',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
$this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
|
||||
$this->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.');
|
||||
|
||||
// Add the same custom mapping again.
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertText('Browser language codes must be unique.');
|
||||
|
||||
// Change browser language code of our custom mapping to zh-sg.
|
||||
$edit = [
|
||||
'mappings[xx][browser_langcode]' => 'zh-sg',
|
||||
'mappings[xx][drupal_langcode]' => 'en',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertText(t('Browser language codes must be unique.'));
|
||||
|
||||
// Change Drupal language code of our custom mapping to zh-hans.
|
||||
$edit = [
|
||||
'mappings[xx][browser_langcode]' => 'xx',
|
||||
'mappings[xx][drupal_langcode]' => 'zh-hans',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
$this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
|
||||
$this->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Ensures the language config overrides can be synchronized.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigOverrideImportTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'config', 'locale', 'config_translation'];
|
||||
|
||||
/**
|
||||
* Tests that language can be enabled and overrides are created during a sync.
|
||||
*/
|
||||
public function testConfigOverrideImport() {
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
/* @var \Drupal\Core\Config\StorageInterface $sync */
|
||||
$sync = \Drupal::service('config.storage.sync');
|
||||
$this->copyConfig(\Drupal::service('config.storage'), $sync);
|
||||
|
||||
// Uninstall the language module and its dependencies so we can test
|
||||
// enabling the language module and creating overrides at the same time
|
||||
// during a configuration synchronization.
|
||||
\Drupal::service('module_installer')->uninstall(['language']);
|
||||
// Ensure that the current site has no overrides registered to the
|
||||
// ConfigFactory.
|
||||
$this->rebuildContainer();
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $override_sync */
|
||||
$override_sync = $sync->createCollection('language.fr');
|
||||
// Create some overrides in sync.
|
||||
$override_sync->write('system.site', ['name' => 'FR default site name']);
|
||||
$override_sync->write('system.maintenance', ['message' => 'FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience']);
|
||||
|
||||
$this->configImporter()->import();
|
||||
$this->rebuildContainer();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
$override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
|
||||
$this->assertEqual('FR default site name', $override->get('name'));
|
||||
$this->drupalGet('fr');
|
||||
$this->assertText('FR default site name');
|
||||
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->drupalGet('admin/config/development/maintenance/translate/fr/edit');
|
||||
$this->assertText('FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuration events are not fired during a sync of overrides.
|
||||
*/
|
||||
public function testConfigOverrideImportEvents() {
|
||||
// Enable the config_events_test module so we can record events occurring.
|
||||
\Drupal::service('module_installer')->install(['config_events_test']);
|
||||
$this->rebuildContainer();
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $sync */
|
||||
$sync = \Drupal::service('config.storage.sync');
|
||||
$this->copyConfig(\Drupal::service('config.storage'), $sync);
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $override_sync */
|
||||
$override_sync = $sync->createCollection('language.fr');
|
||||
// Create some overrides in sync.
|
||||
$override_sync->write('system.site', ['name' => 'FR default site name']);
|
||||
\Drupal::state()->set('config_events_test.event', FALSE);
|
||||
|
||||
$this->configImporter()->import();
|
||||
$this->rebuildContainer();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// Test that no config save event has been fired during the import because
|
||||
// language configuration overrides do not fire events.
|
||||
$event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
|
||||
$this->assertFalse($event_recorder);
|
||||
|
||||
$this->drupalGet('fr');
|
||||
$this->assertText('FR default site name');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Ensures the language config schema is correct.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigSchemaTest extends BrowserTestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'menu_link_content'];
|
||||
|
||||
/**
|
||||
* A user with administrative permissions.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create user.
|
||||
$this->adminUser = $this->drupalCreateUser(['administer languages']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the language config schema is valid.
|
||||
*/
|
||||
public function testValidLanguageConfigSchema() {
|
||||
// Make sure no language configuration available by default.
|
||||
$config_data = $this->config('language.settings')->get();
|
||||
$this->assertTrue(empty($config_data));
|
||||
|
||||
$settings_path = 'admin/config/regional/content-language';
|
||||
|
||||
// Enable translation for menu link.
|
||||
$edit['entity_types[menu_link_content]'] = TRUE;
|
||||
$edit['settings[menu_link_content][menu_link_content][settings][language][language_alterable]'] = TRUE;
|
||||
|
||||
// Enable translation for user.
|
||||
$edit['entity_types[user]'] = TRUE;
|
||||
$edit['settings[user][user][settings][language][language_alterable]'] = TRUE;
|
||||
$edit['settings[user][user][settings][language][langcode]'] = 'en';
|
||||
|
||||
$this->drupalPostForm($settings_path, $edit, t('Save configuration'));
|
||||
|
||||
$config_data = $this->config('language.content_settings.menu_link_content.menu_link_content');
|
||||
// Make sure configuration saved correctly.
|
||||
$this->assertTrue($config_data->get('language_alterable'));
|
||||
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), $config_data->getName(), $config_data->get());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests enabling Language if a module exists that calls
|
||||
* LanguageManager::getLanguages() during installation.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageListModuleInstallTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language_test'];
|
||||
|
||||
/**
|
||||
* Tests enabling Language.
|
||||
*/
|
||||
public function testModuleInstallLanguageList() {
|
||||
// Since LanguageManager::getLanguages() uses static caches we need to do
|
||||
// this by enabling the module using the UI.
|
||||
$admin_user = $this->drupalCreateUser(['access administration pages', 'administer modules']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = [];
|
||||
$edit['modules[language][enable]'] = 'language';
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
|
||||
$this->assertEqual(\Drupal::state()->get('language_test.language_count_preinstall', 0), 1, 'Using LanguageManager::getLanguages() returns 1 language during Language installation.');
|
||||
|
||||
// Get updated module list by rebuilding container.
|
||||
$this->rebuildContainer();
|
||||
$this->assertTrue(\Drupal::moduleHandler()->moduleExists('language'), 'Language module is enabled');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests language negotiation with the language negotiator content entity.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationContentEntityTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'language_test', 'entity_test', 'system'];
|
||||
|
||||
/**
|
||||
* The entity being used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ConfigurableLanguage::create(['id' => 'es'])->save();
|
||||
ConfigurableLanguage::create(['id' => 'fr'])->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
$this->createTranslatableEntity();
|
||||
|
||||
$user = $this->drupalCreateUser(['view test entity']);
|
||||
$this->drupalLogin($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests default with content language remaining same as interface language.
|
||||
*/
|
||||
public function testDefaultConfiguration() {
|
||||
$translation = $this->entity;
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
|
||||
$translation = $this->entity->getTranslation('es');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
|
||||
$translation = $this->entity->getTranslation('fr');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests enabling the language negotiator language_content_entity.
|
||||
*/
|
||||
public function testEnabledLanguageContentNegotiator() {
|
||||
// Define the method language-url with a higher priority than
|
||||
// language-content-entity. This configuration should match the default one,
|
||||
// where the language-content-entity is turned off.
|
||||
$config = $this->config('language.types');
|
||||
$config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationUrl::METHOD_ID => 0,
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// The tests for the default configuration should still pass.
|
||||
$this->testDefaultConfiguration();
|
||||
|
||||
// Define the method language-content-entity with a higher priority than
|
||||
// language-url.
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 0,
|
||||
LanguageNegotiationUrl::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// The method language-content-entity should run before language-url and
|
||||
// append query parameter for the content language and prevent language-url
|
||||
// from overwriting the URL.
|
||||
$default_site_langcode = $this->config('system.site')->get('default_langcode');
|
||||
|
||||
// Now switching to an entity route, so that the URL links are generated
|
||||
// while being on an entity route.
|
||||
$this->setCurrentRequestForRoute('/entity_test/{entity_test}', 'entity.entity_test.canonical');
|
||||
|
||||
$translation = $this->entity;
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $default_site_langcode) && ($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), 'Interface language and Content language are the same as the default translation language of the entity.');
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
|
||||
$translation = $this->entity->getTranslation('es');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
|
||||
$translation = $this->entity->getTranslation('fr');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translated entity.
|
||||
*/
|
||||
protected function createTranslatableEntity() {
|
||||
$this->entity = EntityTest::create();
|
||||
$this->entity->addTranslation('es', ['name' => 'name spanish']);
|
||||
$this->entity->addTranslation('fr', ['name' => 'name french']);
|
||||
$this->entity->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current request to a specific path with the corresponding route.
|
||||
*
|
||||
* @param string $path
|
||||
* The path for which the current request should be created.
|
||||
* @param string $route_name
|
||||
* The route name for which the route object for the request should be
|
||||
* created.
|
||||
*/
|
||||
protected function setCurrentRequestForRoute($path, $route_name) {
|
||||
$request = Request::create($path);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, $route_name);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route($path));
|
||||
$this->container->get('request_stack')->push($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests alterations to language types/negotiation info.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationInfoTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'content_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'view the administration theme', 'administer modules']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'it'], t('Add language'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configurable language manager.
|
||||
*
|
||||
* @return \Drupal\language\ConfigurableLanguageManager
|
||||
*/
|
||||
protected function languageManager() {
|
||||
return $this->container->get('language_manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets state flags for language_test module.
|
||||
*
|
||||
* Ensures to correctly update data both in the child site and the test runner
|
||||
* environment.
|
||||
*
|
||||
* @param array $values
|
||||
* The key/value pairs to set in state.
|
||||
*/
|
||||
protected function stateSet(array $values) {
|
||||
// Set the new state values.
|
||||
$this->container->get('state')->setMultiple($values);
|
||||
// Refresh in-memory static state/config caches and static variables.
|
||||
$this->refreshVariables();
|
||||
// Refresh/rewrite language negotiation configuration, in order to pick up
|
||||
// the manipulations performed by language_test module's info alter hooks.
|
||||
$this->container->get('language_negotiator')->purgeConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests alterations to language types/negotiation info.
|
||||
*/
|
||||
public function testInfoAlterations() {
|
||||
$this->stateSet([
|
||||
// Enable language_test type info.
|
||||
'language_test.language_types' => TRUE,
|
||||
// Enable language_test negotiation info (not altered yet).
|
||||
'language_test.language_negotiation_info' => TRUE,
|
||||
// Alter LanguageInterface::TYPE_CONTENT to be configurable.
|
||||
'language_test.content_language_type' => TRUE,
|
||||
]);
|
||||
$this->container->get('module_installer')->install(['language_test']);
|
||||
$this->resetAll();
|
||||
|
||||
// Check that fixed language types are properly configured without the need
|
||||
// of saving the language negotiation settings.
|
||||
$this->checkFixedLanguageTypes();
|
||||
|
||||
$type = LanguageInterface::TYPE_CONTENT;
|
||||
$language_types = $this->languageManager()->getLanguageTypes();
|
||||
$this->assertTrue(in_array($type, $language_types), 'Content language type is configurable.');
|
||||
|
||||
// Enable some core and custom language negotiation methods. The test
|
||||
// language type is supposed to be configurable.
|
||||
$test_type = 'test_language_type';
|
||||
$interface_method_id = LanguageNegotiationUI::METHOD_ID;
|
||||
$test_method_id = 'test_language_negotiation_method';
|
||||
$form_field = $type . '[enabled][' . $interface_method_id . ']';
|
||||
$edit = [
|
||||
$form_field => TRUE,
|
||||
$type . '[enabled][' . $test_method_id . ']' => TRUE,
|
||||
$test_type . '[enabled][' . $test_method_id . ']' => TRUE,
|
||||
$test_type . '[configurable]' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Alter language negotiation info to remove interface language negotiation
|
||||
// method.
|
||||
$this->stateSet([
|
||||
'language_test.language_negotiation_info_alter' => TRUE,
|
||||
]);
|
||||
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$this->assertFalse(isset($negotiation[$interface_method_id]), 'Interface language negotiation method removed from the stored settings.');
|
||||
|
||||
$this->drupalGet('admin/config/regional/language/detection');
|
||||
$this->assertNoFieldByName($form_field, NULL, 'Interface language negotiation method unavailable.');
|
||||
|
||||
// Check that type-specific language negotiation methods can be assigned
|
||||
// only to the corresponding language types.
|
||||
foreach ($this->languageManager()->getLanguageTypes() as $type) {
|
||||
$form_field = $type . '[enabled][test_language_negotiation_method_ts]';
|
||||
if ($type == $test_type) {
|
||||
$this->assertFieldByName($form_field, NULL, format_string('Type-specific test language negotiation method available for %type.', ['%type' => $type]));
|
||||
}
|
||||
else {
|
||||
$this->assertNoFieldByName($form_field, NULL, format_string('Type-specific test language negotiation method unavailable for %type.', ['%type' => $type]));
|
||||
}
|
||||
}
|
||||
|
||||
// Check language negotiation results.
|
||||
$this->drupalGet('');
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$langcode = $last[$type];
|
||||
$value = $type == LanguageInterface::TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en';
|
||||
$this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', ['%type' => $type, '%language' => $value]));
|
||||
}
|
||||
|
||||
// Uninstall language_test and check that everything is set back to the
|
||||
// original status.
|
||||
$this->container->get('module_installer')->uninstall(['language_test']);
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Check that only the core language types are available.
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$this->assertTrue(strpos($type, 'test') === FALSE, format_string('The %type language is still available', ['%type' => $type]));
|
||||
}
|
||||
|
||||
// Check that fixed language types are properly configured, even those
|
||||
// previously set to configurable.
|
||||
$this->checkFixedLanguageTypes();
|
||||
|
||||
// Check that unavailable language negotiation methods are not present in
|
||||
// the negotiation settings.
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$this->assertFalse(isset($negotiation[$test_method_id]), 'The disabled test language negotiation method is not part of the content language negotiation settings.');
|
||||
|
||||
// Check that configuration page presents the correct options and settings.
|
||||
$this->assertNoRaw(t('Test language detection'), 'No test language type configuration available.');
|
||||
$this->assertNoRaw(t('This is a test language negotiation method'), 'No test language negotiation method available.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that language negotiation for fixed types matches the stored one.
|
||||
*/
|
||||
protected function checkFixedLanguageTypes() {
|
||||
$configurable = $this->languageManager()->getLanguageTypes();
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypesInfo() as $type => $info) {
|
||||
if (!in_array($type, $configurable) && isset($info['fixed'])) {
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$equal = count($info['fixed']) == count($negotiation);
|
||||
while ($equal && list($id) = each($negotiation)) {
|
||||
list(, $info_id) = each($info['fixed']);
|
||||
$equal = $info_id == $id;
|
||||
}
|
||||
$this->assertTrue($equal, format_string('language negotiation for %type is properly set up', ['%type' => $type]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests altering config of configurable language types.
|
||||
*/
|
||||
public function testConfigLangTypeAlterations() {
|
||||
// Default of config.
|
||||
$test_type = LanguageInterface::TYPE_CONTENT;
|
||||
$this->assertFalse($this->isLanguageTypeConfigurable($test_type), 'Language type is not configurable.');
|
||||
|
||||
// Editing config.
|
||||
$edit = [$test_type . '[configurable]' => TRUE];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is now configurable.');
|
||||
|
||||
// After installing another module, the config should be the same.
|
||||
$this->drupalPostForm('admin/modules', ['modules[test_module][enable]' => 1], t('Install'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.');
|
||||
|
||||
// After uninstalling the other module, the config should be the same.
|
||||
$this->drupalPostForm('admin/modules/uninstall', ['uninstall[test_module]' => 1], t('Uninstall'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given language type is configurable.
|
||||
*
|
||||
* @param string $type
|
||||
* The language type.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the specified language type is configurable, FALSE otherwise.
|
||||
*/
|
||||
protected function isLanguageTypeConfigurable($type) {
|
||||
$configurable_types = $this->config('language.types')->get('configurable');
|
||||
return in_array($type, $configurable_types);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationUrlTest extends BrowserTestBase {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'language',
|
||||
'node',
|
||||
'path',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create an Article node type.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(['type' => 'article']);
|
||||
}
|
||||
|
||||
$this->user = $this->drupalCreateUser([
|
||||
'administer languages',
|
||||
'access administration pages',
|
||||
'view the administration theme',
|
||||
'administer nodes',
|
||||
'create article content',
|
||||
'create url aliases',
|
||||
]);
|
||||
$this->drupalLogin($this->user);
|
||||
|
||||
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'de'], $this->t('Add language'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processInbound
|
||||
*/
|
||||
public function testDomain() {
|
||||
// Check if paths that contain language prefixes can be reached when
|
||||
// language is taken from the domain.
|
||||
$edit = [
|
||||
'language_negotiation_url_part' => 'domain',
|
||||
'prefix[en]' => 'eng',
|
||||
'prefix[de]' => 'de',
|
||||
'domain[en]' => $_SERVER['HTTP_HOST'],
|
||||
'domain[de]' => "de.$_SERVER[HTTP_HOST]",
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, $this->t('Save configuration'));
|
||||
|
||||
$nodeValues = [
|
||||
'title[0][value]' => 'Test',
|
||||
'path[0][alias]' => '/eng/test',
|
||||
];
|
||||
$this->drupalPostForm('node/add/article', $nodeValues, $this->t('Save and publish'));
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Confirm that paths are not changed on monolingual non-English sites.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguagePathMonolingualTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'language', 'path'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$web_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer site configuration']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Enable French language.
|
||||
$edit = [];
|
||||
$edit['predefined_langcode'] = 'fr';
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Make French the default language.
|
||||
$edit = [
|
||||
'site_default_language' => 'fr',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
|
||||
|
||||
// Delete English.
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', [], t('Delete'));
|
||||
|
||||
// Changing the default language causes a container rebuild. Therefore need
|
||||
// to rebuild the container in the test environment.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Verify that French is the only language.
|
||||
$this->container->get('language_manager')->reset();
|
||||
$this->assertFalse(\Drupal::languageManager()->isMultilingual(), 'Site is mono-lingual');
|
||||
$this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), 'fr', 'French is the default language');
|
||||
|
||||
// Set language detection to URL.
|
||||
$edit = ['language_interface[enabled][language-url]' => TRUE];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that links do not have language prefixes in them.
|
||||
*/
|
||||
public function testPageLinks() {
|
||||
// Navigate to 'admin/config' path.
|
||||
$this->drupalGet('admin/config');
|
||||
|
||||
// Verify that links in this page do not have a 'fr/' prefix.
|
||||
$this->assertNoLinkByHref('/fr/', 'Links do not contain language prefix');
|
||||
|
||||
// Verify that links in this page can be followed and work.
|
||||
$this->clickLink(t('Languages'));
|
||||
$this->assertResponse(200, 'Clicked link results in a valid page');
|
||||
$this->assertText(t('Add language'), 'Page contains the add language text');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional\Migrate;
|
||||
|
||||
use Drupal\language\ConfigurableLanguageInterface;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateLanguageTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Asserts various properties of a configurable language entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The language ID.
|
||||
* @param string $label
|
||||
* The language name.
|
||||
* @param string $direction
|
||||
* (optional) The language's direction (one of the DIRECTION_* constants in
|
||||
* ConfigurableLanguageInterface). Defaults to LTR.
|
||||
* @param int $weight
|
||||
* (optional) The weight of the language. Defaults to 0.
|
||||
*/
|
||||
protected function assertLanguage($id, $label, $direction = ConfigurableLanguageInterface::DIRECTION_LTR, $weight = 0) {
|
||||
/** @var \Drupal\language\ConfigurableLanguageInterface $language */
|
||||
$language = ConfigurableLanguage::load($id);
|
||||
$this->assertTrue($language instanceof ConfigurableLanguageInterface);
|
||||
$this->assertIdentical($label, $language->label());
|
||||
$this->assertIdentical($direction, $language->getDirection());
|
||||
$this->assertIdentical(0, $language->getWeight());
|
||||
$this->assertFalse($language->isLocked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of Drupal 6 languages to configurable language entities.
|
||||
*/
|
||||
public function testLanguageMigration() {
|
||||
$this->executeMigration('language');
|
||||
$this->assertLanguage('en', 'English');
|
||||
$this->assertLanguage('fr', 'French');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Condition;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the language condition, provided by the language module, is
|
||||
* working properly.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConditionTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* The condition plugin manager.
|
||||
*
|
||||
* @var \Drupal\Core\Condition\ConditionManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system', 'language'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['language']);
|
||||
// Setup Italian.
|
||||
ConfigurableLanguage::createFromLangcode('it')->save();
|
||||
|
||||
$this->manager = $this->container->get('plugin.manager.condition');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the language condition.
|
||||
*/
|
||||
public function testConditions() {
|
||||
// Grab the language condition and configure it to check the content
|
||||
// language.
|
||||
$language = \Drupal::languageManager()->getLanguage('en');
|
||||
$condition = $this->manager->createInstance('language')
|
||||
->setConfig('langcodes', ['en' => 'en', 'it' => 'it'])
|
||||
->setContextValue('language', $language);
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is English, Italian.');
|
||||
|
||||
// Change to Italian only.
|
||||
$condition->setConfig('langcodes', ['it' => 'it']);
|
||||
$this->assertFalse($condition->execute(), 'Language condition fails as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is Italian.');
|
||||
|
||||
// Negate the condition
|
||||
$condition->setConfig('negate', TRUE);
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is not Italian.');
|
||||
|
||||
// Change the default language to Italian.
|
||||
$language = \Drupal::languageManager()->getLanguage('it');
|
||||
|
||||
$condition = $this->manager->createInstance('language')
|
||||
->setConfig('langcodes', ['en' => 'en', 'it' => 'it'])
|
||||
->setContextValue('language', $language);
|
||||
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is English, Italian.');
|
||||
|
||||
// Change to Italian only.
|
||||
$condition->setConfig('langcodes', ['it' => 'it']);
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is Italian.');
|
||||
|
||||
// Negate the condition
|
||||
$condition->setConfig('negate', TRUE);
|
||||
$this->assertFalse($condition->execute(), 'Language condition fails as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is not Italian.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity.
|
||||
*
|
||||
* @group language
|
||||
* @coversDefaultClass \Drupal\language\ConfigurableLanguageManager
|
||||
*/
|
||||
class ConfigurableLanguageManagerTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['user'];
|
||||
|
||||
/**
|
||||
* The language negotiator.
|
||||
*
|
||||
* @var \Drupal\language\LanguageNegotiatorInterface
|
||||
*/
|
||||
protected $languageNegotiator;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\language\ConfigurableLanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installSchema('system', ['sequence']);
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
$this->languageNegotiator = $this->container->get('language_negotiator');
|
||||
$this->languageManager = $this->container->get('language_manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getLanguageSwitchLinks
|
||||
*/
|
||||
public function testLanguageSwitchLinks() {
|
||||
$this->languageNegotiator->setCurrentUser($this->prophesize('Drupal\Core\Session\AccountInterface')->reveal());
|
||||
$this->languageManager->getLanguageSwitchLinks(LanguageInterface::TYPE_INTERFACE, new Url('<current>'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Entity\ConfigurableLanguage.
|
||||
*/
|
||||
class ConfigurableLanguageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests configurable language name methods.
|
||||
*/
|
||||
public function testName() {
|
||||
$name = $this->randomMachineName();
|
||||
$language_code = $this->randomMachineName(2);
|
||||
$configurableLanguage = new ConfigurableLanguage(['label' => $name, 'id' => $language_code], 'configurable_language');
|
||||
$this->assertEqual($configurableLanguage->getName(), $name);
|
||||
$this->assertEqual($configurableLanguage->setName('Test language')->getName(), 'Test language');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests default language code is properly generated for entities.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class EntityDefaultLanguageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'node', 'field', 'text', 'user', 'system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
// Activate Spanish language, so there are two languages activated.
|
||||
$language = $this->container->get('entity.manager')->getStorage('configurable_language')->create([
|
||||
'id' => 'es',
|
||||
]);
|
||||
$language->save();
|
||||
|
||||
// Create a new content type which has Undefined language by default.
|
||||
$this->createContentType('ctund', LanguageInterface::LANGCODE_NOT_SPECIFIED);
|
||||
// Create a new content type which has Spanish language by default.
|
||||
$this->createContentType('ctes', 'es');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that default language code is properly set for new nodes.
|
||||
*/
|
||||
public function testEntityTranslationDefaultLanguageViaCode() {
|
||||
// With language module activated, and a content type that is configured to
|
||||
// have no language by default, a new node of this content type will have
|
||||
// "und" language code when language is not specified.
|
||||
$node = $this->createNode('ctund');
|
||||
$this->assertEqual($node->langcode->value, LanguageInterface::LANGCODE_NOT_SPECIFIED);
|
||||
// With language module activated, and a content type that is configured to
|
||||
// have no language by default, a new node of this content type will have
|
||||
// "es" language code when language is specified as "es".
|
||||
$node = $this->createNode('ctund', 'es');
|
||||
$this->assertEqual($node->langcode->value, 'es');
|
||||
|
||||
// With language module activated, and a content type that is configured to
|
||||
// have language "es" by default, a new node of this content type will have
|
||||
// "es" language code when language is not specified.
|
||||
$node = $this->createNode('ctes');
|
||||
$this->assertEqual($node->langcode->value, 'es');
|
||||
// With language module activated, and a content type that is configured to
|
||||
// have language "es" by default, a new node of this content type will have
|
||||
// "en" language code when language "en" is specified.
|
||||
$node = $this->createNode('ctes', 'en');
|
||||
$this->assertEqual($node->langcode->value, 'en');
|
||||
|
||||
// Disable language module.
|
||||
$this->disableModules(['language']);
|
||||
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have no language specified by default, a new node of this content type
|
||||
// will have site's default language code when language is not specified.
|
||||
$node = $this->createNode('ctund');
|
||||
$this->assertEqual($node->langcode->value, 'en');
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have no language specified by default, a new node of this type will have
|
||||
// "es" language code when language "es" is specified.
|
||||
$node = $this->createNode('ctund', 'es');
|
||||
$this->assertEqual($node->langcode->value, 'es');
|
||||
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have language "es" by default, a new node of this type will have site's
|
||||
// default language code when language is not specified.
|
||||
$node = $this->createNode('ctes');
|
||||
$this->assertEqual($node->langcode->value, 'en');
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have language "es" by default, a new node of this type will have "en"
|
||||
// language code when language "en" is specified.
|
||||
$node = $this->createNode('ctes', 'en');
|
||||
$this->assertEqual($node->langcode->value, 'en');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new node content type.
|
||||
*
|
||||
* @param string $name
|
||||
* The content type name.
|
||||
* @param string $langcode
|
||||
* Default language code of the nodes of this type.
|
||||
*/
|
||||
protected function createContentType($name, $langcode) {
|
||||
$content_type = $this->container->get('entity.manager')->getStorage('node_type')->create([
|
||||
'name' => 'Test ' . $name,
|
||||
'title_label' => 'Title',
|
||||
'type' => $name,
|
||||
'create_body' => FALSE,
|
||||
]);
|
||||
$content_type->save();
|
||||
ContentLanguageSettings::loadByEntityTypeBundle('node', $name)
|
||||
->setLanguageAlterable(FALSE)
|
||||
->setDefaultLangcode($langcode)
|
||||
->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new node of given type and language using Entity API.
|
||||
*
|
||||
* @param string $type
|
||||
* The node content type.
|
||||
* @param string $langcode
|
||||
* (optional) Language code to pass to entity create.
|
||||
*
|
||||
* @return \Drupal\node\NodeInterface
|
||||
* The node created.
|
||||
*/
|
||||
protected function createNode($type, $langcode = NULL) {
|
||||
$values = [
|
||||
'type' => $type,
|
||||
'title' => $this->randomString(),
|
||||
];
|
||||
if (!empty($langcode)) {
|
||||
$values['langcode'] = $langcode;
|
||||
}
|
||||
$node = $this->container->get('entity.manager')->getStorage('node')->create($values);
|
||||
return $node;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests the language of entity URLs.
|
||||
* @group language
|
||||
*/
|
||||
class EntityUrlLanguageTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['entity_test', 'user'];
|
||||
|
||||
/**
|
||||
* The entity being used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test');
|
||||
$this->installEntitySchema('configurable_language');
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
ConfigurableLanguage::create(['id' => 'es'])->save();
|
||||
ConfigurableLanguage::create(['id' => 'fr'])->save();
|
||||
|
||||
$config = $this->config('language.negotiation');
|
||||
$config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])
|
||||
->save();
|
||||
|
||||
\Drupal::service('kernel')->rebuildContainer();
|
||||
|
||||
$this->createTranslatableEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that entity URLs in a language have the right language prefix.
|
||||
*/
|
||||
public function testEntityUrlLanguage() {
|
||||
$this->assertTrue(strpos($this->entity->urlInfo()->toString(), '/en/entity_test/' . $this->entity->id()) !== FALSE);
|
||||
$this->assertTrue(strpos($this->entity->getTranslation('es')->urlInfo()->toString(), '/es/entity_test/' . $this->entity->id()) !== FALSE);
|
||||
$this->assertTrue(strpos($this->entity->getTranslation('fr')->urlInfo()->toString(), '/fr/entity_test/' . $this->entity->id()) !== FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures correct entity URLs with the method language-content-entity enabled.
|
||||
*
|
||||
* Test case with the method language-content-entity enabled and configured
|
||||
* with higher and also with lower priority than the method language-url.
|
||||
*/
|
||||
public function testEntityUrlLanguageWithLanguageContentEnabled() {
|
||||
// Define the method language-content-entity with a higher priority than
|
||||
// language-url.
|
||||
$config = $this->config('language.types');
|
||||
$config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 0,
|
||||
LanguageNegotiationUrl::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// Without being on an content entity route the default entity URL tests
|
||||
// should still pass.
|
||||
$this->testEntityUrlLanguage();
|
||||
|
||||
// Now switching to an entity route, so that the URL links are generated
|
||||
// while being on an entity route.
|
||||
$this->setCurrentRequestForRoute('/entity_test/{entity_test}', 'entity.entity_test.canonical');
|
||||
|
||||
// The method language-content-entity should run before language-url and
|
||||
// append query parameter for the content language and prevent language-url
|
||||
// from overwriting the url.
|
||||
$this->assertTrue(strpos($this->entity->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=en') !== FALSE);
|
||||
$this->assertTrue(strpos($this->entity->getTranslation('es')->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=es') !== FALSE);
|
||||
$this->assertTrue(strpos($this->entity->getTranslation('fr')->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=fr') !== FALSE);
|
||||
|
||||
// Define the method language-url with a higher priority than
|
||||
// language-content-entity. This configuration should match the default one,
|
||||
// where the language-content-entity is turned off.
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationUrl::METHOD_ID => 0,
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// The default entity URL tests should pass again with the current
|
||||
// configuration.
|
||||
$this->testEntityUrlLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translated entity.
|
||||
*/
|
||||
protected function createTranslatableEntity() {
|
||||
$this->entity = EntityTest::create();
|
||||
$this->entity->addTranslation('es', ['name' => 'name spanish']);
|
||||
$this->entity->addTranslation('fr', ['name' => 'name french']);
|
||||
$this->entity->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current request to a specific path with the corresponding route.
|
||||
*
|
||||
* @param string $path
|
||||
* The path for which the current request should be created.
|
||||
* @param string $route_name
|
||||
* The route name for which the route object for the request should be
|
||||
* created.
|
||||
*/
|
||||
protected function setCurrentRequestForRoute($path, $route_name) {
|
||||
$request = Request::create($path);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, $route_name);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route($path));
|
||||
$this->container->get('request_stack')->push($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests \Drupal\language\Config\LanguageConfigFactoryOverride.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigFactoryOverrideTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system', 'language'];
|
||||
|
||||
/**
|
||||
* Tests language.config_factory_override service has the default language.
|
||||
*/
|
||||
public function testLanguageConfigFactoryOverride() {
|
||||
$this->installConfig('system');
|
||||
$this->installConfig('language');
|
||||
|
||||
/** @var \Drupal\language\Config\LanguageConfigFactoryOverride $config_factory_override */
|
||||
$config_factory_override = \Drupal::service('language.config_factory_override');
|
||||
$this->assertEquals('en', $config_factory_override->getLanguage()->getId());
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
|
||||
// Invalidate the container.
|
||||
$this->config('system.site')->set('default_langcode', 'de')->save();
|
||||
drupal_flush_all_caches();
|
||||
|
||||
$config_factory_override = \Drupal::service('language.config_factory_override');
|
||||
$this->assertEquals('de', $config_factory_override->getLanguage()->getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Ensures the language config overrides can be installed.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigOverrideInstallTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'config_events_test'];
|
||||
|
||||
/**
|
||||
* Tests the configuration events are not fired during install of overrides.
|
||||
*/
|
||||
public function testLanguageConfigOverrideInstall() {
|
||||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
// Need to enable test module after creating the language otherwise saving
|
||||
// the language will install the configuration.
|
||||
$this->enableModules(['language_config_override_test']);
|
||||
\Drupal::state()->set('config_events_test.event', FALSE);
|
||||
$this->installConfig(['language_config_override_test']);
|
||||
$event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
|
||||
$this->assertFalse($event_recorder);
|
||||
$config = \Drupal::service('language.config_factory_override')->getOverride('de', 'language_config_override_test.settings');
|
||||
$this->assertEqual($config->get('name'), 'Deutsch');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Exception\DeleteDefaultLanguageException;
|
||||
|
||||
/**
|
||||
* Compares the default language from $GLOBALS against the dependency injected
|
||||
* language object.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageDependencyInjectionTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Test dependency injected languages against a new Language object.
|
||||
*
|
||||
* @see \Drupal\Core\Language\LanguageInterface
|
||||
*/
|
||||
public function testDependencyInjectedNewLanguage() {
|
||||
$expected = $this->languageManager->getDefaultLanguage();
|
||||
$result = $this->languageManager->getCurrentLanguage();
|
||||
foreach ($expected as $property => $value) {
|
||||
$this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the new Language object %prop property.', ['%prop' => $property]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dependency injected Language object against a new default language
|
||||
* object.
|
||||
*
|
||||
* @see \Drupal\Core\Language\Language
|
||||
*/
|
||||
public function testDependencyInjectedNewDefaultLanguage() {
|
||||
$default_language = ConfigurableLanguage::load(\Drupal::languageManager()->getDefaultLanguage()->getId());
|
||||
// Change the language default object to different values.
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
$this->config('system.site')->set('default_langcode', 'fr')->save();
|
||||
|
||||
// The language system creates a Language object which contains the
|
||||
// same properties as the new default language object.
|
||||
$result = \Drupal::languageManager()->getCurrentLanguage();
|
||||
$this->assertIdentical($result->getId(), 'fr');
|
||||
|
||||
// Delete the language to check that we fallback to the default.
|
||||
try {
|
||||
entity_delete_multiple('configurable_language', ['fr']);
|
||||
$this->fail('Expected DeleteDefaultLanguageException thrown.');
|
||||
}
|
||||
catch (DeleteDefaultLanguageException $e) {
|
||||
$this->pass('Expected DeleteDefaultLanguageException thrown.');
|
||||
}
|
||||
|
||||
// Re-save the previous default language and the delete should work.
|
||||
$this->config('system.site')->set('default_langcode', $default_language->getId())->save();
|
||||
|
||||
entity_delete_multiple('configurable_language', ['fr']);
|
||||
$result = \Drupal::languageManager()->getCurrentLanguage();
|
||||
$this->assertIdentical($result->getId(), $default_language->getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests the language fallback behavior.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageFallbackTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$i = 0;
|
||||
foreach (['af', 'am', 'ar'] as $langcode) {
|
||||
$language = ConfigurableLanguage::createFromLangcode($langcode);
|
||||
$language->set('weight', $i--);
|
||||
$language->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language fallback candidates.
|
||||
*/
|
||||
public function testCandidates() {
|
||||
$language_list = $this->languageManager->getLanguages();
|
||||
$expected = array_keys($language_list + [LanguageInterface::LANGCODE_NOT_SPECIFIED => NULL]);
|
||||
|
||||
// Check that language fallback candidates by default are all the available
|
||||
// languages sorted by weight.
|
||||
$candidates = $this->languageManager->getFallbackCandidates();
|
||||
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are properly returned.');
|
||||
|
||||
// Check that candidates are alterable.
|
||||
$this->state->set('language_test.fallback_alter.candidates', TRUE);
|
||||
$expected = array_slice($expected, 0, count($expected) - 1);
|
||||
$candidates = $this->languageManager->getFallbackCandidates();
|
||||
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable.');
|
||||
|
||||
// Check that candidates are alterable for specific operations.
|
||||
$this->state->set('language_test.fallback_alter.candidates', FALSE);
|
||||
$this->state->set('language_test.fallback_operation_alter.candidates', TRUE);
|
||||
$expected[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
|
||||
$expected[] = LanguageInterface::LANGCODE_NOT_APPLICABLE;
|
||||
$candidates = $this->languageManager->getFallbackCandidates(['operation' => 'test']);
|
||||
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable for specific operations.');
|
||||
|
||||
// Check that when the site is monolingual no language fallback is applied.
|
||||
$langcodes_to_delete = [];
|
||||
foreach ($language_list as $langcode => $language) {
|
||||
if (!$language->isDefault()) {
|
||||
$langcodes_to_delete[] = $langcode;
|
||||
}
|
||||
}
|
||||
entity_delete_multiple('configurable_language', $langcodes_to_delete);
|
||||
$candidates = $this->languageManager->getFallbackCandidates();
|
||||
$this->assertEqual(array_values($candidates), [LanguageInterface::LANGCODE_DEFAULT], 'Language fallback is not applied when the Language module is not enabled.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Test for dependency injected language object.
|
||||
*/
|
||||
abstract class LanguageTestBase extends KernelTestBase {
|
||||
|
||||
public static $modules = ['system', 'language', 'language_test'];
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The state storage service.
|
||||
*
|
||||
* @var \Drupal\Core\State\StateInterface
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['language']);
|
||||
|
||||
$this->state = $this->container->get('state');
|
||||
|
||||
// Ensure we are building a new Language object for each test.
|
||||
$this->languageManager = $this->container->get('language_manager');
|
||||
$this->languageManager->reset();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Tests the default language variable migration.
|
||||
*/
|
||||
trait MigrateDefaultLanguageTrait {
|
||||
|
||||
/**
|
||||
* Helper method to test the migration.
|
||||
*
|
||||
* @param string $langcode
|
||||
* The langcode of the default language.
|
||||
* @param bool $existing
|
||||
* Whether the default language exists on the destination.
|
||||
*/
|
||||
protected function doTestMigration($langcode, $existing = TRUE) {
|
||||
// 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([
|
||||
'value' => $value
|
||||
])
|
||||
->condition('name', 'language_default' )
|
||||
->execute();
|
||||
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigrations(['language', 'default_language']);
|
||||
|
||||
if ($existing) {
|
||||
// If the default language exists, we should be able to load it and the
|
||||
// default_langcode config should be set.
|
||||
$default_language = ConfigurableLanguage::load($langcode);
|
||||
$this->assertNotNull($default_language);
|
||||
$this->assertSame($langcode, $this->config('system.site')->get('default_langcode'));
|
||||
}
|
||||
else {
|
||||
// Otherwise, the migration log should contain an error message.
|
||||
$messages = $this->migration->getIdMap()->getMessageIterator();
|
||||
$count = 0;
|
||||
foreach ($messages as $message) {
|
||||
$count++;
|
||||
$this->assertSame($message->message, "The language '$langcode' does not exist on this site.");
|
||||
$this->assertSame((int) $message->level, MigrationInterface::MESSAGE_ERROR);
|
||||
}
|
||||
$this->assertSame($count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to test migrating the default language when no default language is set.
|
||||
*/
|
||||
protected function doTestMigrationWithUnsetVariable() {
|
||||
// Delete the language_default variable.
|
||||
$this->sourceDatabase->delete('variable')
|
||||
->condition('name', 'language_default' )
|
||||
->execute();
|
||||
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigrations(['language', 'default_language']);
|
||||
$messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll();
|
||||
|
||||
// Make sure there's no migration exceptions.
|
||||
$this->assertEmpty($messages);
|
||||
|
||||
// Make sure the default langcode is 'en', since it was the default on D6 & D7.
|
||||
$this->assertSame('en', $this->config('system.site')->get('default_langcode'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\language\Kernel\Migrate\MigrateDefaultLanguageTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the default language variable migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateDefaultLanguageTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use MigrateDefaultLanguageTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests language_default migration with an existing language.
|
||||
*/
|
||||
public function testMigrationWithExistingLanguage() {
|
||||
$this->doTestMigration('fr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language_default migration with a non-existing language.
|
||||
*/
|
||||
public function testMigrationWithNonExistentLanguage() {
|
||||
$this->doTestMigration('tv', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language_default migration with unset variable.
|
||||
*/
|
||||
public function testMigrationWithUnsetVariable() {
|
||||
$this->doTestMigrationWithUnsetVariable();
|
||||
}
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of language content setting variables,
|
||||
* language_content_type_$type, i18n_node_options_* and i18n_lock_node_*.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateLanguageContentSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'text', 'language', 'content_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['node']);
|
||||
$this->executeMigrations(['d6_node_type', 'd6_language_content_settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of content language settings.
|
||||
*/
|
||||
public function testLanguageContent() {
|
||||
// Assert that a translatable content is still translatable.
|
||||
$config = $this->config('language.content_settings.node.article');
|
||||
$this->assertSame($config->get('target_entity_type_id'), 'node');
|
||||
$this->assertSame($config->get('target_bundle'), 'article');
|
||||
$this->assertSame($config->get('default_langcode'), 'current_interface');
|
||||
$this->assertTrue($config->get('third_party_settings.content_translation.enabled'));
|
||||
|
||||
// Assert that a non-translatable content is not translatable.
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'company');
|
||||
$this->assertTrue($config->isDefaultConfiguration());
|
||||
$this->assertFalse($config->isLanguageAlterable());
|
||||
$this->assertSame($config->getDefaultLangcode(), 'site_default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of content language settings when there is no language lock.
|
||||
*/
|
||||
public function testLanguageContentWithNoLanguageLock() {
|
||||
// Assert that a we can assign a language.
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'employee');
|
||||
$this->assertSame($config->getDefaultLangcode(), 'current_interface');
|
||||
$this->assertTrue($config->isLanguageAlterable());
|
||||
}
|
||||
|
||||
}
|
||||
+167
@@ -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(['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(['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(['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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\language\Kernel\Migrate\MigrateDefaultLanguageTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests the default language variable migration.
|
||||
*
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateDefaultLanguageTest extends MigrateDrupal7TestBase {
|
||||
|
||||
use MigrateDefaultLanguageTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests language_default migration with a non-existing language.
|
||||
*/
|
||||
public function testMigrationWithExistingLanguage() {
|
||||
$this->doTestMigration('is');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language_default migration with a non-existing language.
|
||||
*/
|
||||
public function testMigrationWithNonExistentLanguage() {
|
||||
$this->doTestMigration('tv', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language_default migration with unset variable.
|
||||
*/
|
||||
public function testMigrationWithUnsetVariable() {
|
||||
$this->doTestMigrationWithUnsetVariable();
|
||||
}
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of language content setting variables,
|
||||
* language_content_type_$type, i18n_node_options_* and i18n_lock_node_*.
|
||||
*
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'text', 'language', 'content_translation'];
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['node']);
|
||||
$this->executeMigrations(['d7_node_type', 'd7_language_content_settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of content language settings.
|
||||
*/
|
||||
public function testLanguageContent() {
|
||||
// Assert that a translatable content is still translatable.
|
||||
$config = $this->config('language.content_settings.node.blog');
|
||||
$this->assertIdentical($config->get('target_entity_type_id'), 'node');
|
||||
$this->assertIdentical($config->get('target_bundle'), 'blog');
|
||||
$this->assertIdentical($config->get('default_langcode'), 'current_interface');
|
||||
$this->assertFalse($config->get('language_alterable'));
|
||||
$this->assertTrue($config->get('third_party_settings.content_translation.enabled'));
|
||||
|
||||
// Assert that a non-translatable content is not translatable.
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'page');
|
||||
$this->assertTrue($config->isDefaultConfiguration());
|
||||
$this->assertFalse($config->isLanguageAlterable());
|
||||
$this->assertSame($config->getDefaultLangcode(), 'site_default');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration of language negotiation.
|
||||
*
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests migration of language types variables to language.types.yml.
|
||||
*/
|
||||
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 the migration with prefix negotiation.
|
||||
*/
|
||||
public function testLanguageNegotiationWithPrefix() {
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration with domain negotiation.
|
||||
*/
|
||||
public function testLanguageNegotiationWithDomain() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(['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,89 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the language source plugin.
|
||||
*
|
||||
* @covers \Drupal\language\Plugin\migrate\source\Language
|
||||
* @group language
|
||||
*/
|
||||
class LanguageTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language', 'migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['languages'] = [
|
||||
[
|
||||
'language' => 'en',
|
||||
'name' => 'English',
|
||||
'native' => 'English',
|
||||
'direction' => '0',
|
||||
'enabled' => '1',
|
||||
'plurals' => '0',
|
||||
'formula' => '',
|
||||
'domain' => '',
|
||||
'prefix' => '',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
],
|
||||
[
|
||||
'language' => 'fr',
|
||||
'name' => 'French',
|
||||
'native' => 'Français',
|
||||
'direction' => '0',
|
||||
'enabled' => '0',
|
||||
'plurals' => '2',
|
||||
'formula' => '($n>1)',
|
||||
'domain' => '',
|
||||
'prefix' => 'fr',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'language' => 'en',
|
||||
'name' => 'English',
|
||||
'native' => 'English',
|
||||
'direction' => '0',
|
||||
'enabled' => '1',
|
||||
'plurals' => '0',
|
||||
'formula' => '',
|
||||
'domain' => '',
|
||||
'prefix' => '',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
],
|
||||
[
|
||||
'language' => 'fr',
|
||||
'name' => 'French',
|
||||
'native' => 'Français',
|
||||
'direction' => '0',
|
||||
'enabled' => '0',
|
||||
'plurals' => '2',
|
||||
'formula' => '($n>1)',
|
||||
'domain' => '',
|
||||
'prefix' => 'fr',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
],
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the argument language handler.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Plugin\views\argument\Language.php
|
||||
*/
|
||||
class ArgumentLanguageTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the language argument.
|
||||
*/
|
||||
public function testArgument() {
|
||||
$view = Views::getView('test_view');
|
||||
foreach (['en' => 'John', 'xx-lolspeak' => 'George'] as $langcode => $name) {
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('arguments', [
|
||||
'langcode' => [
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
],
|
||||
]);
|
||||
$this->executeView($view, [$langcode]);
|
||||
|
||||
$expected = [[
|
||||
'name' => $name,
|
||||
]];
|
||||
$this->assertIdenticalResultset($view, $expected, ['views_test_data_name' => 'name']);
|
||||
$view->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the field language handler.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Plugin\views\field\Language
|
||||
*/
|
||||
class FieldLanguageTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the language field.
|
||||
*/
|
||||
public function testField() {
|
||||
$view = Views::getView('test_view');
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', [
|
||||
'langcode' => [
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
],
|
||||
]);
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual($view->field['langcode']->advancedRender($view->result[0]), 'English');
|
||||
$this->assertEqual($view->field['langcode']->advancedRender($view->result[1]), 'Lolspeak');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the filter language handler.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Plugin\views\filter\Language
|
||||
*/
|
||||
class FilterLanguageTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the language filter.
|
||||
*/
|
||||
public function testFilter() {
|
||||
$view = Views::getView('test_view');
|
||||
foreach (['en' => 'John', 'xx-lolspeak' => 'George'] as $langcode => $name) {
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('filters', [
|
||||
'langcode' => [
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
'value' => [$langcode],
|
||||
],
|
||||
]);
|
||||
$this->executeView($view);
|
||||
|
||||
$expected = [[
|
||||
'name' => $name,
|
||||
]];
|
||||
$this->assertIdenticalResultset($view, $expected, ['views_test_data_name' => 'name']);
|
||||
|
||||
$expected = [
|
||||
'***LANGUAGE_site_default***',
|
||||
'***LANGUAGE_language_interface***',
|
||||
'***LANGUAGE_language_content***',
|
||||
'en',
|
||||
'xx-lolspeak',
|
||||
'und',
|
||||
'zxx'
|
||||
];
|
||||
$this->assertIdentical(array_keys($view->filter['langcode']->getValueOptions()), $expected);
|
||||
|
||||
$view->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Views;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
|
||||
/**
|
||||
* Defines the base class for all Language handler tests.
|
||||
*/
|
||||
abstract class LanguageTestBase extends ViewsKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system', 'language'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp();
|
||||
$this->installConfig(['language']);
|
||||
|
||||
// Create another language beside English.
|
||||
ConfigurableLanguage::create(['id' => 'xx-lolspeak', 'label' => 'Lolspeak'])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function schemaDefinition() {
|
||||
$schema = parent::schemaDefinition();
|
||||
$schema['views_test_data']['fields']['langcode'] = [
|
||||
'description' => 'The {language}.langcode of this beatle.',
|
||||
'type' => 'varchar',
|
||||
'length' => 12,
|
||||
'default' => '',
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test_data']['langcode'] = [
|
||||
'title' => t('Langcode'),
|
||||
'help' => t('Langcode'),
|
||||
'field' => [
|
||||
'id' => 'language',
|
||||
],
|
||||
'argument' => [
|
||||
'id' => 'language',
|
||||
],
|
||||
'filter' => [
|
||||
'id' => 'language',
|
||||
],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function dataSet() {
|
||||
$data = parent::dataSet();
|
||||
$data[0]['langcode'] = 'en';
|
||||
$data[1]['langcode'] = 'xx-lolspeak';
|
||||
$data[2]['langcode'] = '';
|
||||
$data[3]['langcode'] = '';
|
||||
$data[4]['langcode'] = '';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\Config;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\language\Config\LanguageConfigOverride;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Config\LanguageConfigOverride
|
||||
* @group Config
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigOverrideTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Language configuration override.
|
||||
*
|
||||
* @var \Drupal\language\Config\LanguageConfigOverride
|
||||
*/
|
||||
protected $configTranslation;
|
||||
|
||||
/**
|
||||
* Storage.
|
||||
*
|
||||
* @var \Drupal\Core\Config\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* Event Dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* Typed Config.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $typedConfig;
|
||||
|
||||
/**
|
||||
* The mocked cache tags invalidator.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $cacheTagsInvalidator;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->storage = $this->getMock('Drupal\Core\Config\StorageInterface');
|
||||
$this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$this->typedConfig = $this->getMock('\Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
$this->configTranslation = new LanguageConfigOverride('config.test', $this->storage, $this->typedConfig, $this->eventDispatcher);
|
||||
$this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testSaveNew() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->assertTrue($this->configTranslation->isNew());
|
||||
$this->configTranslation->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testSaveExisting() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->configTranslation->initWithData([]);
|
||||
$this->configTranslation->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function testDelete() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->configTranslation->initWithData([]);
|
||||
$this->configTranslation->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity class.
|
||||
*
|
||||
* @group language
|
||||
* @coversDefaultClass \Drupal\language\Entity\ConfigurableLanguage
|
||||
* @see \Drupal\language\Entity\ConfigurableLanguage.
|
||||
*/
|
||||
class ConfigurableLanguageUnitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::getDirection
|
||||
*/
|
||||
public function testDirection() {
|
||||
// Direction of language writing, an integer. Usually either
|
||||
// ConfigurableLanguage::DIRECTION_LTR or
|
||||
// ConfigurableLanguage::DIRECTION_RTL.
|
||||
$configurableLanguage = new ConfigurableLanguage(['direction' => ConfigurableLanguage::DIRECTION_LTR], 'configurable_language');
|
||||
$this->assertEquals(ConfigurableLanguage::DIRECTION_LTR, $configurableLanguage->getDirection());
|
||||
|
||||
// Test direction again, setting direction to RTL.
|
||||
$configurableLanguage = new ConfigurableLanguage(['direction' => ConfigurableLanguage::DIRECTION_RTL], 'configurable_language');
|
||||
$this->assertEquals(ConfigurableLanguage::DIRECTION_RTL, $configurableLanguage->getDirection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getWeight
|
||||
* @covers ::setWeight
|
||||
*/
|
||||
public function testWeight() {
|
||||
// The weight, an integer. Used to order languages with larger positive
|
||||
// weights sinking items toward the bottom of lists.
|
||||
$configurableLanguage = new ConfigurableLanguage(['weight' => -5], 'configurable_language');
|
||||
$this->assertEquals($configurableLanguage->getWeight(), -5);
|
||||
$this->assertEquals($configurableLanguage->setWeight(13)->getWeight(), 13);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Entity\ContentLanguageSettings
|
||||
* @group language
|
||||
*/
|
||||
class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The entity type used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityTypeId;
|
||||
|
||||
/**
|
||||
* The UUID generator used for testing.
|
||||
*
|
||||
* @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $uuid;
|
||||
|
||||
/**
|
||||
* The typed configuration manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $typedConfigManager;
|
||||
|
||||
/**
|
||||
* The typed configuration manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\Entity\ConfigEntityStorage|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $configEntityStorageInterface;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityTypeId = $this->randomMachineName();
|
||||
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
|
||||
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
|
||||
|
||||
$this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
|
||||
$this->configEntityStorageInterface = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('config.typed', $this->typedConfigManager);
|
||||
$container->set('config.storage', $this->configEntityStorageInterface);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::calculateDependencies
|
||||
*/
|
||||
public function testCalculateDependencies() {
|
||||
// Mock the interfaces necessary to create a dependency on a bundle entity.
|
||||
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
$target_entity_type->expects($this->any())
|
||||
->method('getBundleConfigDependency')
|
||||
->will($this->returnValue(['type' => 'config', 'name' => 'test.test_entity_type.id']));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with('test_entity_type')
|
||||
->will($this->returnValue($target_entity_type));
|
||||
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
], 'language_content_settings');
|
||||
$dependencies = $config->calculateDependencies()->getDependencies();
|
||||
$this->assertContains('test.test_entity_type.id', $dependencies['config']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::id
|
||||
*/
|
||||
public function testId() {
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
], 'language_content_settings');
|
||||
$this->assertSame('test_entity_type.test_bundle', $config->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTargetEntityTypeId
|
||||
*/
|
||||
public function testTargetEntityTypeId() {
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
], 'language_content_settings');
|
||||
$this->assertSame('test_entity_type', $config->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTargetBundle
|
||||
*/
|
||||
public function testTargetBundle() {
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
], 'language_content_settings');
|
||||
$this->assertSame('test_bundle', $config->getTargetBundle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDefaultLangcode
|
||||
* @covers ::setDefaultLangcode
|
||||
*
|
||||
* @dataProvider providerDefaultLangcode
|
||||
*/
|
||||
public function testDefaultLangcode(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->getDefaultLangcode());
|
||||
}
|
||||
|
||||
public function providerDefaultLangcode() {
|
||||
$langcode = $this->randomMachineName();
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
], 'language_content_settings');
|
||||
$config->setDefaultLangcode($langcode);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
], 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$config, $langcode],
|
||||
[$defaultConfig, LanguageInterface::LANGCODE_SITE_DEFAULT],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setLanguageAlterable
|
||||
* @covers ::isLanguageAlterable
|
||||
*
|
||||
* @dataProvider providerLanguageAlterable
|
||||
*/
|
||||
public function testLanguageAlterable(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->isLanguageAlterable());
|
||||
}
|
||||
|
||||
public function providerLanguageAlterable() {
|
||||
$alterableConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
], 'language_content_settings');
|
||||
$alterableConfig->setLanguageAlterable(TRUE);
|
||||
|
||||
$nonAlterableConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
], 'language_content_settings');
|
||||
$nonAlterableConfig->setLanguageAlterable(FALSE);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
], 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$alterableConfig, TRUE],
|
||||
[$nonAlterableConfig, FALSE],
|
||||
[$defaultConfig, FALSE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isDefaultConfiguration
|
||||
*
|
||||
* @dataProvider providerIsDefaultConfiguration
|
||||
*/
|
||||
public function testIsDefaultConfiguration(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->isDefaultConfiguration());
|
||||
}
|
||||
|
||||
public function providerIsDefaultConfiguration() {
|
||||
$alteredLanguage = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
], 'language_content_settings');
|
||||
$alteredLanguage->setLanguageAlterable(TRUE);
|
||||
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
], 'language_content_settings');
|
||||
$alteredDefaultLangcode->setDefaultLangcode($this->randomMachineName());
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
], 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$alteredLanguage, FALSE],
|
||||
[$alteredDefaultLangcode, FALSE],
|
||||
[$defaultConfig, TRUE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::loadByEntityTypeBundle
|
||||
*
|
||||
* @dataProvider providerLoadByEntityTypeBundle
|
||||
*/
|
||||
public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $existing_config = NULL, $expected_langcode, $expected_language_alterable) {
|
||||
list($type, $bundle) = explode('.', $config_id);
|
||||
|
||||
$nullConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => $type,
|
||||
'target_bundle' => $bundle,
|
||||
], 'language_content_settings');
|
||||
$this->configEntityStorageInterface
|
||||
->expects($this->any())
|
||||
->method('load')
|
||||
->with($config_id)
|
||||
->will($this->returnValue($existing_config));
|
||||
$this->configEntityStorageInterface
|
||||
->expects($this->any())
|
||||
->method('create')
|
||||
->will($this->returnValue($nullConfig));
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('language_content_settings')
|
||||
->will($this->returnValue($this->configEntityStorageInterface));
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getEntityTypeFromClass')
|
||||
->with('Drupal\language\Entity\ContentLanguageSettings')
|
||||
->willReturn('language_content_settings');
|
||||
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle($type, $bundle);
|
||||
|
||||
$this->assertSame($expected_langcode, $config->getDefaultLangcode());
|
||||
$this->assertSame($expected_language_alterable, $config->isLanguageAlterable());
|
||||
}
|
||||
|
||||
public function providerLoadByEntityTypeBundle() {
|
||||
$alteredLanguage = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
], 'language_content_settings');
|
||||
$alteredLanguage->setLanguageAlterable(TRUE);
|
||||
|
||||
$langcode = $this->randomMachineName();
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
], 'language_content_settings');
|
||||
$alteredDefaultLangcode->setDefaultLangcode($langcode);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
], 'language_content_settings');
|
||||
|
||||
return [
|
||||
['test_entity_type.test_bundle', $alteredLanguage, LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE],
|
||||
['test_entity_type.test_fixed_language_bundle', $alteredDefaultLangcode, $langcode, FALSE],
|
||||
['test_entity_type.test_default_language_bundle', $defaultConfig, LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE],
|
||||
['test_entity_type.null_bundle', NULL, LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationUrlTest extends UnitTestCase {
|
||||
|
||||
protected $languageManager;
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
|
||||
// Set up some languages to be used by the language-based path processor.
|
||||
$language_de = $this->getMock('\Drupal\Core\Language\LanguageInterface');
|
||||
$language_de->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('de'));
|
||||
$language_en = $this->getMock('\Drupal\Core\Language\LanguageInterface');
|
||||
$language_en->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('en'));
|
||||
$languages = [
|
||||
'de' => $language_de,
|
||||
'en' => $language_en,
|
||||
];
|
||||
$this->languages = $languages;
|
||||
|
||||
// Create a language manager stub.
|
||||
$language_manager = $this->getMockBuilder('Drupal\language\ConfigurableLanguageManagerInterface')
|
||||
->getMock();
|
||||
$language_manager->expects($this->any())
|
||||
->method('getLanguages')
|
||||
->will($this->returnValue($languages));
|
||||
$this->languageManager = $language_manager;
|
||||
|
||||
// Create a user stub.
|
||||
$this->user = $this->getMockBuilder('Drupal\Core\Session\AccountInterface')
|
||||
->getMock();
|
||||
|
||||
$cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('cache_contexts_manager', $cache_contexts_manager);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test path prefix language negotiation and outbound path processing.
|
||||
*
|
||||
* @dataProvider providerTestPathPrefix
|
||||
*/
|
||||
public function testPathPrefix($prefix, $prefixes, $expected_langcode) {
|
||||
$this->languageManager->expects($this->any())
|
||||
->method('getCurrentLanguage')
|
||||
->will($this->returnValue($this->languages[(in_array($expected_langcode, ['en', 'de'])) ? $expected_langcode : 'en']));
|
||||
|
||||
$config = $this->getConfigFactoryStub([
|
||||
'language.negotiation' => [
|
||||
'url' => [
|
||||
'source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
|
||||
'prefixes' => $prefixes,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$request = Request::create('/' . $prefix . '/foo', 'GET');
|
||||
$method = new LanguageNegotiationUrl();
|
||||
$method->setLanguageManager($this->languageManager);
|
||||
$method->setConfig($config);
|
||||
$method->setCurrentUser($this->user);
|
||||
$this->assertEquals($expected_langcode, $method->getLangcode($request));
|
||||
|
||||
$cacheability = new BubbleableMetadata();
|
||||
$options = [];
|
||||
$method->processOutbound('foo', $options, $request, $cacheability);
|
||||
$expected_cacheability = new BubbleableMetadata();
|
||||
if ($expected_langcode) {
|
||||
$this->assertSame($prefix . '/', $options['prefix']);
|
||||
$expected_cacheability->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
|
||||
}
|
||||
else {
|
||||
$this->assertFalse(isset($options['prefix']));
|
||||
}
|
||||
$this->assertEquals($expected_cacheability, $cacheability);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for the path prefix test.
|
||||
*
|
||||
* @return array
|
||||
* An array of data for checking path prefix negotiation.
|
||||
*/
|
||||
public function providerTestPathPrefix() {
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => [
|
||||
'de' => 'de',
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
];
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'en-uk',
|
||||
'prefixes' => [
|
||||
'de' => 'de',
|
||||
'en' => 'en-uk',
|
||||
],
|
||||
'expected_langcode' => 'en',
|
||||
];
|
||||
// No configuration.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => [],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// Non-matching prefix.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => [
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// Non-existing language.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'it',
|
||||
'prefixes' => [
|
||||
'it' => 'it',
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
return $path_prefix_configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test domain language negotiation and outbound path processing.
|
||||
*
|
||||
* @dataProvider providerTestDomain
|
||||
*/
|
||||
public function testDomain($http_host, $domains, $expected_langcode) {
|
||||
$this->languageManager->expects($this->any())
|
||||
->method('getCurrentLanguage')
|
||||
->will($this->returnValue($this->languages['en']));
|
||||
|
||||
$config = $this->getConfigFactoryStub([
|
||||
'language.negotiation' => [
|
||||
'url' => [
|
||||
'source' => LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
'domains' => $domains,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$request = Request::create('', 'GET', [], [], [], ['HTTP_HOST' => $http_host]);
|
||||
$method = new LanguageNegotiationUrl();
|
||||
$method->setLanguageManager($this->languageManager);
|
||||
$method->setConfig($config);
|
||||
$method->setCurrentUser($this->user);
|
||||
$this->assertEquals($expected_langcode, $method->getLangcode($request));
|
||||
|
||||
$cacheability = new BubbleableMetadata();
|
||||
$options = [];
|
||||
$this->assertSame('foo', $method->processOutbound('foo', $options, $request, $cacheability));
|
||||
$expected_cacheability = new BubbleableMetadata();
|
||||
if ($expected_langcode !== FALSE && count($domains) > 1) {
|
||||
$expected_cacheability->setCacheMaxAge(Cache::PERMANENT)->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
|
||||
}
|
||||
$this->assertEquals($expected_cacheability, $cacheability);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for the domain test.
|
||||
*
|
||||
* @return array
|
||||
* An array of data for checking domain negotiation.
|
||||
*/
|
||||
public function providerTestDomain() {
|
||||
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.de',
|
||||
'domains' => [
|
||||
'de' => 'http://example.de',
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
];
|
||||
// No configuration.
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.de',
|
||||
'domains' => [],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// HTTP host with a port.
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.de:8080',
|
||||
'domains' => [
|
||||
'de' => 'http://example.de',
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
];
|
||||
// Domain configuration with https://.
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.de',
|
||||
'domains' => [
|
||||
'de' => 'https://example.de',
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
];
|
||||
// Non-matching HTTP host.
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.com',
|
||||
'domains' => [
|
||||
'de' => 'http://example.com',
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
];
|
||||
// Testing a non-existing language.
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.com',
|
||||
'domains' => [
|
||||
'it' => 'http://example.it',
|
||||
],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// Multiple domain configurations.
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.com',
|
||||
'domains' => [
|
||||
'de' => 'http://example.de',
|
||||
'en' => 'http://example.com',
|
||||
],
|
||||
'expected_langcode' => 'en',
|
||||
];
|
||||
return $domain_configuration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @todo Remove as part of https://www.drupal.org/node/2481833.
|
||||
namespace Drupal\language\Plugin\LanguageNegotiation;
|
||||
|
||||
if (!function_exists('base_path')) {
|
||||
function base_path() {
|
||||
return '/';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\Menu;
|
||||
|
||||
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
|
||||
|
||||
/**
|
||||
* Tests existence of language local tasks.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->directoryList = [
|
||||
'language' => 'core/modules/language',
|
||||
];
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language admin overview local tasks existence.
|
||||
*
|
||||
* @dataProvider getLanguageAdminOverviewRoutes
|
||||
*/
|
||||
public function testLanguageAdminLocalTasks($route, $expected) {
|
||||
$this->assertLocalTasks($route, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function getLanguageAdminOverviewRoutes() {
|
||||
return [
|
||||
['entity.configurable_language.collection', [['entity.configurable_language.collection', 'language.negotiation']]],
|
||||
['language.negotiation', [['entity.configurable_language.collection', 'language.negotiation']]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language edit local tasks existence.
|
||||
*/
|
||||
public function testLanguageEditLocalTasks() {
|
||||
$this->assertLocalTasks('entity.configurable_language.edit_form', [
|
||||
0 => ['entity.configurable_language.edit_form'],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,86 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\process;
|
||||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageNegotiation;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
use Drupal\migrate\MigrateException;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
public function testStringInput() {
|
||||
$this->plugin = new LanguageNegotiation([], 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'The input should be an array');
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\process;
|
||||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageTypes;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
use Drupal\migrate\MigrateException;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
public function testStringInput() {
|
||||
$this->plugin = new LanguageTypes([], 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'The input should be an array');
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
name: 'Test Module'
|
||||
type: module
|
||||
description: 'Support module for testing.'
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-19
|
||||
version: '8.3.1'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1492622988
|
||||
Reference in New Issue
Block a user