Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -131,3 +131,11 @@ condition.plugin.language:
type: sequence
sequence:
type: string
field.widget.settings.language_select:
type: mapping
label: 'Language format settings'
mapping:
include_locked:
type: boolean
label: 'Include locked languages'

View file

@ -0,0 +1,44 @@
/**
* @file
* Language admin behavior.
*/
(function($, Drupal) {
/**
* Makes language negotiation inherit user interface negotiation.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attach behavior to language negotiation admin user interface.
*/
Drupal.behaviors.negotiationLanguage = {
attach() {
const $configForm = $('#language-negotiation-configure-form');
const inputSelector = 'input[name$="[configurable]"]';
// Given a customization checkbox derive the language type being changed.
function toggleTable(checkbox) {
const $checkbox = $(checkbox);
// Get the language detection type such as Interface text language
// detection or Content language detection.
$checkbox
.closest('.table-language-group')
.find('table, .tabledrag-toggle-weight')
.toggle($checkbox.prop('checked'));
}
// Bind hide/show and rearrange customization checkboxes.
$configForm
.once('negotiation-language-admin-bind')
.on('change', inputSelector, event => {
toggleTable(event.target);
});
// Initially, hide language detection types that are not customized.
$configForm
.find(`${inputSelector}:not(:checked)`)
.each((index, element) => {
toggleTable(element);
});
},
};
})(jQuery, Drupal);

View file

@ -1,43 +1,29 @@
/**
* @file
* Language admin behavior.
*/
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function ($, Drupal) {
'use strict';
/**
* Makes language negotiation inherit user interface negotiation.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attach behavior to language negotiation admin user interface.
*/
Drupal.behaviors.negotiationLanguage = {
attach: function () {
attach: function attach() {
var $configForm = $('#language-negotiation-configure-form');
var inputSelector = 'input[name$="[configurable]"]';
// Given a customization checkbox derive the language type being changed.
function toggleTable(checkbox) {
var $checkbox = $(checkbox);
// Get the language detection type such as Interface text language
// detection or Content language detection.
$checkbox.closest('.table-language-group')
.find('table, .tabledrag-toggle-weight')
.toggle($checkbox.prop('checked'));
$checkbox.closest('.table-language-group').find('table, .tabledrag-toggle-weight').toggle($checkbox.prop('checked'));
}
// Bind hide/show and rearrange customization checkboxes.
$configForm.once('negotiation-language-admin-bind').on('change', inputSelector, function (event) {
toggleTable(event.target);
});
// Initially, hide language detection types that are not customized.
$configForm.find(inputSelector + ':not(:checked)').each(function (index, element) {
toggleTable(element);
});
}
};
})(jQuery, Drupal);
})(jQuery, Drupal);

View file

@ -15,7 +15,6 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\language\ConfigurableLanguageInterface;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
@ -43,15 +42,15 @@ function language_help($route_name, RouteMatchInterface $route_match) {
$output .= '<dt>' . t('Making a block visible per language') . '</dt>';
$output .= '<dd>' . t('If the Block module is enabled, then the Language module allows you to set the visibility of a block based on selected languages on the <a href=":blocks">Block layout</a> page.', [':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</dd>';
$output .= '<dt>' . t('Choosing user languages') . '</dt>';
$output .= '<dd>' . t('Users can choose a <em>Site language</em> on their profile page. This language is used for email messages, and can be used by modules to determine a user\'s language. It can also be used for interface text, if the <em>User</em> method is enabled as a <em>Detection and selection</em> method (see below). Administrative users can choose a separate <em>Administration pages language</em> for the interface text on administration pages. This configuration is only available on the user\'s profile page if the <em>Account administration pages</em> method is enabled (see below).') . '</dd>';
$output .= '<dd>' . t("Users can choose a <em>Site language</em> on their profile page. This language is used for email messages, and can be used by modules to determine a user's language. It can also be used for interface text, if the <em>User</em> method is enabled as a <em>Detection and selection</em> method (see below). Administrative users can choose a separate <em>Administration pages language</em> for the interface text on administration pages. This configuration is only available on the user's profile page if the <em>Account administration pages</em> method is enabled (see below).") . '</dd>';
$output .= '<dt>' . t('Language detection and selection') . '</dt>';
$output .= '<dd>' . t('The <a href=":detection">Detection and selection</a> page provides several methods for deciding which language is used for displaying interface text. When a method detects and selects an interface language, then the following methods in the list are not applied. You can order them by importance, with your preferred method at the top of the list, followed by one or several fall-back methods.', [':detection' => \Drupal::url('language.negotiation')]);
$output .= '<ul><li>' . t('<em>URL</em> sets the interface language based on a path prefix or domain (for example specifying <em>de</em> for German would result in URLs like <em>example.com/de/contact</em>). The default language does not require a path prefix, but can have one assigned as well. If the language detection is done by domain name, a domain needs to be specified for each language.') . '</li>';
$output .= '<li>' . t('<em>Session</em> determines the interface language from a request or session parameter (for example <em>example.com?language=de</em> would set the interface language to German based on the use of <em>de</em> as the <em>language</em> parameter).') . '</li>';
$output .= '<li>' . t('<em>User</em> follows the language configuration set on the user\'s profile page.') . '</li>';
$output .= '<li>' . t("<em>User</em> follows the language configuration set on the user's profile page.") . '</li>';
$output .= '<li>' . t('<em>Browser</em> sets the interface language based on the browser\'s language settings. Since browsers use different language codes to refer to the same languages, you can add and edit languages codes to map the browser language codes to the <a href=":language_list">language codes</a> used on your site.', [':language_list' => \Drupal::url('entity.configurable_language.collection')]) . '</li>';
$output .= '<li>' . t('<em>Account administration pages</em> follows the configuration set as <em>Administration pages language</em> on the profile page of an administrative user. This method is similar to the <em>User</em> method, but only sets the interface text language on administration pages, independent of the interface text language on other pages.') . '</li>';
$output .= '<li>' . t('<em>Selected language</em> allows you to specify the site\'s default language or a specific language as the fall-back language. This method should be listed last.') . '</li></ul></dd>';
$output .= '<li>' . t("<em>Selected language</em> allows you to specify the site's default language or a specific language as the fall-back language. This method should be listed last.") . '</li></ul></dd>';
$output .= '</dl>';
return $output;
@ -193,7 +192,7 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_
$bundle = $values['bundle'];
$form_object = $form_state->getFormObject();
if ($form_object instanceof EntityFormInterface) {
/** @var EntityFormInterface $form_object */
/** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
$entity = $form_object->getEntity();
if ($entity->getEntityType()->getBundleOf()) {
$bundle = $entity->id();
@ -205,7 +204,7 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_
$config->setLanguageAlterable($form_state->getValue([$element_name, 'language_alterable']));
$config->save();
// Set the form_state languaged with the updated bundle.
// Set the form_state language with the updated bundle.
$form_state->set('language', $language);
}
}
@ -272,6 +271,8 @@ function language_get_default_langcode($entity_type, $bundle) {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal::config('language.negotiation')->get('url.prefixes') instead.
*
* @see https://www.drupal.org/node/2912748
*/
function language_negotiation_url_prefixes() {
return \Drupal::config('language.negotiation')->get('url.prefixes');
@ -301,6 +302,8 @@ function language_negotiation_url_prefixes_update() {
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* Use \Drupal::config('language.negotiation')->get('url.domains') instead.
*
* @see https://www.drupal.org/node/2912748
*/
function language_negotiation_url_domains() {
return \Drupal::config('language.negotiation')->get('url.domains');
@ -342,38 +345,6 @@ function language_modules_uninstalled($modules) {
language_modules_installed($modules);
}
/**
* Implements hook_ENTITY_TYPE_insert() for 'configurable_language'.
*/
function language_configurable_language_insert(ConfigurableLanguageInterface $language) {
if ($language->isLocked()) {
return;
}
// Add language to the list of language domains.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$domains = $config->get('url.domains');
$domains[$language->id()] = '';
$config->set('url.domains', $domains)->save();
}
/**
* Implements hook_ENTITY_TYPE_delete() for 'configurable_language'.
*/
function language_configurable_language_delete(ConfigurableLanguageInterface $language) {
// Remove language from language prefix list.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$prefixes = $config->get('url.prefixes');
unset($prefixes[$language->id()]);
$config->set('url.prefixes', $prefixes)->save();
// Remove language from language domain list.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$domains = $config->get('url.domains');
unset($domains[$language->id()]);
$config->set('url.domains', $domains)->save();
}
/**
* Implements hook_preprocess_HOOK() for block templates.
*/

View file

@ -0,0 +1,28 @@
<?php
/**
* @file
* Post update functions for Language module.
*/
use Drupal\Core\Entity\Entity\EntityFormDisplay;
/**
* Add the 'include_locked' settings to the 'language_select' widget.
*/
function language_post_update_language_select_widget() {
foreach (EntityFormDisplay::loadMultiple() as $display_form) {
$content = $display_form->get('content');
$changed = FALSE;
foreach (array_keys($content) as $element) {
if (isset($content[$element]['type']) && $content[$element]['type'] == 'language_select') {
$content[$element]['settings']['include_locked'] = TRUE;
$changed = TRUE;
}
}
if ($changed) {
$display_form->set('content', $content);
$display_form->save();
}
}
}

View file

@ -0,0 +1,21 @@
id: d6_language_content_menu_settings
label: Drupal 6 language content menu settings
migration_tags:
- Drupal 6
- Configuration
source:
plugin: extension
name: i18nmenu
constants:
target_type: 'menu_link_content'
langcode: 'site_default'
process:
target_entity_type_id: 'constants/target_type'
# menu_link_content has a bundle key but no bundle support so use the entity
# type as the bundle.
target_bundle: 'constants/target_type'
default_langcode: 'constants/langcode'
# Drupal 6 menus are translated when the i18nmenu module is enabled.
language_alterable: status
destination:
plugin: entity:language_content_settings

View file

@ -1,8 +1,8 @@
id: d6_language_content_settings
label: Drupal 6 language content settings
migration_tags:
- Drupal 6
- Configuration
source:
plugin: d6_language_content_settings
constants:

View file

@ -0,0 +1,53 @@
id: d6_language_content_taxonomy_vocabulary_settings
label: Drupal 6 language taxonomy vocabulary settings
migration_tags:
- Drupal 6
- Configuration
source:
plugin: d6_language_content_settings_taxonomy_vocabulary
constants:
target_type: 'taxonomy_term'
default_langcode: 'site_default'
process:
target_bundle:
-
plugin: migration_lookup
migration: d6_taxonomy_vocabulary
source: vid
-
plugin: skip_on_empty
method: row
# State is the value in the i18ntaxonomy_vocabulary array defined as:
# 0: No multilingual options.
# 1: Localizable terms. Run through the localization system.
# 2: Predefined language for a vocabulary and its terms.
# 3: Per-language terms, translatable (referencing terms with different
# languages) but not localizable.
language_alterable:
plugin: static_map
source: state
map:
0: false
1: true
2: false
3: true
'third_party_settings/content_translation/enabled':
plugin: static_map
source: state
map:
0: false
1: true
2: false
3: false
target_entity_type_id: 'constants/target_type'
default_langcode:
plugin: default_value
default_value: site_default
source: language
destination:
plugin: entity:language_content_settings
content_translation_update_definitions:
- taxonomy_term
migration_dependencies:
required:
- d6_taxonomy_vocabulary

View file

@ -2,10 +2,12 @@ id: d6_language_negotiation_settings
label: Language negotiation settings
migration_tags:
- Drupal 6
- Configuration
source:
plugin: variable
variables:
- language_negotiation
source_module: language
process:
session/parameter:
plugin: default_value

View file

@ -2,10 +2,12 @@ id: d6_language_types
label: Language types
migration_tags:
- Drupal 6
- Configuration
source:
plugin: variable
variables:
- language_negotiation
source_module: language
process:
all:
plugin: default_value

View file

@ -2,6 +2,7 @@ id: d7_language_content_settings
label: Drupal 7 language content settings
migration_tags:
- Drupal 7
- Configuration
source:
plugin: d7_language_content_settings
constants:
@ -19,6 +20,8 @@ process:
0: NULL
1: 'current_interface'
2: 'current_interface'
4: 'und'
default_value: NULL
-
plugin: skip_on_empty
method: row
@ -37,6 +40,7 @@ process:
0: NULL
1: false
2: true
4: true
destination:
plugin: entity:language_content_settings
content_translation_update_definitions:

View file

@ -2,11 +2,13 @@ id: d7_language_negotiation_settings
label: Language negotiation settings
migration_tags:
- Drupal 7
- Configuration
source:
plugin: variable
variables:
- locale_language_negotiation_session_param
- locale_language_negotiation_url_part
source_module: locale
process:
session/parameter:
plugin: default_value

View file

@ -2,6 +2,7 @@ id: d7_language_types
label: Language types
migration_tags:
- Drupal 7
- Configuration
source:
plugin: variable
variables:
@ -12,6 +13,7 @@ source:
- locale_language_providers_weight_language
- locale_language_providers_weight_language_content
- locale_language_providers_weight_language_url
source_module: language
process:
all:
plugin: language_types

View file

@ -3,10 +3,12 @@ label: Default language
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: variable
variables:
- language_default
source_module: locale
process:
default_langcode:
-

View file

@ -3,6 +3,7 @@ label: Languages
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: language
process:

View file

@ -3,6 +3,7 @@ label: Language prefixes and domains
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: language
fetch_all: true

View file

@ -75,7 +75,7 @@ class LanguageConfigFactoryOverride extends ConfigFactoryOverrideBase implements
$this->baseStorage = $storage;
$this->eventDispatcher = $event_dispatcher;
$this->typedConfigManager = $typed_config;
// Prior to negiotiation the override language should be the default
// Prior to negotiation the override language should be the default
// language.
$this->language = $default_language->get();
}

View file

@ -426,7 +426,12 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
}
/**
* {@inheritdoc}
* Sets the configuration override language.
*
* @param \Drupal\Core\Language\LanguageInterface $language
* The language to override configuration with.
*
* @return $this
*/
public function setConfigOverrideLanguage(LanguageInterface $language = NULL) {
$this->configFactoryOverride->setLanguage($language);

View file

@ -16,6 +16,13 @@ use Drupal\language\ConfigurableLanguageInterface;
* @ConfigEntityType(
* id = "configurable_language",
* label = @Translation("Language"),
* label_collection = @Translation("Languages"),
* label_singular = @Translation("language"),
* label_plural = @Translation("languages"),
* label_count = @PluralTranslation(
* singular = "@count language",
* plural = "@count languages",
* ),
* handlers = {
* "list_builder" = "Drupal\language\LanguageListBuilder",
* "access" = "Drupal\language\LanguageAccessControlHandler",
@ -139,6 +146,14 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu
// Install any available language configuration overrides for the language.
\Drupal::service('language.config_factory_override')->installLanguageOverrides($this->id());
}
if (!$this->isLocked() && !$update) {
// Add language to the list of language domains.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$domains = $config->get('url.domains');
$domains[$this->id()] = '';
$config->set('url.domains', $domains)->save();
}
}
/**
@ -173,6 +188,12 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu
if (!\Drupal::languageManager()->isMultilingual()) {
ConfigurableLanguageManager::rebuildServices();
}
// Remove language from language prefix and domain list.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$config->clear('url.prefixes.' . $entity->id());
$config->clear('url.domains.' . $entity->id());
$config->save();
}
/**

View file

@ -14,6 +14,13 @@ use Drupal\language\ContentLanguageSettingsInterface;
* @ConfigEntityType(
* id = "language_content_settings",
* label = @Translation("Content Language Settings"),
* label_collection = @Translation("Content Language Settings"),
* label_singular = @Translation("content language setting"),
* label_plural = @Translation("content languages settings"),
* label_count = @PluralTranslation(
* singular = "@count content language setting",
* plural = "@count content languages settings",
* ),
* admin_permission = "administer languages",
* config_prefix = "content_settings",
* entity_keys = {

View file

@ -81,7 +81,7 @@ class ConfigSubscriber implements EventSubscriberInterface {
* then this event must be changed to work with both the old and new schema
* definition so this event is update safe.
*
* @param ConfigCrudEvent $event
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The configuration event.
*/
public function onConfigSave(ConfigCrudEvent $event) {

View file

@ -2,6 +2,7 @@
namespace Drupal\language\EventSubscriber;
use Drupal\Core\DrupalKernelInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\Translator\TranslatorInterface;
use Drupal\language\ConfigurableLanguageManagerInterface;
@ -33,14 +34,14 @@ class LanguageRequestSubscriber implements EventSubscriberInterface {
/**
* The translation service.
*
* @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface;
* @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface
*/
protected $translation;
/**
* The current active user.
*
* @return \Drupal\Core\Session\AccountInterface
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
@ -51,7 +52,7 @@ class LanguageRequestSubscriber implements EventSubscriberInterface {
* The language manager service.
* @param \Drupal\language\LanguageNegotiatorInterface $negotiator
* The language negotiator.
* @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translation;
* @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translation
* The translation service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current active user.
@ -64,25 +65,39 @@ class LanguageRequestSubscriber implements EventSubscriberInterface {
}
/**
* Sets the default language and initializes configuration overrides.
* Initializes the language manager at the beginning of the request.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The Event to process.
*/
public function onKernelRequestLanguage(GetResponseEvent $event) {
if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
$this->negotiator->setCurrentUser($this->currentUser);
if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
$this->languageManager->setNegotiator($this->negotiator);
$this->languageManager->setConfigOverrideLanguage($this->languageManager->getCurrentLanguage());
}
// After the language manager has initialized, set the default langcode
// for the string translations.
$langcode = $this->languageManager->getCurrentLanguage()->getId();
$this->translation->setDefaultLangcode($langcode);
$this->setLanguageOverrides();
}
}
/**
* Initializes config overrides whenever the service container is rebuilt.
*/
public function onContainerInitializeSubrequestFinished() {
$this->setLanguageOverrides();
}
/**
* Sets the language for config overrides on the language manager.
*/
private function setLanguageOverrides() {
$this->negotiator->setCurrentUser($this->currentUser);
if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
$this->languageManager->setNegotiator($this->negotiator);
$this->languageManager->setConfigOverrideLanguage($this->languageManager->getCurrentLanguage());
}
// After the language manager has initialized, set the default langcode for
// the string translations.
$langcode = $this->languageManager->getCurrentLanguage()->getId();
$this->translation->setDefaultLangcode($langcode);
}
/**
* Registers the methods in this class that should be listeners.
*
@ -91,6 +106,7 @@ class LanguageRequestSubscriber implements EventSubscriberInterface {
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = ['onKernelRequestLanguage', 255];
$events[DrupalKernelInterface::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED][] = ['onContainerInitializeSubrequestFinished', 255];
return $events;
}

View file

@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure the content language settings for this site.
*
* @internal
*/
class ContentLanguageSettingsForm extends FormBase {
@ -155,7 +157,7 @@ class ContentLanguageSettingsForm extends FormBase {
->save();
}
}
drupal_set_message($this->t('Settings successfully updated.'));
$this->messenger()->addStatus($this->t('Settings successfully updated.'));
}
}

View file

@ -9,6 +9,8 @@ use Drupal\language\Entity\ConfigurableLanguage;
/**
* Controller for language addition forms.
*
* @internal
*/
class LanguageAddForm extends LanguageFormBase {
@ -86,12 +88,12 @@ class LanguageAddForm extends LanguageFormBase {
$t_args = ['%language' => $this->entity->label(), '%langcode' => $this->entity->id()];
$this->logger('language')->notice('The %language (%langcode) language has been created.', $t_args);
drupal_set_message($this->t('The language %language has been created and can now be used.', $t_args));
$this->messenger()->addStatus($this->t('The language %language has been created and can now be used.', $t_args));
if ($this->moduleHandler->moduleExists('block')) {
// Tell the user they have the option to add a language switcher block
// to their theme so they can switch between the languages.
drupal_set_message($this->t('Use one of the language switcher blocks to allow site visitors to switch between languages. You can enable these blocks on the <a href=":block-admin">block administration page</a>.', [':block-admin' => $this->url('block.admin_display')]));
$this->messenger()->addStatus($this->t('Use one of the language switcher blocks to allow site visitors to switch between languages. You can enable these blocks on the <a href=":block-admin">block administration page</a>.', [':block-admin' => $this->url('block.admin_display')]));
}
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
}

View file

@ -6,6 +6,8 @@ use Drupal\Core\Entity\EntityDeleteForm;
/**
* Defines a confirmation form for deleting a language entity.
*
* @internal
*/
class LanguageDeleteForm extends EntityDeleteForm {

View file

@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Controller for language edit forms.
*
* @internal
*/
class LanguageEditForm extends LanguageFormBase {

View file

@ -50,11 +50,11 @@ abstract class LanguageFormBase extends EntityForm {
$form['langcode_view'] = [
'#type' => 'item',
'#title' => $this->t('Language code'),
'#markup' => $language->id()
'#markup' => $language->id(),
];
$form['langcode'] = [
'#type' => 'value',
'#value' => $language->id()
'#value' => $language->id(),
];
}
else {

View file

@ -9,6 +9,8 @@ use Drupal\Core\Url;
/**
* Defines a confirmation form for deleting a browser language negotiation mapping.
*
* @internal
*/
class NegotiationBrowserDeleteForm extends ConfirmFormBase {
use ConfigFormBaseTrait;
@ -27,7 +29,6 @@ class NegotiationBrowserDeleteForm extends ConfirmFormBase {
return ['language.mappings'];
}
/**
* {@inheritdoc}
*/
@ -74,7 +75,7 @@ class NegotiationBrowserDeleteForm extends ConfirmFormBase {
$this->logger('language')->notice('The browser language detection mapping for the %browser browser language code has been deleted.', $args);
drupal_set_message($this->t('The mapping for the %browser browser language code has been deleted.', $args));
$this->messenger()->addStatus($this->t('The mapping for the %browser browser language code has been deleted.', $args));
$form_state->setRedirect('language.negotiation_browser');
}

View file

@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure the browser language negotiation method for this site.
*
* @internal
*/
class NegotiationBrowserForm extends ConfigFormBase {
@ -23,11 +25,8 @@ class NegotiationBrowserForm extends ConfigFormBase {
/**
* {@inheritdoc}
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler
*/
public function __construct(ConfigFactoryInterface $config_factory, ConfigurableLanguageManagerInterface $language_manager ) {
public function __construct(ConfigFactoryInterface $config_factory, ConfigurableLanguageManagerInterface $language_manager) {
parent::__construct($config_factory);
$this->languageManager = $language_manager;
}

View file

@ -3,7 +3,6 @@
namespace Drupal\language\Form;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
@ -17,6 +16,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure the selected language negotiation method for this site.
*
* @internal
*/
class NegotiationConfigureForm extends ConfigFormBase {
@ -202,7 +203,7 @@ class NegotiationConfigureForm extends ConfigFormBase {
$this->blockManager->clearCachedDefinitions();
$form_state->setRedirect('language.negotiation');
drupal_set_message($this->t('Language detection configuration saved.'));
$this->messenger()->addStatus($this->t('Language detection configuration saved.'));
}
/**
@ -213,7 +214,7 @@ class NegotiationConfigureForm extends ConfigFormBase {
* @param string $type
* The language type to generate the table for.
*/
protected function configureFormTable(array &$form, $type) {
protected function configureFormTable(array &$form, $type) {
$info = $form['#language_types_info'][$type];
$table_form = [
@ -234,7 +235,7 @@ class NegotiationConfigureForm extends ConfigFormBase {
'#attributes' => ['class' => ['language-customization-checkbox']],
'#attached' => [
'library' => [
'language/drupal.language.admin'
'language/drupal.language.admin',
],
],
];
@ -274,7 +275,7 @@ class NegotiationConfigureForm extends ConfigFormBase {
$table_form['weight'][$method_id] = [
'#type' => 'weight',
'#title' => $this->t('Weight for @title language detection method', ['@title' => Unicode::strtolower($method_name)]),
'#title' => $this->t('Weight for @title language detection method', ['@title' => mb_strtolower($method_name)]),
'#title_display' => 'invisible',
'#default_value' => $weight,
'#attributes' => ['class' => ["language-method-weight-$type"]],
@ -285,7 +286,7 @@ class NegotiationConfigureForm extends ConfigFormBase {
$table_form['enabled'][$method_id] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable @title language detection method', ['@title' => Unicode::strtolower($method_name)]),
'#title' => $this->t('Enable @title language detection method', ['@title' => mb_strtolower($method_name)]),
'#title_display' => 'invisible',
'#default_value' => $enabled,
];

View file

@ -8,6 +8,8 @@ use Drupal\Core\Form\ConfigFormBase;
/**
* Configure the selected language negotiation method for this site.
*
* @internal
*/
class NegotiationSelectedForm extends ConfigFormBase {

View file

@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Configure the session language negotiation method for this site.
*
* @internal
*/
class NegotiationSessionForm extends ConfigFormBase {

View file

@ -12,6 +12,8 @@ use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
/**
* Configure the URL language negotiation method for this site.
*
* @internal
*/
class NegotiationUrlForm extends ConfigFormBase {

View file

@ -60,7 +60,6 @@ class PathProcessorLanguage implements InboundPathProcessorInterface, OutboundPa
*/
protected $configSubscriber;
/**
* Constructs a PathProcessorLanguage object.
*
@ -147,7 +146,7 @@ class PathProcessorLanguage implements InboundPathProcessorInterface, OutboundPa
// Sort the processors list, so that their functions are called in the
// order specified by the weight of the methods.
uksort($this->processors[$scope], function ($method_id_a, $method_id_b) use($weights) {
uksort($this->processors[$scope], function ($method_id_a, $method_id_b) use ($weights) {
$a_weight = $weights[$method_id_a];
$b_weight = $weights[$method_id_b];

View file

@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -37,6 +38,13 @@ class LanguageListBuilder extends DraggableListBuilder {
*/
protected $configFactory;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* {@inheritdoc}
*/
@ -45,7 +53,8 @@ class LanguageListBuilder extends DraggableListBuilder {
$entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('language_manager'),
$container->get('config.factory')
$container->get('config.factory'),
$container->get('messenger')
);
}
@ -60,11 +69,14 @@ class LanguageListBuilder extends DraggableListBuilder {
* The language manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory) {
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory, MessengerInterface $messenger) {
parent::__construct($entity_type, $storage);
$this->languageManager = $language_manager;
$this->configFactory = $config_factory;
$this->messenger = $messenger;
}
/**
@ -154,7 +166,7 @@ class LanguageListBuilder extends DraggableListBuilder {
$this->languageManager->updateLockedLanguageWeights();
}
drupal_set_message(t('Configuration saved.'));
$this->messenger->addStatus($this->t('Configuration saved.'));
// Force the redirection to the page with the language we have just
// selected as default.
$form_state->setRedirectUrl($this->entities[$new_id]->urlInfo('collection', ['language' => $this->entities[$new_id]]));

View file

@ -28,7 +28,7 @@ abstract class LanguageNegotiationMethodBase implements LanguageNegotiationMetho
/**
* The current active user.
*
* @return \Drupal\Core\Session\AccountInterface
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;

View file

@ -24,7 +24,7 @@ interface LanguageNegotiationMethodInterface {
/**
* Injects the configuration factory.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The configuration factory.
*/
public function setConfig(ConfigFactoryInterface $config);

View file

@ -38,7 +38,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
/**
* The settings instance.
*
* @return \Drupal\Core\Site\Settings
* @var \Drupal\Core\Site\Settings
*/
protected $settings;
@ -52,7 +52,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
/**
* The current active user.
*
* @return \Drupal\Core\Session\AccountInterface
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
@ -74,7 +74,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface {
* Constructs a new LanguageNegotiator object.
*
* @param \Drupal\language\ConfigurableLanguageManagerInterface $language_manager
* The language manager.
* The language manager.
* @param \Drupal\Component\Plugin\PluginManagerInterface $negotiator_manager
* The language negotiation methods plugin manager
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory

View file

@ -91,7 +91,6 @@ use Drupal\Core\Session\AccountInterface;
* }
* }
* }
* ?>
* @endcode
*
* For more information, see

View file

@ -70,7 +70,7 @@ class LanguageServiceProvider extends ServiceProviderBase {
// and caching. This might prove difficult as this is called before the
// container has finished building.
$config_storage = BootstrapConfigStorageFactory::get();
$config_ids = array_filter($config_storage->listAll($prefix), function($config_id) use ($prefix) {
$config_ids = array_filter($config_storage->listAll($prefix), function ($config_id) use ($prefix) {
return $config_id != $prefix . LanguageInterface::LANGCODE_NOT_SPECIFIED && $config_id != $prefix . LanguageInterface::LANGCODE_NOT_APPLICABLE;
});
return count($config_ids) > 1;

View file

@ -57,7 +57,6 @@ class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface
$this->pathMatcher = $path_matcher;
}
/**
* {@inheritdoc}
*/
@ -71,7 +70,6 @@ class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface
);
}
/**
* {@inheritdoc}
*/

View file

@ -104,7 +104,7 @@ class Language extends ConditionPluginBase implements ContainerFactoryPluginInte
$language_list = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
$selected = $this->configuration['langcodes'];
// Reduce the language list to an array of language names.
$language_names = array_reduce($language_list, function(&$result, $item) use ($selected) {
$language_names = array_reduce($language_list, function (&$result, $item) use ($selected) {
// If the current item of the $language_list array is one of the selected
// languages, add it to the $results array.
if (!empty($selected[$item->getId()])) {

View file

@ -20,7 +20,7 @@ class LanguageDomains extends ArrayBuild {
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if ($row->getSourceProperty('domain_negotiation')) {
if ($row->getSourceProperty('domain_negotiation_used')) {
global $base_url;
foreach ($value as $old_key => $old_value) {

View file

@ -8,7 +8,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* @MigrateSource(
* id = "language",
* source_provider = "locale"
* source_module = "locale"
* )
*/
class Language extends DrupalSqlBase {
@ -66,7 +66,7 @@ class Language extends DrupalSqlBase {
// when the 'language_negotiation' variable is set to '3', and in D7, when
// the 'locale_language_negotiation_url_part' variable is set to '1'.
if ($this->variableGet('language_negotiation', 0) == 3 || $this->variableGet('locale_language_negotiation_url_part', 0) == 1) {
$row->setSourceProperty('domain_negotiation', TRUE);
$row->setSourceProperty('domain_negotiation_used', TRUE);
}
}

View file

@ -10,6 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d6_language_content_settings",
* source_module = "locale"
* )
*/
class LanguageContentSettings extends DrupalSqlBase {

View file

@ -0,0 +1,65 @@
<?php
namespace Drupal\language\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 6 i18n vocabularies source from database.
*
* @MigrateSource(
* id = "d6_language_content_settings_taxonomy_vocabulary",
* source_module = "taxonomy"
* )
*/
class LanguageContentSettingsTaxonomyVocabulary extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('vocabulary', 'v')
->fields('v', ['vid', 'language']);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'vid' => $this->t('The vocabulary ID.'),
'language' => $this->t('The default language for new terms.'),
'state' => $this->t('The i18n taxonomy translation setting.'),
];
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Get the i18n taxonomy translation setting for this vocabulary.
// 0 - No multilingual options
// 1 - Localizable terms. Run through the localization system.
// 2 - Predefined language for a vocabulary and its terms.
// 3 - Per-language terms, translatable (referencing terms with different
// languages) but not localizable.
$i18ntaxonomy_vocabulary = $this->variableGet('i18ntaxonomy_vocabulary', NULL);
$vid = $row->getSourceProperty('vid');
$state = FALSE;
if (array_key_exists($vid, $i18ntaxonomy_vocabulary)) {
$state = $i18ntaxonomy_vocabulary[$vid];
}
$row->setSourceProperty('state', $state);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['vid']['type'] = 'integer';
return $ids;
}
}

View file

@ -10,6 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d7_language_content_settings",
* source_module = "locale"
* )
*/
class LanguageContentSettings extends DrupalSqlBase {

View file

@ -5,4 +5,4 @@ core: 8.x
package: Testing
version: VERSION
dependencies:
- entity_test
- drupal:entity_test

View file

@ -8,6 +8,8 @@ use Drupal\language\Entity\ContentLanguageSettings;
/**
* A form containing a language configuration element.
*
* @internal
*/
class LanguageConfigurationElement extends FormBase {

View file

@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* A form containing a language select element.
*
* @internal
*/
class LanguageConfigurationElementTest extends FormBase {

View file

@ -15,7 +15,7 @@ use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
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()]));
\Drupal::messenger()->addStatus(t('Language negotiation method: @name', ['@name' => \Drupal::languageManager()->getNegotiatedLanguageMethod()]));
}
}

View file

@ -53,7 +53,7 @@ class LanguageTestController implements ContainerInjectionInterface {
/**
* Route entity upcasting test helper.
*
* @param \Drupal\language\ConfigurableLanguageInterface $language
* @param \Drupal\language\ConfigurableLanguageInterface $configurable_language
* The ConfigurableLanguage object from the route.
*
* @return string

View file

@ -1,8 +1,8 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests entity type without language support.
@ -12,7 +12,7 @@ use Drupal\simpletest\WebTestBase;
*
* @group language
*/
class EntityTypeWithoutLanguageFormTest extends WebTestBase {
class EntityTypeWithoutLanguageFormTest extends BrowserTestBase {
/**
* Modules to enable.

View file

@ -0,0 +1,30 @@
<?php
namespace Drupal\Tests\language\Functional\Hal;
use Drupal\Tests\language\Functional\Rest\ConfigurableLanguageResourceTestBase;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group hal
*/
class ConfigurableLanguageHalJsonAnonTest extends ConfigurableLanguageResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}

View file

@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\language\Functional\Hal;
use Drupal\Tests\language\Functional\Rest\ConfigurableLanguageResourceTestBase;
use Drupal\Tests\rest\Functional\BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* @group hal
*/
class ConfigurableLanguageHalJsonBasicAuthTest extends ConfigurableLanguageResourceTestBase {
use BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal', 'basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\language\Functional\Hal;
use Drupal\Tests\language\Functional\Rest\ConfigurableLanguageResourceTestBase;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class ConfigurableLanguageHalJsonCookieTest extends ConfigurableLanguageResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,30 @@
<?php
namespace Drupal\Tests\language\Functional\Hal;
use Drupal\Tests\language\Functional\Rest\ContentLanguageSettingsResourceTestBase;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group hal
*/
class ContentLanguageSettingsHalJsonAnonTest extends ContentLanguageSettingsResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}

View file

@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\language\Functional\Hal;
use Drupal\Tests\language\Functional\Rest\ContentLanguageSettingsResourceTestBase;
use Drupal\Tests\rest\Functional\BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* @group hal
*/
class ContentLanguageSettingsHalJsonBasicAuthTest extends ContentLanguageSettingsResourceTestBase {
use BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal', 'basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\language\Functional\Hal;
use Drupal\Tests\language\Functional\Rest\ContentLanguageSettingsResourceTestBase;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class ContentLanguageSettingsHalJsonCookieTest extends ContentLanguageSettingsResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,83 @@
<?php
namespace Drupal\Tests\language\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
/**
* Tests breadcrumbs functionality.
*
* @group Menu
*/
class LanguageBreadcrumbTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['language', 'block', 'filter'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
ConfigurableLanguage::createFromLangcode('de')->save();
ConfigurableLanguage::createFromLangcode('gsw-berne')->save();
}
/**
* Tests breadcrumbs with URL prefixes.
*/
public function testBreadCrumbs() {
// Prepare common base breadcrumb elements.
$home = ['' => 'Home'];
$admin = $home + ['admin' => t('Administration')];
$page = $this->getSession()->getPage();
// /user/login is the default frontpage which only works for an anonymous
// user. Access the frontpage in different languages, ensure that no
// breadcrumb is displayed.
$this->drupalGet('user/login');
$breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
$this->assertNull($breadcrumbs);
$this->drupalGet('de/user/login');
$breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
$this->assertNull($breadcrumbs);
$this->drupalGet('gsw-berne/user/login');
$breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
$this->assertNull($breadcrumbs);
$admin_user = $this->drupalCreateUser(['access administration pages']);
$this->drupalLogin($admin_user);
// Use administration routes to assert that breadcrumb is displayed
// correctly on pages other than the frontpage.
$this->drupalGet('admin');
$breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
$this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Home'));
$this->assertEquals(0, substr_count($breadcrumbs->getText(), 'Administration'));
$this->drupalGet('de/admin');
$breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
$this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Home'));
$this->assertEquals(0, substr_count($breadcrumbs->getText(), 'Administration'));
$this->drupalGet('admin/structure', $admin);
$breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
$this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Home'));
$this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Administration'));
$this->drupalGet('de/admin/structure', $admin);
$breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
$this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Home'));
$this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Administration'));
}
}

View file

@ -1,19 +1,19 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the features of the language configuration element field.
*
* @group language
*/
class LanguageConfigurationElementTest extends WebTestBase {
class LanguageConfigurationElementTest extends BrowserTestBase {
/**
* Modules to enable.
@ -170,7 +170,7 @@ class LanguageConfigurationElementTest extends WebTestBase {
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been saved on the Article content type.');
// Update the article content type by changing the title label.
$edit = [
'title_label' => 'Name'
'title_label' => 'Name',
];
$this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
// Check that we still have the settings for the updated node type.
@ -189,7 +189,7 @@ class LanguageConfigurationElementTest extends WebTestBase {
if ($this->profile != 'standard') {
$this->drupalCreateContentType([
'type' => 'article',
'name' => 'Article'
'name' => 'Article',
]);
}
$admin_user = $this->drupalCreateUser(['administer content types']);
@ -240,7 +240,7 @@ class LanguageConfigurationElementTest extends WebTestBase {
$this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been saved on the Country vocabulary.');
// Update the vocabulary.
$edit = [
'name' => 'Nation'
'name' => 'Nation',
];
$this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save'));
// Check that we still have the settings for the updated vocabulary.

View file

@ -1,17 +1,17 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Adds and configures languages to check negotiation changes.
*
* @group language
*/
class LanguageConfigurationTest extends WebTestBase {
class LanguageConfigurationTest extends BrowserTestBase {
/**
* Modules to enable.
@ -169,10 +169,7 @@ class LanguageConfigurationTest extends WebTestBase {
$this->checkConfigurableLanguageWeight('after re-ordering');
// Remove predefined language.
$edit = [
'confirm' => 1,
];
$this->drupalPostForm('admin/config/regional/language/delete/fr', $edit, 'Delete');
$this->drupalPostForm('admin/config/regional/language/delete/fr', [], 'Delete');
$this->checkConfigurableLanguageWeight('after deleting a language');
}
@ -201,7 +198,7 @@ class LanguageConfigurationTest extends WebTestBase {
* @return int
* Maximum weight of configurable languages.
*/
protected function getHighestConfigurableLanguageWeight(){
protected function getHighestConfigurableLanguageWeight() {
$max_weight = 0;
$storage = $this->container->get('entity_type.manager')

View file

@ -1,17 +1,17 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\BrowserTestBase;
/**
* Adds and configures custom languages.
*
* @group language
*/
class LanguageCustomLanguageConfigurationTest extends WebTestBase {
class LanguageCustomLanguageConfigurationTest extends BrowserTestBase {
/**
* Modules to enable.

View file

@ -1,18 +1,18 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\BrowserTestBase;
/**
* Adds a new language and tests changing its status and the default language.
*
* @group language
*/
class LanguageListTest extends WebTestBase {
class LanguageListTest extends BrowserTestBase {
/**
* Modules to enable.
@ -176,9 +176,20 @@ class LanguageListTest extends WebTestBase {
$this->assertResponse(403, 'Can not delete locked language');
// Ensure that NL cannot be set default when it's not available.
// First create the NL language.
$edit = [
'predefined_langcode' => 'nl',
];
$this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
// Load the form which has now the additional NL language option.
$this->drupalGet('admin/config/regional/language');
$extra_values = '&site_default_language=nl';
$this->drupalPostForm(NULL, [], t('Save configuration'), [], [], NULL, $extra_values);
// Delete the NL language in the background.
$language_storage = $this->container->get('entity_type.manager')->getStorage('configurable_language');
$language_storage->load('nl')->delete();
$this->drupalPostForm(NULL, ['site_default_language' => 'nl'], 'Save configuration');
$this->assertText(t('Selected default language no longer exists.'));
$this->assertNoFieldChecked('edit-site-default-language-xx', 'The previous default language got deselected.');
}

View file

@ -1,15 +1,15 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Adds a new language with translations and tests language list order.
*
* @group language
*/
class LanguageLocaleListTest extends WebTestBase {
class LanguageLocaleListTest extends BrowserTestBase {
/**
* Modules to enable.
@ -57,9 +57,11 @@ class LanguageLocaleListTest extends WebTestBase {
// Get language list displayed in select list.
$this->drupalGet('fr/admin/config/regional/language/add');
$select = $this->xpath('//select[@id="edit-predefined-langcode"]');
$select_element = (array) end($select);
$options = $select_element['option'];
$option_elements = $this->xpath('//select[@id="edit-predefined-langcode/option"]');
$options = [];
foreach ($option_elements as $option_element) {
$options[] = $option_element->getText();
}
// Remove the 'Custom language...' option form the end.
array_pop($options);
// Order language list.

View file

@ -90,7 +90,7 @@ class LanguageNegotiationContentEntityTest extends BrowserTestBase {
$config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
$config->set('negotiation.language_content.enabled', [
LanguageNegotiationUrl::METHOD_ID => 0,
LanguageNegotiationContentEntity::METHOD_ID => 1
LanguageNegotiationContentEntity::METHOD_ID => 1,
]);
$config->save();
@ -105,7 +105,7 @@ class LanguageNegotiationContentEntityTest extends BrowserTestBase {
// language-url.
$config->set('negotiation.language_content.enabled', [
LanguageNegotiationContentEntity::METHOD_ID => 0,
LanguageNegotiationUrl::METHOD_ID => 1
LanguageNegotiationUrl::METHOD_ID => 1,
]);
$config->save();

View file

@ -160,11 +160,7 @@ class LanguageNegotiationInfoTest extends BrowserTestBase {
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;
}
$equal = array_keys($negotiation) === array_values($info['fixed']);
$this->assertTrue($equal, format_string('language negotiation for %type is properly set up', ['%type' => $type]));
}
}

View file

@ -70,7 +70,7 @@ class LanguageNegotiationUrlTest extends BrowserTestBase {
'title[0][value]' => 'Test',
'path[0][alias]' => '/eng/test',
];
$this->drupalPostForm('node/add/article', $nodeValues, $this->t('Save and publish'));
$this->drupalPostForm('node/add/article', $nodeValues, $this->t('Save'));
$this->assertSession()->statusCodeEquals(200);
}

View file

@ -1,15 +1,15 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the content translation settings language selector options.
*
* @group language
*/
class LanguageSelectorTranslatableTest extends WebTestBase {
class LanguageSelectorTranslatableTest extends BrowserTestBase {
/**
* Modules to enable.
@ -29,7 +29,7 @@ class LanguageSelectorTranslatableTest extends WebTestBase {
/**
* The user with administrator privileges.
*
* @var \Drupal\user\Entity\User;
* @var \Drupal\user\Entity\User
*/
public $administrator;
@ -82,7 +82,7 @@ class LanguageSelectorTranslatableTest extends WebTestBase {
$elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => 'edit-settings-user-user-settings-language-langcode', ':option' => 'en']);
// Check that the language text is translated.
$this->assertEqual((string) $elements[0], $name_translation, 'Checking the option string English is translated to Spanish.');
$this->assertEqual($elements[0]->getText(), $name_translation, 'Checking the option string English is translated to Spanish.');
}
}

View file

@ -1,19 +1,19 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\Core\Language\LanguageInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Functional tests for the language switching feature.
*
* @group language
*/
class LanguageSwitchingTest extends WebTestBase {
class LanguageSwitchingTest extends BrowserTestBase {
/**
* Modules to enable.
@ -73,22 +73,24 @@ class LanguageSwitchingTest extends WebTestBase {
// Assert that each list item and anchor element has the appropriate data-
// attributes.
list($language_switcher) = $this->xpath('//div[@id=:id]', [':id' => 'block-test-language-block']);
$language_switchers = $this->xpath('//div[@id=:id]/ul/li', [':id' => 'block-test-language-block']);
$list_items = [];
$anchors = [];
$labels = [];
foreach ($language_switcher->ul->li as $list_item) {
$classes = explode(" ", (string) $list_item['class']);
foreach ($language_switchers as $list_item) {
$classes = explode(" ", $list_item->getAttribute('class'));
list($langcode) = array_intersect($classes, ['en', 'fr']);
$list_items[] = [
'langcode_class' => $langcode,
'data-drupal-link-system-path' => (string) $list_item['data-drupal-link-system-path'],
'data-drupal-link-system-path' => $list_item->getAttribute('data-drupal-link-system-path'),
];
$link = $list_item->find('xpath', 'a');
$anchors[] = [
'hreflang' => (string) $list_item->a['hreflang'],
'data-drupal-link-system-path' => (string) $list_item->a['data-drupal-link-system-path'],
'hreflang' => $link->getAttribute('hreflang'),
'data-drupal-link-system-path' => $link->getAttribute('data-drupal-link-system-path'),
];
$labels[] = (string) $list_item->a;
$labels[] = $link->getText();
}
$expected_list_items = [
0 => ['langcode_class' => 'en', 'data-drupal-link-system-path' => 'user/2'],
@ -124,7 +126,7 @@ class LanguageSwitchingTest extends WebTestBase {
$this->assertText($block_label, 'Language switcher block found.');
// Assert that only the current language is marked as active.
list($language_switcher) = $this->xpath('//div[@id=:id]', [':id' => 'block-test-language-block']);
$language_switchers = $this->xpath('//div[@id=:id]/ul/li', [':id' => 'block-test-language-block']);
$links = [
'active' => [],
'inactive' => [],
@ -134,8 +136,8 @@ class LanguageSwitchingTest extends WebTestBase {
'inactive' => [],
];
$labels = [];
foreach ($language_switcher->ul->li as $link) {
$classes = explode(" ", (string) $link['class']);
foreach ($language_switchers as $list_item) {
$classes = explode(" ", $list_item->getAttribute('class'));
list($langcode) = array_intersect($classes, ['en', 'fr']);
if (in_array('is-active', $classes)) {
$links['active'][] = $langcode;
@ -143,14 +145,16 @@ class LanguageSwitchingTest extends WebTestBase {
else {
$links['inactive'][] = $langcode;
}
$anchor_classes = explode(" ", (string) $link->a['class']);
$link = $list_item->find('xpath', 'a');
$anchor_classes = explode(" ", $link->getAttribute('class'));
if (in_array('is-active', $anchor_classes)) {
$anchors['active'][] = $langcode;
}
else {
$anchors['inactive'][] = $langcode;
}
$labels[] = (string) $link->a;
$labels[] = $link->getText();
}
$this->assertIdentical($links, ['active' => ['en'], 'inactive' => ['fr']], 'Only the current language list item is marked as active on the language switcher block.');
$this->assertIdentical($anchors, ['active' => ['en'], 'inactive' => ['fr']], 'Only the current language anchor is marked as active on the language switcher block.');
@ -208,7 +212,7 @@ class LanguageSwitchingTest extends WebTestBase {
':hreflang' => 'en',
]);
$english_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2], ['language' => $languages['en']]);
$this->assertEqual($english_url, (string) $english_link['href']);
$this->assertEqual($english_url, $english_link->getAttribute('href'));
// Verify the Italian URL is correct
list($italian_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', [
@ -216,7 +220,7 @@ class LanguageSwitchingTest extends WebTestBase {
':hreflang' => 'it',
]);
$italian_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2], ['language' => $languages['it']]);
$this->assertEqual($italian_url, (string) $italian_link['href']);
$this->assertEqual($italian_url, $italian_link->getAttribute('href'));
}
/**

View file

@ -1,8 +1,8 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\tour\Tests\TourTestBase;
use Drupal\Tests\tour\Functional\TourTestBase;
/**
* Tests tour functionality.

View file

@ -1,16 +1,18 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Url;
use Drupal\file\Entity\File;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser;
use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Symfony\Component\HttpFoundation\Request;
@ -37,7 +39,14 @@ use Drupal\block\Entity\Block;
*
* @group language
*/
class LanguageUILanguageNegotiationTest extends WebTestBase {
class LanguageUILanguageNegotiationTest extends BrowserTestBase {
/**
* The admin user for testing.
*
* @var \Drupal\user\Entity\User
*/
protected $adminUser;
/**
* Modules to enable.
@ -53,8 +62,8 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages', 'administer blocks']);
$this->drupalLogin($admin_user);
$this->adminUser = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages', 'administer blocks']);
$this->drupalLogin($this->adminUser);
}
/**
@ -69,9 +78,20 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
// For testing path prefix.
$langcode = 'zh-hans';
// For setting browser language preference to 'vi'.
$http_header_browser_fallback = ["Accept-Language: $langcode_browser_fallback;q=1"];
$http_header_browser_fallback = ["Accept-Language" => "$langcode_browser_fallback;q=1"];
// For setting browser language preference to some unknown.
$http_header_blah = ["Accept-Language: blah;q=1"];
$http_header_blah = ["Accept-Language" => "blah;q=1"];
// Create a private file for testing accessible by the admin user.
drupal_mkdir($this->privateFilesDirectory . '/test');
$filepath = 'private://test/private-file-test.txt';
$contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data.";
file_put_contents($filepath, $contents);
$file = File::create([
'uri' => $filepath,
'uid' => $this->adminUser->id(),
]);
$file->save();
// Setup the site languages by installing two languages.
// Set the default language in order for the translated string to be registered
@ -107,7 +127,7 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
];
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$textarea = current($this->xpath('//textarea'));
$lid = (string) $textarea[0]['name'];
$lid = $textarea->getAttribute('name');
$edit = [
$lid => $language_browser_fallback_string,
];
@ -119,7 +139,7 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
];
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$textarea = current($this->xpath('//textarea'));
$lid = (string) $textarea[0]['name'];
$lid = $textarea->getAttribute('name');
$edit = [
$lid => $language_string,
];
@ -242,6 +262,21 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
];
$this->doRunTest($test);
// Set preferred langcode for user to default langcode.
$account = $this->loggedInUser;
$account->preferred_langcode = $default_language->getId();
$account->save();
$test = [
'language_negotiation' => [LanguageNegotiationUser::METHOD_ID, LanguageNegotiationUrl::METHOD_ID],
'path' => "$langcode/admin/config",
'expect' => $default_string,
'expected_method_id' => LanguageNegotiationUser::METHOD_ID,
'http_header' => [],
'message' => 'USER > URL: User has default language as preferred user language setting, the UI language is default',
];
$this->doRunTest($test);
// Set preferred langcode for user to unknown language.
$account = $this->loggedInUser;
$account->preferred_langcode = $langcode_unknown;
@ -359,6 +394,13 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
$this->drupalGet($test['path'], $test['path_options'], $test['http_header']);
$this->assertText($test['expect'], $test['message']);
$this->assertText(t('Language negotiation method: @name', ['@name' => $test['expected_method_id']]));
// Get the private file and ensure it is a 200. It is important to
// invalidate the router cache to ensure the routing system runs a full
// match.
Cache::invalidateTags(['route_match']);
$this->drupalGet('system/files/test/private-file-test.txt');
$this->assertResponse(200);
}
/**
@ -398,7 +440,7 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
// Access the front page without specifying any valid URL language prefix
// and having as browser language preference a non-default language.
$http_header = ["Accept-Language: $langcode_browser_fallback;q=1"];
$http_header = ["Accept-Language" => "$langcode_browser_fallback;q=1"];
$language = new Language(['id' => '']);
$this->drupalGet('', ['language' => $language], $http_header);
@ -406,11 +448,11 @@ class LanguageUILanguageNegotiationTest extends WebTestBase {
// language.
$args = [':id' => 'block-test-language-block', ':url' => \Drupal::url('<front>') . $langcode_browser_fallback];
$fields = $this->xpath('//div[@id=:id]//a[@class="language-link is-active" and starts-with(@href, :url)]', $args);
$this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language');
$this->assertSame($fields[0]->getText(), $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language');
// Check that URLs are rewritten using the given browser language.
$fields = $this->xpath('//div[@class="site-name"]/a[@rel="home" and @href=:url]', $args);
$this->assertTrue($fields[0] == 'Drupal', 'URLs are rewritten using the browser language.');
$this->assertSame($fields[0]->getText(), 'Drupal', 'URLs are rewritten using the browser language.');
}
/**

View file

@ -1,12 +1,12 @@
<?php
namespace Drupal\language\Tests;
namespace Drupal\Tests\language\Functional;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\HttpFoundation\Request;
/**
@ -14,7 +14,7 @@ use Symfony\Component\HttpFoundation\Request;
*
* @group language
*/
class LanguageUrlRewritingTest extends WebTestBase {
class LanguageUrlRewritingTest extends BrowserTestBase {
/**
* Modules to enable.
@ -90,9 +90,8 @@ class LanguageUrlRewritingTest extends WebTestBase {
// we can always check the prefixed URL.
$prefixes = language_negotiation_url_prefixes();
$stored_prefix = isset($prefixes[$language->getId()]) ? $prefixes[$language->getId()] : $this->randomMachineName();
if ($this->assertNotEqual($stored_prefix, $prefix, $message1)) {
$prefix = $stored_prefix;
}
$this->assertNotEqual($stored_prefix, $prefix, $message1);
$prefix = $stored_prefix;
$this->drupalGet("$prefix/$path");
$this->assertResponse(404, $message2);
@ -109,7 +108,7 @@ class LanguageUrlRewritingTest extends WebTestBase {
$edit = [
'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
'domain[en]' => $base_url_host,
'domain[fr]' => $language_domain
'domain[fr]' => $language_domain,
];
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
// Rebuild the container so that the new language gets picked up by services

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class ConfigurableLanguageJsonAnonTest extends ConfigurableLanguageResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* @group rest
*/
class ConfigurableLanguageJsonBasicAuthTest extends ConfigurableLanguageResourceTestBase {
use BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class ConfigurableLanguageJsonCookieTest extends ConfigurableLanguageResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,95 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Url;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
abstract class ConfigurableLanguageResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['language'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'configurable_language';
/**
* @var \Drupal\language\ConfigurableLanguageInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer languages']);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$configurable_language = ConfigurableLanguage::create([
'id' => 'll',
'label' => 'Llama Language',
]);
$configurable_language->save();
return $configurable_language;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'dependencies' => [],
'direction' => 'ltr',
'id' => 'll',
'label' => 'Llama Language',
'langcode' => 'en',
'locked' => FALSE,
'status' => TRUE,
'uuid' => $this->entity->uuid(),
'weight' => 0,
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['languages:language_interface']);
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update in https://www.drupal.org/node/2300677.
}
/**
* Test a GET request for a default config entity, which has a _core key.
*
* @see https://www.drupal.org/node/2915414
*/
public function testGetDefaultConfig() {
$this->initAuthentication();
$url = Url::fromUri('base:/entity/configurable_language/en')->setOption('query', ['_format' => static::$format]);;
$request_options = $this->getAuthenticationRequestOptions('GET');
$this->provisionEntityResource();
$this->setUpAuthorization('GET');
$response = $this->request('GET', $url, $request_options);
$normalization = $this->serializer->decode((string) $response->getBody(), static::$format);
$this->assertArrayNotHasKey('_core', $normalization);
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ConfigurableLanguageXmlAnonTest extends ConfigurableLanguageResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceWithInterfaceTranslationTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ConfigurableLanguageXmlBasicAuthTest extends ConfigurableLanguageResourceTestBase {
use BasicAuthResourceWithInterfaceTranslationTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ConfigurableLanguageXmlCookieTest extends ConfigurableLanguageResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class ContentLanguageSettingsJsonAnonTest extends ContentLanguageSettingsResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* @group rest
*/
class ContentLanguageSettingsJsonBasicAuthTest extends ContentLanguageSettingsResourceTestBase {
use BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class ContentLanguageSettingsJsonCookieTest extends ContentLanguageSettingsResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,92 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class ContentLanguageSettingsResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['language', 'node'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'language_content_settings';
/**
* @var \Drupal\language\ContentLanguageSettingsInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer languages']);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create a "Camelids" node type.
$camelids = NodeType::create([
'name' => 'Camelids',
'type' => 'camelids',
]);
$camelids->save();
$entity = ContentLanguageSettings::create([
'target_entity_type_id' => 'node',
'target_bundle' => 'camelids',
]);
$entity->setDefaultLangcode('site_default')
->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'default_langcode' => 'site_default',
'dependencies' => [
'config' => [
'node.type.camelids',
],
],
'id' => 'node.camelids',
'langcode' => 'en',
'language_alterable' => FALSE,
'status' => TRUE,
'target_bundle' => 'camelids',
'target_entity_type_id' => 'node',
'uuid' => $this->entity->uuid(),
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update in https://www.drupal.org/node/2300677.
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return [
'languages:language_interface',
'user.permissions',
];
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ContentLanguageSettingsXmlAnonTest extends ContentLanguageSettingsResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceWithInterfaceTranslationTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ContentLanguageSettingsXmlBasicAuthTest extends ContentLanguageSettingsResourceTestBase {
use BasicAuthResourceWithInterfaceTranslationTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\language\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ContentLanguageSettingsXmlCookieTest extends ContentLanguageSettingsResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,41 @@
<?php
namespace Drupal\Tests\language\Functional\Update;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the update path for the language_select widget.
*
* @group Update
* @group legacy
*/
class LanguageSelectWidgetUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz',
];
}
/**
* Tests language_post_update_language_select_widget().
*/
public function testLanguagePostUpdateLanguageSelectWidget() {
// Tests before the update.
$content_before = EntityFormDisplay::load('node.page.default')->get('content');
$this->assertEqual([], $content_before['langcode']['settings']);
// Run the update.
$this->runUpdates();
// Tests after the update.
$content_after = EntityFormDisplay::load('node.page.default')->get('content');
$this->assertEqual(['include_locked' => TRUE], $content_after['langcode']['settings']);
}
}

View file

@ -74,7 +74,7 @@ class EntityUrlLanguageTest extends LanguageTestBase {
$config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
$config->set('negotiation.language_content.enabled', [
LanguageNegotiationContentEntity::METHOD_ID => 0,
LanguageNegotiationUrl::METHOD_ID => 1
LanguageNegotiationUrl::METHOD_ID => 1,
]);
$config->save();
@ -98,7 +98,7 @@ class EntityUrlLanguageTest extends LanguageTestBase {
// where the language-content-entity is turned off.
$config->set('negotiation.language_content.enabled', [
LanguageNegotiationUrl::METHOD_ID => 0,
LanguageNegotiationContentEntity::METHOD_ID => 1
LanguageNegotiationContentEntity::METHOD_ID => 1,
]);
$config->save();

View file

@ -0,0 +1,77 @@
<?php
namespace Drupal\Tests\language\Kernel;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the language select widget.
*
* @group language
*/
class LanguageSelectWidgetTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'entity_test',
'language',
'user',
'system',
];
/**
* The entity form display.
*
* @var \Drupal\Core\Entity\Entity\EntityFormDisplay
*/
protected $entityFormDisplay;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$storage = $this->container->get('entity_type.manager')->getStorage('entity_form_display');
$this->entityFormDisplay = $storage->create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
]);
}
/**
* Tests the widget with the locked languages.
*/
public function testWithIncludedLockedLanguage() {
$this->entityFormDisplay->setComponent('langcode', [
'type' => 'language_select',
])->save();
$entity = EntityTest::create(['name' => $this->randomString()]);
$form = $this->container->get('entity.form_builder')->getForm($entity);
$options = array_keys($form['langcode']['widget'][0]['value']['#options']);
$this->assertSame(['en', 'und', 'zxx'], $options);
}
/**
* Test the widget without the locked languages.
*/
public function testWithoutIncludedLockedLanguage() {
$this->entityFormDisplay->setComponent('langcode', [
'type' => 'language_select',
'settings' => ['include_locked' => FALSE],
])->save();
$entity = EntityTest::create(['name' => $this->randomString()]);
$form = $this->container->get('entity.form_builder')->getForm($entity);
$options = array_keys($form['langcode']['widget'][0]['value']['#options']);
$this->assertSame(['en'], $options);
}
}

View file

@ -45,10 +45,10 @@ class MigrateDefaultLanguageTest extends MigrateDrupal6TestBase {
$count = 0;
foreach ($messages as $message) {
$count++;
$this->assertSame($message->message, "The language 'tv' does not exist on this site.");
$this->assertSame((int) $message->level, MigrationInterface::MESSAGE_ERROR);
$this->assertSame("The language 'tv' does not exist on this site.", $message->message);
$this->assertSame(MigrationInterface::MESSAGE_ERROR, (int) $message->level);
}
$this->assertSame($count, 1);
$this->assertSame(1, $count);
}
/**

View file

@ -0,0 +1,68 @@
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d6;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration of the ability to translate menu content.
*
* @group migrate_drupal_6
*/
class MigrateLanguageContentMenuSettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'language',
'content_translation',
'menu_link_content',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create some languages.
ConfigurableLanguage::createFromLangcode('en')->save();
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->executeMigrations(['d6_language_content_menu_settings']);
}
/**
* Tests migration of menu translation ability.
*/
public function testLanguageMenuContent() {
$config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
$this->assertInstanceOf(ContentLanguageSettings::class, $config);
$this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
$this->assertSame('menu_link_content', $config->getTargetBundle());
$this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
// Test that menus are not alterable when the i18nmenu is not enabled.
$this->sourceDatabase->update('system')
->fields(['status' => 0])
->condition('name', 'i18nmenu')
->execute();
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = $this->getMigration('d6_language_content_menu_settings');
// Indicate we're rerunning a migration that's already run.
$migration->getIdMap()->prepareUpdate();
$this->executeMigration($migration);
$config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
$this->assertInstanceOf(ContentLanguageSettings::class, $config);
$this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
$this->assertSame('menu_link_content', $config->getTargetBundle());
$this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
$this->assertFalse($config->isLanguageAlterable());
}
}

View file

@ -25,6 +25,7 @@ class MigrateLanguageContentSettingsTest extends MigrateDrupal6TestBase {
parent::setUp();
$this->installConfig(['node']);
$this->installEntitySchema('node');
$this->executeMigrations(['d6_node_type', 'd6_language_content_settings']);
}

View file

@ -0,0 +1,80 @@
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d6;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration of i18ntaxonomy vocabulary settings.
*
* @group migrate_drupal_6
*/
class MigrateLanguageContentTaxonomyVocabularySettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'language',
'content_translation',
'taxonomy',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('taxonomy_term');
$this->executeMigrations([
'language',
'd6_taxonomy_vocabulary',
'd6_language_content_taxonomy_vocabulary_settings',
]);
}
/**
* Tests migration of 18ntaxonomy vocabulary settings.
*/
public function testLanguageContentTaxonomy() {
$target_entity = 'taxonomy_term';
// Per Language.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_1_i_0_', LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE, ['enabled' => FALSE]);
// Set language to vocabulary.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_2_i_1_', 'fr', FALSE, ['enabled' => FALSE]);
// Localize terms.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_3_i_2_', LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE, ['enabled' => TRUE]);
// None translation enabled.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_name_much_longer_than', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'tags', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'forums', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'type', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
}
/**
* Asserts a content language settings configuration.
*
* @param string $target_entity
* The expected target entity type.
* @param string $bundle
* The expected bundle.
* @param string $default_langcode
* The default language code.
* @param bool $language_alterable
* The expected state of language alterable.
* @param array $third_party_settings
* The content translation setting.
*/
public function assertLanguageContentSettings($target_entity, $bundle, $default_langcode, $language_alterable, array $third_party_settings) {
$config = ContentLanguageSettings::load($target_entity . "." . $bundle);
$this->assertInstanceOf(ContentLanguageSettings::class, $config);
$this->assertSame($target_entity, $config->getTargetEntityTypeId());
$this->assertSame($bundle, $config->getTargetBundle());
$this->assertSame($default_langcode, $config->getDefaultLangcode());
$this->assertSame($language_alterable, $config->isLanguageAlterable());
$this->assertSame($third_party_settings, $config->getThirdPartySettings('content_translation'));
}
}

View file

@ -29,26 +29,26 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
]);
$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');
$this->assertSame('language', $config->get('session.parameter'));
$this->assertSame(LanguageNegotiationUrl::CONFIG_PATH_PREFIX, $config->get('url.source'));
$this->assertSame('site_default', $config->get('selected_langcode'));
$expected_prefixes = [
'en' => '',
'fr' => 'fr',
'zu' => 'zu',
];
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
$this->assertSame($expected_prefixes, $config->get('url.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]);
$this->assertSame(['language_interface', 'language_content', 'language_url'], $config->get('all'));
$this->assertSame(['language_interface'], $config->get('configurable'));
$this->assertSame(['language-interface' => 0], $config->get('negotiation.language_content.enabled'));
$this->assertSame(['language-url' => 0, 'language-url-fallback' => 1], $config->get('negotiation.language_url.enabled'));
$expected_language_interface = [
'language-url' => 0,
'language-selected' => 1,
];
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
$this->assertSame($expected_language_interface, $config->get('negotiation.language_interface.enabled'));
}
/**
@ -68,19 +68,19 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
]);
$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');
$this->assertSame('language', $config->get('session.parameter'));
$this->assertSame(LanguageNegotiationUrl::CONFIG_PATH_PREFIX, $config->get('url.source'));
$this->assertSame('site_default', $config->get('selected_langcode'));
$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]);
$this->assertSame(['language_interface', 'language_content', 'language_url'], $config->get('all'));
$this->assertSame(['language_interface'], $config->get('configurable'));
$this->assertSame(['language-interface' => 0], $config->get('negotiation.language_content.enabled'));
$this->assertSame(['language-url' => 0, 'language-url-fallback' => 1], $config->get('negotiation.language_url.enabled'));
$expected_language_interface = [
'language-selected' => 0,
];
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
$this->assertSame($expected_language_interface, $config->get('negotiation.language_interface.enabled'));
}
/**
@ -100,28 +100,28 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
]);
$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');
$this->assertSame('language', $config->get('session.parameter'));
$this->assertSame(LanguageNegotiationUrl::CONFIG_PATH_PREFIX, $config->get('url.source'));
$this->assertSame('site_default', $config->get('selected_langcode'));
$expected_prefixes = [
'en' => '',
'fr' => 'fr',
'zu' => 'zu',
];
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
$this->assertSame($expected_prefixes, $config->get('url.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]);
$this->assertSame(['language_interface', 'language_content', 'language_url'], $config->get('all'));
$this->assertSame(['language_interface'], $config->get('configurable'));
$this->assertSame(['language-interface' => 0], $config->get('negotiation.language_content.enabled'));
$this->assertSame(['language-url' => 0, 'language-url-fallback' => 1], $config->get('negotiation.language_url.enabled'));
$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);
$this->assertSame($expected_language_interface, $config->get('negotiation.language_interface.enabled'));
}
/**
@ -142,26 +142,26 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
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');
$this->assertSame('language', $config->get('session.parameter'));
$this->assertSame(LanguageNegotiationUrl::CONFIG_DOMAIN, $config->get('url.source'));
$this->assertSame('site_default', $config->get('selected_langcode'));
$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);
$this->assertSame($expected_domains, $config->get('url.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]);
$this->assertSame(['language_interface', 'language_content', 'language_url'], $config->get('all'));
$this->assertSame(['language_interface'], $config->get('configurable'));
$this->assertSame(['language-interface' => 0], $config->get('negotiation.language_content.enabled'));
$this->assertSame(['language-url' => 0, 'language-url-fallback' => 1], $config->get('negotiation.language_url.enabled'));
$expected_language_interface = [
'language-url' => 0,
'language-selected' => 1,
];
$this->assertSame($config->get('negotiation.language_interface.enabled'), $expected_language_interface);
$this->assertSame($expected_language_interface, $config->get('negotiation.language_interface.enabled'));
}
}

View file

@ -45,10 +45,10 @@ class MigrateDefaultLanguageTest extends MigrateDrupal7TestBase {
$count = 0;
foreach ($messages as $message) {
$count++;
$this->assertSame($message->message, "The language 'tv' does not exist on this site.");
$this->assertSame((int) $message->level, MigrationInterface::MESSAGE_ERROR);
$this->assertSame("The language 'tv' does not exist on this site.", $message->message);
$this->assertSame(MigrationInterface::MESSAGE_ERROR, (int) $message->level);
}
$this->assertSame($count, 1);
$this->assertSame(1, $count);
}
/**

View file

@ -17,6 +17,7 @@ class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
* {@inheritdoc}
*/
public static $modules = ['node', 'text', 'language', 'content_translation', 'menu_ui'];
/**
* {@inheritdoc}
*/
@ -24,6 +25,7 @@ class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
parent::setUp();
$this->installConfig(['node']);
$this->installEntitySchema('node');
$this->executeMigrations(['d7_node_type', 'd7_language_content_settings']);
}
@ -33,9 +35,9 @@ class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
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->assertSame($config->get('target_entity_type_id'), 'node');
$this->assertSame($config->get('target_bundle'), 'blog');
$this->assertSame($config->get('default_langcode'), 'current_interface');
$this->assertFalse($config->get('language_alterable'));
$this->assertTrue($config->get('third_party_settings.content_translation.enabled'));
@ -45,6 +47,23 @@ class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
$this->assertFalse($config->isLanguageAlterable());
$this->assertSame($config->getDefaultLangcode(), 'site_default');
// Make sure there's no migration exceptions.
$messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll();
$this->assertEmpty($messages);
// Assert that a content type translatable with entity_translation is still
// translatable.
$config = $this->config('language.content_settings.node.test_content_type');
$this->assertTrue($config->get('third_party_settings.content_translation.enabled'));
$this->assertSame($config->get('default_langcode'), 'und');
// Assert that a content type without a 'language_content_type' variable is
// not translatable
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'book');
$this->assertTrue($config->isDefaultConfiguration());
$this->assertFalse($config->isLanguageAlterable());
$this->assertSame($config->getDefaultLangcode(), 'site_default');
}
}

View file

@ -28,10 +28,10 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
]);
$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]]);
$this->assertSame(['language_content', 'language_url', 'language_interface'], $config->get('all'));
$this->assertSame(['language_interface'], $config->get('configurable'));
$this->assertSame(['enabled' => ['language-interface' => 0]], $config->get('negotiation.language_content'));
$this->assertSame(['enabled' => ['language-url' => 0, 'language-url-fallback' => 1]], $config->get('negotiation.language_url'));
$expected_language_interface = [
'enabled' => [
'language-url' => -9,
@ -46,13 +46,17 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
'language-selected' => -6,
],
];
$this->assertSame($config->get('negotiation.language_interface'), $expected_language_interface);
$this->assertSame($expected_language_interface, $config->get('negotiation.language_interface'));
}
/**
* Tests the migration with prefix negotiation.
*/
public function testLanguageNegotiationWithPrefix() {
$this->sourceDatabase->update('languages')
->fields(['domain' => ''])
->execute();
$this->executeMigrations([
'language',
'd7_language_negotiation_settings',
@ -60,14 +64,25 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
]);
$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');
$this->assertSame('language', $config->get('session.parameter'));
$this->assertSame(LanguageNegotiationUrl::CONFIG_PATH_PREFIX, $config->get('url.source'));
$this->assertSame('site_default', $config->get('selected_langcode'));
$expected_prefixes = [
'en' => '',
'fr' => 'fr',
'is' => 'is',
];
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
$this->assertSame($expected_prefixes, $config->get('url.prefixes'));
// If prefix negotiation is used, make sure that no domains are migrated.
// Otherwise there will be validation errors when trying to save URL
// language detection configuration from the UI.
$expected_domains = [
'en' => '',
'fr' => '',
'is' => '',
];
$this->assertSame($expected_domains, $config->get('url.domains'));
}
/**
@ -87,14 +102,15 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
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');
$this->assertSame('language', $config->get('session.parameter'));
$this->assertSame(LanguageNegotiationUrl::CONFIG_DOMAIN, $config->get('url.source'));
$this->assertSame('site_default', $config->get('selected_langcode'));
$expected_domains = [
'en' => parse_url($base_url, PHP_URL_HOST),
'fr' => 'fr.drupal.org',
'is' => 'is.drupal.org',
];
$this->assertSame($config->get('url.domains'), $expected_domains);
$this->assertSame($expected_domains, $config->get('url.domains'));
}
/**
@ -112,14 +128,15 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
]);
$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');
$this->assertSame('language', $config->get('session.parameter'));
$this->assertSame(LanguageNegotiationUrl::CONFIG_PATH_PREFIX, $config->get('url.source'));
$this->assertSame('site_default', $config->get('selected_langcode'));
$expected_prefixes = [
'en' => '',
'fr' => 'fr',
'is' => 'is',
];
$this->assertSame($config->get('url.prefixes'), $expected_prefixes);
$this->assertSame($expected_prefixes, $config->get('url.prefixes'));
}
}

View file

@ -0,0 +1,74 @@
<?php
namespace Drupal\Tests\language\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests menu source plugin.
*
* @covers \Drupal\language\Plugin\migrate\source\d6\LanguageContentSettings
*
* @group language
*/
class LanguageContentSettingsTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['language', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['node_type'] = [
[
'type' => 'article',
'name' => 'Article',
'module' => 'node',
'description' => 'An <em>article</em>, content type.',
'help' => '',
'has_title' => 1,
'title_label' => 'Title',
'has_body' => 1,
'body_label' => 'Body',
'min_word_count' => 0,
'custom' => 1,
'modified' => 1,
'locked' => 0,
'orig_type' => 'story',
],
[
'type' => 'company',
'name' => 'Company',
'module' => 'node',
'description' => 'Company node type',
'help' => '',
'has_title' => 1,
'title_label' => 'Name',
'has_body' => 1,
'body_label' => 'Description',
'min_word_count' => 0,
'custom' => 0,
'modified' => 1,
'locked' => 0,
'orig_type' => 'company',
],
];
foreach ($tests[0]['source_data']['node_type'] as $node_type) {
$tests[0]['expected_data'][] = [
'type' => $node_type['type'],
'language_content_type' => NULL,
'i18n_lock_node' => 0,
];
}
return $tests;
}
}

View file

@ -0,0 +1,81 @@
<?php
namespace Drupal\Tests\language\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests i18ntaxonomy vocabulary setting source plugin.
*
* @covers \Drupal\language\Plugin\migrate\source\d6\LanguageContentSettingsTaxonomyVocabulary
*
* @group language
*/
class LanguageContentTaxonomyVocabularySettingsTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'language', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['vocabulary'] = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'help' => 1,
'relations' => 0,
'hierarchy' => 0,
'multiple' => 0,
'required' => 0,
'tags' => 1,
'module' => 'taxonomy',
'weight' => 0,
'language' => '',
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 0,
'language' => 'zu',
],
];
$tests[0]['source_data']['variable'] = [
[
'name' => 'i18ntaxonomy_vocabulary',
'value' => 'a:4:{i:1;s:1:"3";i:2;s:1:"2";i:3;s:1:"3";i:5;s:1:"1";}',
],
];
$tests[0]['expected_data'] = [
[
'vid' => 1,
'language' => '',
'state' => 3,
],
[
'vid' => 2,
'language' => 'zu',
'state' => 2,
],
];
return $tests;
}
}

Some files were not shown because too many files have changed in this diff Show more