Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -24,19 +24,19 @@ class LanguageConfigurationElement extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle');
|
||||
|
||||
$form['lang_configuration'] = array(
|
||||
$form['lang_configuration'] = [
|
||||
'#type' => 'language_configuration',
|
||||
'#entity_information' => array(
|
||||
'#entity_information' => [
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'some_bundle',
|
||||
),
|
||||
],
|
||||
'#default_value' => $conf,
|
||||
);
|
||||
];
|
||||
|
||||
$form['submit'] = array(
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Save',
|
||||
);
|
||||
];
|
||||
$form['#submit'][] = 'language_configuration_element_submit';
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ class LanguageConfigurationElementTest extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#title' => t('Language select'),
|
||||
'#type' => 'language_select',
|
||||
'#default_value' => language_get_default_langcode('entity_test', 'some_bundle'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
|
||||
|
||||
/**
|
||||
|
@ -14,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', array('@name' => \Drupal::languageManager()->getNegotiatedLanguageMethod())));
|
||||
drupal_set_message(t('Language negotiation method: @name', ['@name' => \Drupal::languageManager()->getNegotiatedLanguageMethod()]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,16 +24,16 @@ function language_test_page_top() {
|
|||
*/
|
||||
function language_test_language_types_info() {
|
||||
if (\Drupal::state()->get('language_test.language_types')) {
|
||||
return array(
|
||||
'test_language_type' => array(
|
||||
return [
|
||||
'test_language_type' => [
|
||||
'name' => t('Test'),
|
||||
'description' => t('A test language type.'),
|
||||
),
|
||||
'fixed_test_language_type' => array(
|
||||
'fixed' => array('test_language_negotiation_method'),
|
||||
],
|
||||
'fixed_test_language_type' => [
|
||||
'fixed' => ['test_language_negotiation_method'],
|
||||
'locked' => TRUE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,7 @@ function language_test_language_negotiation_info_alter(array &$negotiation_info)
|
|||
* Store the last negotiated languages.
|
||||
*/
|
||||
function language_test_store_language_negotiation() {
|
||||
$last = array();
|
||||
$last = [];
|
||||
foreach (\Drupal::languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$last[$type] = \Drupal::languageManager()->getCurrentLanguage($type)->getId();
|
||||
}
|
||||
|
@ -99,3 +100,10 @@ function language_test_language_fallback_candidates_test_alter(array &$candidate
|
|||
function language_test_module_preinstall() {
|
||||
\Drupal::state()->set('language_test.language_count_preinstall', count(\Drupal::languageManager()->getLanguages()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_switch_links_alter().
|
||||
*/
|
||||
function language_test_language_switch_links_alter(array &$links, $type, Url $url) {
|
||||
// I'll just sit here and wait to be called with the right arguments.
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class LanguageTestController implements ContainerInjectionInterface {
|
|||
* Testing feedback based on (translated) entity title.
|
||||
*/
|
||||
public function testEntity(ConfigurableLanguageInterface $configurable_language) {
|
||||
return array('#markup' => $this->t('Loaded %label.', array('%label' => $configurable_language->label())));
|
||||
return ['#markup' => $this->t('Loaded %label.', ['%label' => $configurable_language->label()])];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,43 +72,43 @@ class LanguageTestController implements ContainerInjectionInterface {
|
|||
public function typeLinkActiveClass() {
|
||||
// We assume that 'en' and 'fr' have been configured.
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
return array(
|
||||
'no_language' => array(
|
||||
return [
|
||||
'no_language' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to the current path with no langcode provided.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'attributes' => array(
|
||||
'#options' => [
|
||||
'attributes' => [
|
||||
'id' => 'no_lang_link',
|
||||
),
|
||||
],
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
'fr' => array(
|
||||
],
|
||||
],
|
||||
'fr' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to a French version of the current path.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'language' => $languages['fr'],
|
||||
'attributes' => array(
|
||||
'attributes' => [
|
||||
'id' => 'fr_link',
|
||||
),
|
||||
],
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
'en' => array(
|
||||
],
|
||||
],
|
||||
'en' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link to an English version of the current path.'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'language' => $languages['en'],
|
||||
'attributes' => array(
|
||||
'attributes' => [
|
||||
'id' => 'en_link',
|
||||
),
|
||||
],
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +130,7 @@ class LanguageTestController implements ContainerInjectionInterface {
|
|||
else {
|
||||
$base_path = $request->getBasePath();
|
||||
}
|
||||
$sub_request = Request::create($base_path . '/user', 'GET', $request->query->all(), $request->cookies->all(), array(), $server);
|
||||
$sub_request = Request::create($base_path . '/user', 'GET', $request->query->all(), $request->cookies->all(), [], $server);
|
||||
return $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Test administration path based conversion of entities.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class AdminPathEntityConverterLanguageTest extends BrowserTestBase {
|
||||
|
||||
public static $modules = ['language', 'language_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$permissions = [
|
||||
'access administration pages',
|
||||
'administer site configuration',
|
||||
];
|
||||
$this->drupalLogin($this->drupalCreateUser($permissions));
|
||||
ConfigurableLanguage::createFromLangcode('es')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the translated and untranslated config entities are loaded properly.
|
||||
*/
|
||||
public function testConfigUsingCurrentLanguage() {
|
||||
\Drupal::languageManager()
|
||||
->getLanguageConfigOverride('es', 'language.entity.es')
|
||||
->set('label', 'Español')
|
||||
->save();
|
||||
|
||||
$this->drupalGet('es/admin/language_test/entity_using_current_language/es');
|
||||
$this->assertNoRaw(t('Loaded %label.', ['%label' => 'Spanish']));
|
||||
$this->assertRaw(t('Loaded %label.', ['%label' => 'Español']));
|
||||
|
||||
$this->drupalGet('es/admin/language_test/entity_using_original_language/es');
|
||||
$this->assertRaw(t('Loaded %label.', ['%label' => 'Spanish']));
|
||||
$this->assertNoRaw(t('Loaded %label.', ['%label' => 'Español']));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the language settings on block config appears correctly.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageBlockSettingsVisibilityTest extends BrowserTestBase {
|
||||
|
||||
public static $modules = ['block', 'language'];
|
||||
|
||||
public function testUnnecessaryLanguageSettingsVisibility() {
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer blocks']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'hu'], t('Add language'));
|
||||
$this->drupalGet('admin/structure/block/add/system_menu_block:admin/stark');
|
||||
$this->assertNoFieldByXPath('//input[@id="edit-visibility-language-langcodes-und"]', NULL, '\'Not specified\' option does not appear at block config, language settings section.');
|
||||
$this->assertNoFieldByXpath('//input[@id="edit-visibility-language-langcodes-zxx"]', NULL, '\'Not applicable\' option does not appear at block config, language settings section.');
|
||||
$this->assertFieldByXPath('//input[@id="edit-visibility-language-langcodes-en"]', NULL, '\'English\' option appears at block config, language settings section.');
|
||||
$this->assertFieldByXpath('//input[@id="edit-visibility-language-langcodes-hu"]', NULL, '\'Hungarian\' option appears at block config, language settings section.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests browser language detection.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageBrowserDetectionTest extends BrowserTestBase {
|
||||
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests for adding, editing and deleting mappings between browser language
|
||||
* codes and Drupal language codes.
|
||||
*/
|
||||
public function testUIBrowserLanguageMappings() {
|
||||
// User to manage languages.
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Check that the configure link exists.
|
||||
$this->drupalGet('admin/config/regional/language/detection');
|
||||
$this->assertLinkByHref('admin/config/regional/language/detection/browser');
|
||||
|
||||
// Check that defaults are loaded from language.mappings.yml.
|
||||
$this->drupalGet('admin/config/regional/language/detection/browser');
|
||||
$this->assertField('edit-mappings-zh-cn-browser-langcode', 'zh-cn', 'Chinese browser language code found.');
|
||||
$this->assertField('edit-mappings-zh-cn-drupal-langcode', 'zh-hans-cn', 'Chinese Drupal language code found.');
|
||||
|
||||
// Delete zh-cn language code.
|
||||
$browser_langcode = 'zh-cn';
|
||||
$this->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode);
|
||||
$message = t('Are you sure you want to delete @browser_langcode?', [
|
||||
'@browser_langcode' => $browser_langcode,
|
||||
]);
|
||||
$this->assertRaw($message);
|
||||
|
||||
// Confirm the delete.
|
||||
$edit = [];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm'));
|
||||
|
||||
// We need raw here because %browser will add HTML.
|
||||
$t_args = [
|
||||
'%browser' => $browser_langcode,
|
||||
];
|
||||
$this->assertRaw(t('The mapping for the %browser browser language code has been deleted.', $t_args), 'The test browser language code has been deleted.');
|
||||
|
||||
// Check we went back to the browser negotiation mapping overview.
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
// Check that ch-zn no longer exists.
|
||||
$this->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.');
|
||||
|
||||
// Add a new custom mapping.
|
||||
$edit = [
|
||||
'new_mapping[browser_langcode]' => 'xx',
|
||||
'new_mapping[drupal_langcode]' => 'en',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
$this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
|
||||
$this->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.');
|
||||
|
||||
// Add the same custom mapping again.
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertText('Browser language codes must be unique.');
|
||||
|
||||
// Change browser language code of our custom mapping to zh-sg.
|
||||
$edit = [
|
||||
'mappings[xx][browser_langcode]' => 'zh-sg',
|
||||
'mappings[xx][drupal_langcode]' => 'en',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertText(t('Browser language codes must be unique.'));
|
||||
|
||||
// Change Drupal language code of our custom mapping to zh-hans.
|
||||
$edit = [
|
||||
'mappings[xx][browser_langcode]' => 'xx',
|
||||
'mappings[xx][drupal_langcode]' => 'zh-hans',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
|
||||
$this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
|
||||
$this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
|
||||
$this->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Ensures the language config overrides can be synchronized.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigOverrideImportTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'config', 'locale', 'config_translation'];
|
||||
|
||||
/**
|
||||
* Tests that language can be enabled and overrides are created during a sync.
|
||||
*/
|
||||
public function testConfigOverrideImport() {
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
/* @var \Drupal\Core\Config\StorageInterface $sync */
|
||||
$sync = \Drupal::service('config.storage.sync');
|
||||
$this->copyConfig(\Drupal::service('config.storage'), $sync);
|
||||
|
||||
// Uninstall the language module and its dependencies so we can test
|
||||
// enabling the language module and creating overrides at the same time
|
||||
// during a configuration synchronization.
|
||||
\Drupal::service('module_installer')->uninstall(['language']);
|
||||
// Ensure that the current site has no overrides registered to the
|
||||
// ConfigFactory.
|
||||
$this->rebuildContainer();
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $override_sync */
|
||||
$override_sync = $sync->createCollection('language.fr');
|
||||
// Create some overrides in sync.
|
||||
$override_sync->write('system.site', ['name' => 'FR default site name']);
|
||||
$override_sync->write('system.maintenance', ['message' => 'FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience']);
|
||||
|
||||
$this->configImporter()->import();
|
||||
$this->rebuildContainer();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
$override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
|
||||
$this->assertEqual('FR default site name', $override->get('name'));
|
||||
$this->drupalGet('fr');
|
||||
$this->assertText('FR default site name');
|
||||
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->drupalGet('admin/config/development/maintenance/translate/fr/edit');
|
||||
$this->assertText('FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configuration events are not fired during a sync of overrides.
|
||||
*/
|
||||
public function testConfigOverrideImportEvents() {
|
||||
// Enable the config_events_test module so we can record events occurring.
|
||||
\Drupal::service('module_installer')->install(['config_events_test']);
|
||||
$this->rebuildContainer();
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $sync */
|
||||
$sync = \Drupal::service('config.storage.sync');
|
||||
$this->copyConfig(\Drupal::service('config.storage'), $sync);
|
||||
|
||||
/* @var \Drupal\Core\Config\StorageInterface $override_sync */
|
||||
$override_sync = $sync->createCollection('language.fr');
|
||||
// Create some overrides in sync.
|
||||
$override_sync->write('system.site', ['name' => 'FR default site name']);
|
||||
\Drupal::state()->set('config_events_test.event', FALSE);
|
||||
|
||||
$this->configImporter()->import();
|
||||
$this->rebuildContainer();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// Test that no config save event has been fired during the import because
|
||||
// language configuration overrides do not fire events.
|
||||
$event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
|
||||
$this->assertFalse($event_recorder);
|
||||
|
||||
$this->drupalGet('fr');
|
||||
$this->assertText('FR default site name');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Ensures the language config schema is correct.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigSchemaTest extends BrowserTestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'menu_link_content'];
|
||||
|
||||
/**
|
||||
* A user with administrative permissions.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create user.
|
||||
$this->adminUser = $this->drupalCreateUser(['administer languages']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the language config schema is valid.
|
||||
*/
|
||||
public function testValidLanguageConfigSchema() {
|
||||
// Make sure no language configuration available by default.
|
||||
$config_data = $this->config('language.settings')->get();
|
||||
$this->assertTrue(empty($config_data));
|
||||
|
||||
$settings_path = 'admin/config/regional/content-language';
|
||||
|
||||
// Enable translation for menu link.
|
||||
$edit['entity_types[menu_link_content]'] = TRUE;
|
||||
$edit['settings[menu_link_content][menu_link_content][settings][language][language_alterable]'] = TRUE;
|
||||
|
||||
// Enable translation for user.
|
||||
$edit['entity_types[user]'] = TRUE;
|
||||
$edit['settings[user][user][settings][language][language_alterable]'] = TRUE;
|
||||
$edit['settings[user][user][settings][language][langcode]'] = 'en';
|
||||
|
||||
$this->drupalPostForm($settings_path, $edit, t('Save configuration'));
|
||||
|
||||
$config_data = $this->config('language.content_settings.menu_link_content.menu_link_content');
|
||||
// Make sure configuration saved correctly.
|
||||
$this->assertTrue($config_data->get('language_alterable'));
|
||||
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), $config_data->getName(), $config_data->get());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests enabling Language if a module exists that calls
|
||||
* LanguageManager::getLanguages() during installation.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageListModuleInstallTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language_test'];
|
||||
|
||||
/**
|
||||
* Tests enabling Language.
|
||||
*/
|
||||
public function testModuleInstallLanguageList() {
|
||||
// Since LanguageManager::getLanguages() uses static caches we need to do
|
||||
// this by enabling the module using the UI.
|
||||
$admin_user = $this->drupalCreateUser(['access administration pages', 'administer modules']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = [];
|
||||
$edit['modules[language][enable]'] = 'language';
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
|
||||
$this->assertEqual(\Drupal::state()->get('language_test.language_count_preinstall', 0), 1, 'Using LanguageManager::getLanguages() returns 1 language during Language installation.');
|
||||
|
||||
// Get updated module list by rebuilding container.
|
||||
$this->rebuildContainer();
|
||||
$this->assertTrue(\Drupal::moduleHandler()->moduleExists('language'), 'Language module is enabled');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests language negotiation with the language negotiator content entity.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationContentEntityTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'language_test', 'entity_test', 'system'];
|
||||
|
||||
/**
|
||||
* The entity being used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ConfigurableLanguage::create(['id' => 'es'])->save();
|
||||
ConfigurableLanguage::create(['id' => 'fr'])->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
$this->createTranslatableEntity();
|
||||
|
||||
$user = $this->drupalCreateUser(['view test entity']);
|
||||
$this->drupalLogin($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests default with content language remaining same as interface language.
|
||||
*/
|
||||
public function testDefaultConfiguration() {
|
||||
$translation = $this->entity;
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
|
||||
$translation = $this->entity->getTranslation('es');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
|
||||
$translation = $this->entity->getTranslation('fr');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), new FormattableMarkup('Interface language %interface_language and Content language %content_language are the same as the translation language %translation_language of the entity.', ['%interface_language' => $last_interface_language, '%content_language' => $last_content_language, '%translation_language' => $translation->language()->getId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests enabling the language negotiator language_content_entity.
|
||||
*/
|
||||
public function testEnabledLanguageContentNegotiator() {
|
||||
// Define the method language-url with a higher priority than
|
||||
// language-content-entity. This configuration should match the default one,
|
||||
// where the language-content-entity is turned off.
|
||||
$config = $this->config('language.types');
|
||||
$config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationUrl::METHOD_ID => 0,
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// The tests for the default configuration should still pass.
|
||||
$this->testDefaultConfiguration();
|
||||
|
||||
// Define the method language-content-entity with a higher priority than
|
||||
// language-url.
|
||||
$config->set('negotiation.language_content.enabled', [
|
||||
LanguageNegotiationContentEntity::METHOD_ID => 0,
|
||||
LanguageNegotiationUrl::METHOD_ID => 1
|
||||
]);
|
||||
$config->save();
|
||||
|
||||
// In order to reflect the changes for a multilingual site in the container
|
||||
// we have to rebuild it.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// The method language-content-entity should run before language-url and
|
||||
// append query parameter for the content language and prevent language-url
|
||||
// from overwriting the URL.
|
||||
$default_site_langcode = $this->config('system.site')->get('default_langcode');
|
||||
|
||||
// Now switching to an entity route, so that the URL links are generated
|
||||
// while being on an entity route.
|
||||
$this->setCurrentRequestForRoute('/entity_test/{entity_test}', 'entity.entity_test.canonical');
|
||||
|
||||
$translation = $this->entity;
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue(($last_interface_language == $default_site_langcode) && ($last_interface_language == $last_content_language) && ($last_content_language == $translation->language()->getId()), 'Interface language and Content language are the same as the default translation language of the entity.');
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
|
||||
$translation = $this->entity->getTranslation('es');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
|
||||
$translation = $this->entity->getTranslation('fr');
|
||||
$this->drupalGet($translation->urlInfo());
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
$last_content_language = $last[LanguageInterface::TYPE_CONTENT];
|
||||
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
|
||||
$this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
|
||||
$this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translated entity.
|
||||
*/
|
||||
protected function createTranslatableEntity() {
|
||||
$this->entity = EntityTest::create();
|
||||
$this->entity->addTranslation('es', ['name' => 'name spanish']);
|
||||
$this->entity->addTranslation('fr', ['name' => 'name french']);
|
||||
$this->entity->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current request to a specific path with the corresponding route.
|
||||
*
|
||||
* @param string $path
|
||||
* The path for which the current request should be created.
|
||||
* @param string $route_name
|
||||
* The route name for which the route object for the request should be
|
||||
* created.
|
||||
*/
|
||||
protected function setCurrentRequestForRoute($path, $route_name) {
|
||||
$request = Request::create($path);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, $route_name);
|
||||
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route($path));
|
||||
$this->container->get('request_stack')->push($request);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests alterations to language types/negotiation info.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationInfoTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['language', 'content_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'view the administration theme', 'administer modules']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'it'], t('Add language'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configurable language manager.
|
||||
*
|
||||
* @return \Drupal\language\ConfigurableLanguageManager
|
||||
*/
|
||||
protected function languageManager() {
|
||||
return $this->container->get('language_manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets state flags for language_test module.
|
||||
*
|
||||
* Ensures to correctly update data both in the child site and the test runner
|
||||
* environment.
|
||||
*
|
||||
* @param array $values
|
||||
* The key/value pairs to set in state.
|
||||
*/
|
||||
protected function stateSet(array $values) {
|
||||
// Set the new state values.
|
||||
$this->container->get('state')->setMultiple($values);
|
||||
// Refresh in-memory static state/config caches and static variables.
|
||||
$this->refreshVariables();
|
||||
// Refresh/rewrite language negotiation configuration, in order to pick up
|
||||
// the manipulations performed by language_test module's info alter hooks.
|
||||
$this->container->get('language_negotiator')->purgeConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests alterations to language types/negotiation info.
|
||||
*/
|
||||
public function testInfoAlterations() {
|
||||
$this->stateSet([
|
||||
// Enable language_test type info.
|
||||
'language_test.language_types' => TRUE,
|
||||
// Enable language_test negotiation info (not altered yet).
|
||||
'language_test.language_negotiation_info' => TRUE,
|
||||
// Alter LanguageInterface::TYPE_CONTENT to be configurable.
|
||||
'language_test.content_language_type' => TRUE,
|
||||
]);
|
||||
$this->container->get('module_installer')->install(['language_test']);
|
||||
$this->resetAll();
|
||||
|
||||
// Check that fixed language types are properly configured without the need
|
||||
// of saving the language negotiation settings.
|
||||
$this->checkFixedLanguageTypes();
|
||||
|
||||
$type = LanguageInterface::TYPE_CONTENT;
|
||||
$language_types = $this->languageManager()->getLanguageTypes();
|
||||
$this->assertTrue(in_array($type, $language_types), 'Content language type is configurable.');
|
||||
|
||||
// Enable some core and custom language negotiation methods. The test
|
||||
// language type is supposed to be configurable.
|
||||
$test_type = 'test_language_type';
|
||||
$interface_method_id = LanguageNegotiationUI::METHOD_ID;
|
||||
$test_method_id = 'test_language_negotiation_method';
|
||||
$form_field = $type . '[enabled][' . $interface_method_id . ']';
|
||||
$edit = [
|
||||
$form_field => TRUE,
|
||||
$type . '[enabled][' . $test_method_id . ']' => TRUE,
|
||||
$test_type . '[enabled][' . $test_method_id . ']' => TRUE,
|
||||
$test_type . '[configurable]' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Alter language negotiation info to remove interface language negotiation
|
||||
// method.
|
||||
$this->stateSet([
|
||||
'language_test.language_negotiation_info_alter' => TRUE,
|
||||
]);
|
||||
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$this->assertFalse(isset($negotiation[$interface_method_id]), 'Interface language negotiation method removed from the stored settings.');
|
||||
|
||||
$this->drupalGet('admin/config/regional/language/detection');
|
||||
$this->assertNoFieldByName($form_field, NULL, 'Interface language negotiation method unavailable.');
|
||||
|
||||
// Check that type-specific language negotiation methods can be assigned
|
||||
// only to the corresponding language types.
|
||||
foreach ($this->languageManager()->getLanguageTypes() as $type) {
|
||||
$form_field = $type . '[enabled][test_language_negotiation_method_ts]';
|
||||
if ($type == $test_type) {
|
||||
$this->assertFieldByName($form_field, NULL, format_string('Type-specific test language negotiation method available for %type.', ['%type' => $type]));
|
||||
}
|
||||
else {
|
||||
$this->assertNoFieldByName($form_field, NULL, format_string('Type-specific test language negotiation method unavailable for %type.', ['%type' => $type]));
|
||||
}
|
||||
}
|
||||
|
||||
// Check language negotiation results.
|
||||
$this->drupalGet('');
|
||||
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$langcode = $last[$type];
|
||||
$value = $type == LanguageInterface::TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en';
|
||||
$this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', ['%type' => $type, '%language' => $value]));
|
||||
}
|
||||
|
||||
// Uninstall language_test and check that everything is set back to the
|
||||
// original status.
|
||||
$this->container->get('module_installer')->uninstall(['language_test']);
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Check that only the core language types are available.
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
|
||||
$this->assertTrue(strpos($type, 'test') === FALSE, format_string('The %type language is still available', ['%type' => $type]));
|
||||
}
|
||||
|
||||
// Check that fixed language types are properly configured, even those
|
||||
// previously set to configurable.
|
||||
$this->checkFixedLanguageTypes();
|
||||
|
||||
// Check that unavailable language negotiation methods are not present in
|
||||
// the negotiation settings.
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$this->assertFalse(isset($negotiation[$test_method_id]), 'The disabled test language negotiation method is not part of the content language negotiation settings.');
|
||||
|
||||
// Check that configuration page presents the correct options and settings.
|
||||
$this->assertNoRaw(t('Test language detection'), 'No test language type configuration available.');
|
||||
$this->assertNoRaw(t('This is a test language negotiation method'), 'No test language negotiation method available.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that language negotiation for fixed types matches the stored one.
|
||||
*/
|
||||
protected function checkFixedLanguageTypes() {
|
||||
$configurable = $this->languageManager()->getLanguageTypes();
|
||||
foreach ($this->languageManager()->getDefinedLanguageTypesInfo() as $type => $info) {
|
||||
if (!in_array($type, $configurable) && isset($info['fixed'])) {
|
||||
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
|
||||
$equal = count($info['fixed']) == count($negotiation);
|
||||
while ($equal && list($id) = each($negotiation)) {
|
||||
list(, $info_id) = each($info['fixed']);
|
||||
$equal = $info_id == $id;
|
||||
}
|
||||
$this->assertTrue($equal, format_string('language negotiation for %type is properly set up', ['%type' => $type]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests altering config of configurable language types.
|
||||
*/
|
||||
public function testConfigLangTypeAlterations() {
|
||||
// Default of config.
|
||||
$test_type = LanguageInterface::TYPE_CONTENT;
|
||||
$this->assertFalse($this->isLanguageTypeConfigurable($test_type), 'Language type is not configurable.');
|
||||
|
||||
// Editing config.
|
||||
$edit = [$test_type . '[configurable]' => TRUE];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is now configurable.');
|
||||
|
||||
// After installing another module, the config should be the same.
|
||||
$this->drupalPostForm('admin/modules', ['modules[test_module][enable]' => 1], t('Install'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.');
|
||||
|
||||
// After uninstalling the other module, the config should be the same.
|
||||
$this->drupalPostForm('admin/modules/uninstall', ['uninstall[test_module]' => 1], t('Uninstall'));
|
||||
$this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given language type is configurable.
|
||||
*
|
||||
* @param string $type
|
||||
* The language type.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the specified language type is configurable, FALSE otherwise.
|
||||
*/
|
||||
protected function isLanguageTypeConfigurable($type) {
|
||||
$configurable_types = $this->config('language.types')->get('configurable');
|
||||
return in_array($type, $configurable_types);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationUrlTest extends BrowserTestBase {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'language',
|
||||
'node',
|
||||
'path',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create an Article node type.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(['type' => 'article']);
|
||||
}
|
||||
|
||||
$this->user = $this->drupalCreateUser([
|
||||
'administer languages',
|
||||
'access administration pages',
|
||||
'view the administration theme',
|
||||
'administer nodes',
|
||||
'create article content',
|
||||
'create url aliases',
|
||||
]);
|
||||
$this->drupalLogin($this->user);
|
||||
|
||||
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'de'], $this->t('Add language'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processInbound
|
||||
*/
|
||||
public function testDomain() {
|
||||
// Check if paths that contain language prefixes can be reached when
|
||||
// language is taken from the domain.
|
||||
$edit = [
|
||||
'language_negotiation_url_part' => 'domain',
|
||||
'prefix[en]' => 'eng',
|
||||
'prefix[de]' => 'de',
|
||||
'domain[en]' => $_SERVER['HTTP_HOST'],
|
||||
'domain[de]' => "de.$_SERVER[HTTP_HOST]",
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, $this->t('Save configuration'));
|
||||
|
||||
$nodeValues = [
|
||||
'title[0][value]' => 'Test',
|
||||
'path[0][alias]' => '/eng/test',
|
||||
];
|
||||
$this->drupalPostForm('node/add/article', $nodeValues, $this->t('Save and publish'));
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Confirm that paths are not changed on monolingual non-English sites.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguagePathMonolingualTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'language', 'path'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$web_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer site configuration']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Enable French language.
|
||||
$edit = [];
|
||||
$edit['predefined_langcode'] = 'fr';
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Make French the default language.
|
||||
$edit = [
|
||||
'site_default_language' => 'fr',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
|
||||
|
||||
// Delete English.
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', [], t('Delete'));
|
||||
|
||||
// Changing the default language causes a container rebuild. Therefore need
|
||||
// to rebuild the container in the test environment.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Verify that French is the only language.
|
||||
$this->container->get('language_manager')->reset();
|
||||
$this->assertFalse(\Drupal::languageManager()->isMultilingual(), 'Site is mono-lingual');
|
||||
$this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), 'fr', 'French is the default language');
|
||||
|
||||
// Set language detection to URL.
|
||||
$edit = ['language_interface[enabled][language-url]' => TRUE];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that links do not have language prefixes in them.
|
||||
*/
|
||||
public function testPageLinks() {
|
||||
// Navigate to 'admin/config' path.
|
||||
$this->drupalGet('admin/config');
|
||||
|
||||
// Verify that links in this page do not have a 'fr/' prefix.
|
||||
$this->assertNoLinkByHref('/fr/', 'Links do not contain language prefix');
|
||||
|
||||
// Verify that links in this page can be followed and work.
|
||||
$this->clickLink(t('Languages'));
|
||||
$this->assertResponse(200, 'Clicked link results in a valid page');
|
||||
$this->assertText(t('Add language'), 'Page contains the add language text');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Functional\Migrate;
|
||||
|
||||
use Drupal\language\ConfigurableLanguageInterface;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateLanguageTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Asserts various properties of a configurable language entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The language ID.
|
||||
* @param string $label
|
||||
* The language name.
|
||||
* @param string $direction
|
||||
* (optional) The language's direction (one of the DIRECTION_* constants in
|
||||
* ConfigurableLanguageInterface). Defaults to LTR.
|
||||
* @param int $weight
|
||||
* (optional) The weight of the language. Defaults to 0.
|
||||
*/
|
||||
protected function assertLanguage($id, $label, $direction = ConfigurableLanguageInterface::DIRECTION_LTR, $weight = 0) {
|
||||
/** @var \Drupal\language\ConfigurableLanguageInterface $language */
|
||||
$language = ConfigurableLanguage::load($id);
|
||||
$this->assertTrue($language instanceof ConfigurableLanguageInterface);
|
||||
$this->assertIdentical($label, $language->label());
|
||||
$this->assertIdentical($direction, $language->getDirection());
|
||||
$this->assertIdentical(0, $language->getWeight());
|
||||
$this->assertFalse($language->isLocked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of Drupal 6 languages to configurable language entities.
|
||||
*/
|
||||
public function testLanguageMigration() {
|
||||
$this->executeMigration('language');
|
||||
$this->assertLanguage('en', 'English');
|
||||
$this->assertLanguage('fr', 'French');
|
||||
}
|
||||
|
||||
}
|
|
@ -32,12 +32,12 @@ class LanguageConditionTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'language');
|
||||
public static $modules = ['system', 'language'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('language'));
|
||||
$this->installConfig(['language']);
|
||||
// Setup Italian.
|
||||
ConfigurableLanguage::createFromLangcode('it')->save();
|
||||
|
||||
|
@ -52,14 +52,14 @@ class LanguageConditionTest extends KernelTestBase {
|
|||
// language.
|
||||
$language = \Drupal::languageManager()->getLanguage('en');
|
||||
$condition = $this->manager->createInstance('language')
|
||||
->setConfig('langcodes', array('en' => 'en', 'it' => 'it'))
|
||||
->setConfig('langcodes', ['en' => 'en', 'it' => 'it'])
|
||||
->setContextValue('language', $language);
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is English, Italian.');
|
||||
|
||||
// Change to Italian only.
|
||||
$condition->setConfig('langcodes', array('it' => 'it'));
|
||||
$condition->setConfig('langcodes', ['it' => 'it']);
|
||||
$this->assertFalse($condition->execute(), 'Language condition fails as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is Italian.');
|
||||
|
@ -74,7 +74,7 @@ class LanguageConditionTest extends KernelTestBase {
|
|||
$language = \Drupal::languageManager()->getLanguage('it');
|
||||
|
||||
$condition = $this->manager->createInstance('language')
|
||||
->setConfig('langcodes', array('en' => 'en', 'it' => 'it'))
|
||||
->setConfig('langcodes', ['en' => 'en', 'it' => 'it'])
|
||||
->setContextValue('language', $language);
|
||||
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
|
@ -82,7 +82,7 @@ class LanguageConditionTest extends KernelTestBase {
|
|||
$this->assertEqual($condition->summary(), 'The language is English, Italian.');
|
||||
|
||||
// Change to Italian only.
|
||||
$condition->setConfig('langcodes', array('it' => 'it'));
|
||||
$condition->setConfig('langcodes', ['it' => 'it']);
|
||||
$this->assertTrue($condition->execute(), 'Language condition passes as expected.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual($condition->summary(), 'The language is Italian.');
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity.
|
||||
*
|
||||
* @group language
|
||||
* @coversDefaultClass \Drupal\language\ConfigurableLanguageManager
|
||||
*/
|
||||
class ConfigurableLanguageManagerTest extends LanguageTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['user'];
|
||||
|
||||
/**
|
||||
* The language negotiator.
|
||||
*
|
||||
* @var \Drupal\language\LanguageNegotiatorInterface
|
||||
*/
|
||||
protected $languageNegotiator;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\language\ConfigurableLanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installSchema('system', ['sequence']);
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
$this->languageNegotiator = $this->container->get('language_negotiator');
|
||||
$this->languageManager = $this->container->get('language_manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getLanguageSwitchLinks
|
||||
*/
|
||||
public function testLanguageSwitchLinks() {
|
||||
$this->languageNegotiator->setCurrentUser($this->prophesize('Drupal\Core\Session\AccountInterface')->reveal());
|
||||
$this->languageManager->getLanguageSwitchLinks(LanguageInterface::TYPE_INTERFACE, new Url('<current>'));
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@ class ConfigurableLanguageTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Tests configurable language name methods.
|
||||
|
@ -26,7 +26,7 @@ class ConfigurableLanguageTest extends KernelTestBase {
|
|||
public function testName() {
|
||||
$name = $this->randomMachineName();
|
||||
$language_code = $this->randomMachineName(2);
|
||||
$configurableLanguage = new ConfigurableLanguage(array('label' => $name, 'id' => $language_code), 'configurable_language');
|
||||
$configurableLanguage = new ConfigurableLanguage(['label' => $name, 'id' => $language_code], 'configurable_language');
|
||||
$this->assertEqual($configurableLanguage->getName(), $name);
|
||||
$this->assertEqual($configurableLanguage->setName('Test language')->getName(), 'Test language');
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class EntityDefaultLanguageTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'node', 'field', 'text', 'user', 'system');
|
||||
public static $modules = ['language', 'node', 'field', 'text', 'user', 'system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -29,9 +29,9 @@ class EntityDefaultLanguageTest extends KernelTestBase {
|
|||
$this->installEntitySchema('user');
|
||||
|
||||
// Activate Spanish language, so there are two languages activated.
|
||||
$language = $this->container->get('entity.manager')->getStorage('configurable_language')->create(array(
|
||||
$language = $this->container->get('entity.manager')->getStorage('configurable_language')->create([
|
||||
'id' => 'es',
|
||||
));
|
||||
]);
|
||||
$language->save();
|
||||
|
||||
// Create a new content type which has Undefined language by default.
|
||||
|
@ -67,7 +67,7 @@ class EntityDefaultLanguageTest extends KernelTestBase {
|
|||
$this->assertEqual($node->langcode->value, 'en');
|
||||
|
||||
// Disable language module.
|
||||
$this->disableModules(array('language'));
|
||||
$this->disableModules(['language']);
|
||||
|
||||
// With language module disabled, and a content type that is configured to
|
||||
// have no language specified by default, a new node of this content type
|
||||
|
@ -101,12 +101,12 @@ class EntityDefaultLanguageTest extends KernelTestBase {
|
|||
* Default language code of the nodes of this type.
|
||||
*/
|
||||
protected function createContentType($name, $langcode) {
|
||||
$content_type = $this->container->get('entity.manager')->getStorage('node_type')->create(array(
|
||||
$content_type = $this->container->get('entity.manager')->getStorage('node_type')->create([
|
||||
'name' => 'Test ' . $name,
|
||||
'title_label' => 'Title',
|
||||
'type' => $name,
|
||||
'create_body' => FALSE,
|
||||
));
|
||||
]);
|
||||
$content_type->save();
|
||||
ContentLanguageSettings::loadByEntityTypeBundle('node', $name)
|
||||
->setLanguageAlterable(FALSE)
|
||||
|
@ -127,10 +127,10 @@ class EntityDefaultLanguageTest extends KernelTestBase {
|
|||
* The node created.
|
||||
*/
|
||||
protected function createNode($type, $langcode = NULL) {
|
||||
$values = array(
|
||||
$values = [
|
||||
'type' => $type,
|
||||
'title' => $this->randomString(),
|
||||
);
|
||||
];
|
||||
if (!empty($langcode)) {
|
||||
$values['langcode'] = $langcode;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests \Drupal\language\Config\LanguageConfigFactoryOverride.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigFactoryOverrideTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system', 'language'];
|
||||
|
||||
/**
|
||||
* Tests language.config_factory_override service has the default language.
|
||||
*/
|
||||
public function testLanguageConfigFactoryOverride() {
|
||||
$this->installConfig('system');
|
||||
$this->installConfig('language');
|
||||
|
||||
/** @var \Drupal\language\Config\LanguageConfigFactoryOverride $config_factory_override */
|
||||
$config_factory_override = \Drupal::service('language.config_factory_override');
|
||||
$this->assertEquals('en', $config_factory_override->getLanguage()->getId());
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
|
||||
// Invalidate the container.
|
||||
$this->config('system.site')->set('default_langcode', 'de')->save();
|
||||
drupal_flush_all_caches();
|
||||
|
||||
$config_factory_override = \Drupal::service('language.config_factory_override');
|
||||
$this->assertEquals('de', $config_factory_override->getLanguage()->getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ class LanguageConfigOverrideInstallTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'config_events_test');
|
||||
public static $modules = ['language', 'config_events_test'];
|
||||
|
||||
/**
|
||||
* Tests the configuration events are not fired during install of overrides.
|
||||
|
@ -26,9 +26,9 @@ class LanguageConfigOverrideInstallTest extends KernelTestBase {
|
|||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
// Need to enable test module after creating the language otherwise saving
|
||||
// the language will install the configuration.
|
||||
$this->enableModules(array('language_config_override_test'));
|
||||
$this->enableModules(['language_config_override_test']);
|
||||
\Drupal::state()->set('config_events_test.event', FALSE);
|
||||
$this->installConfig(array('language_config_override_test'));
|
||||
$this->installConfig(['language_config_override_test']);
|
||||
$event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
|
||||
$this->assertFalse($event_recorder);
|
||||
$config = \Drupal::service('language.config_factory_override')->getOverride('de', 'language_config_override_test.settings');
|
||||
|
|
|
@ -18,11 +18,11 @@ class LanguageDependencyInjectionTest extends LanguageTestBase {
|
|||
*
|
||||
* @see \Drupal\Core\Language\LanguageInterface
|
||||
*/
|
||||
function testDependencyInjectedNewLanguage() {
|
||||
public function testDependencyInjectedNewLanguage() {
|
||||
$expected = $this->languageManager->getDefaultLanguage();
|
||||
$result = $this->languageManager->getCurrentLanguage();
|
||||
foreach ($expected as $property => $value) {
|
||||
$this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the new Language object %prop property.', array('%prop' => $property)));
|
||||
$this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the new Language object %prop property.', ['%prop' => $property]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ class LanguageDependencyInjectionTest extends LanguageTestBase {
|
|||
*
|
||||
* @see \Drupal\Core\Language\Language
|
||||
*/
|
||||
function testDependencyInjectedNewDefaultLanguage() {
|
||||
public function testDependencyInjectedNewDefaultLanguage() {
|
||||
$default_language = ConfigurableLanguage::load(\Drupal::languageManager()->getDefaultLanguage()->getId());
|
||||
// Change the language default object to different values.
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
@ -45,7 +45,7 @@ class LanguageDependencyInjectionTest extends LanguageTestBase {
|
|||
|
||||
// Delete the language to check that we fallback to the default.
|
||||
try {
|
||||
entity_delete_multiple('configurable_language', array('fr'));
|
||||
entity_delete_multiple('configurable_language', ['fr']);
|
||||
$this->fail('Expected DeleteDefaultLanguageException thrown.');
|
||||
}
|
||||
catch (DeleteDefaultLanguageException $e) {
|
||||
|
@ -55,7 +55,7 @@ class LanguageDependencyInjectionTest extends LanguageTestBase {
|
|||
// Re-save the previous default language and the delete should work.
|
||||
$this->config('system.site')->set('default_langcode', $default_language->getId())->save();
|
||||
|
||||
entity_delete_multiple('configurable_language', array('fr'));
|
||||
entity_delete_multiple('configurable_language', ['fr']);
|
||||
$result = \Drupal::languageManager()->getCurrentLanguage();
|
||||
$this->assertIdentical($result->getId(), $default_language->getId());
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class LanguageFallbackTest extends LanguageTestBase {
|
|||
parent::setUp();
|
||||
|
||||
$i = 0;
|
||||
foreach (array('af', 'am', 'ar') as $langcode) {
|
||||
foreach (['af', 'am', 'ar'] as $langcode) {
|
||||
$language = ConfigurableLanguage::createFromLangcode($langcode);
|
||||
$language->set('weight', $i--);
|
||||
$language->save();
|
||||
|
@ -31,7 +31,7 @@ class LanguageFallbackTest extends LanguageTestBase {
|
|||
*/
|
||||
public function testCandidates() {
|
||||
$language_list = $this->languageManager->getLanguages();
|
||||
$expected = array_keys($language_list + array(LanguageInterface::LANGCODE_NOT_SPECIFIED => NULL));
|
||||
$expected = array_keys($language_list + [LanguageInterface::LANGCODE_NOT_SPECIFIED => NULL]);
|
||||
|
||||
// Check that language fallback candidates by default are all the available
|
||||
// languages sorted by weight.
|
||||
|
@ -49,11 +49,11 @@ class LanguageFallbackTest extends LanguageTestBase {
|
|||
$this->state->set('language_test.fallback_operation_alter.candidates', TRUE);
|
||||
$expected[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
|
||||
$expected[] = LanguageInterface::LANGCODE_NOT_APPLICABLE;
|
||||
$candidates = $this->languageManager->getFallbackCandidates(array('operation' => 'test'));
|
||||
$candidates = $this->languageManager->getFallbackCandidates(['operation' => 'test']);
|
||||
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable for specific operations.');
|
||||
|
||||
// Check that when the site is monolingual no language fallback is applied.
|
||||
$langcodes_to_delete = array();
|
||||
$langcodes_to_delete = [];
|
||||
foreach ($language_list as $langcode => $language) {
|
||||
if (!$language->isDefault()) {
|
||||
$langcodes_to_delete[] = $langcode;
|
||||
|
@ -61,7 +61,7 @@ class LanguageFallbackTest extends LanguageTestBase {
|
|||
}
|
||||
entity_delete_multiple('configurable_language', $langcodes_to_delete);
|
||||
$candidates = $this->languageManager->getFallbackCandidates();
|
||||
$this->assertEqual(array_values($candidates), array(LanguageInterface::LANGCODE_DEFAULT), 'Language fallback is not applied when the Language module is not enabled.');
|
||||
$this->assertEqual(array_values($candidates), [LanguageInterface::LANGCODE_DEFAULT], 'Language fallback is not applied when the Language module is not enabled.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use Drupal\KernelTests\KernelTestBase;
|
|||
*/
|
||||
abstract class LanguageTestBase extends KernelTestBase {
|
||||
|
||||
public static $modules = array('system', 'language', 'language_test');
|
||||
public static $modules = ['system', 'language', 'language_test'];
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
|
@ -30,7 +30,7 @@ abstract class LanguageTestBase extends KernelTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('language'));
|
||||
$this->installConfig(['language']);
|
||||
|
||||
$this->state = $this->container->get('state');
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ trait MigrateDefaultLanguageTrait {
|
|||
// default language is migrated.
|
||||
$value = 'O:8:"stdClass":11:{s:8:"language";s:2:"' . $langcode . '";s:4:"name";s:6:"French";s:6:"native";s:6:"French";s:9:"direction";s:1:"0";s:7:"enabled";i:1;s:7:"plurals";s:1:"0";s:7:"formula";s:0:"";s:6:"domain";s:0:"";s:6:"prefix";s:0:"";s:6:"weight";s:1:"0";s:10:"javascript";s:0:"";}';
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'value' => $value
|
||||
))
|
||||
])
|
||||
->condition('name', 'language_default' )
|
||||
->execute();
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
public function testLanguageNegotiationWithNoNegotiation() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(0)))
|
||||
->fields(['value' => serialize(0)])
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
|
@ -88,7 +88,7 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
public function testLanguageNegotiationWithPathPrefix() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(2)))
|
||||
->fields(['value' => serialize(2)])
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
|
@ -129,7 +129,7 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
public function testLanguageNegotiationWithDomain() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(3)))
|
||||
->fields(['value' => serialize(3)])
|
||||
->condition('name', 'language_negotiation')
|
||||
->execute();
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class MigrateLanguageNegotiationSettingsTest extends MigrateDrupal7TestBase {
|
|||
*/
|
||||
public function testLanguageNegotiationWithDomain() {
|
||||
$this->sourceDatabase->update('variable')
|
||||
->fields(array('value' => serialize(1)))
|
||||
->fields(['value' => serialize(1)])
|
||||
->condition('name', 'locale_language_negotiation_url_part')
|
||||
->execute();
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Kernel\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the language source plugin.
|
||||
*
|
||||
* @covers \Drupal\language\Plugin\migrate\source\Language
|
||||
* @group language
|
||||
*/
|
||||
class LanguageTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language', 'migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['languages'] = [
|
||||
[
|
||||
'language' => 'en',
|
||||
'name' => 'English',
|
||||
'native' => 'English',
|
||||
'direction' => '0',
|
||||
'enabled' => '1',
|
||||
'plurals' => '0',
|
||||
'formula' => '',
|
||||
'domain' => '',
|
||||
'prefix' => '',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
],
|
||||
[
|
||||
'language' => 'fr',
|
||||
'name' => 'French',
|
||||
'native' => 'Français',
|
||||
'direction' => '0',
|
||||
'enabled' => '0',
|
||||
'plurals' => '2',
|
||||
'formula' => '($n>1)',
|
||||
'domain' => '',
|
||||
'prefix' => 'fr',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'language' => 'en',
|
||||
'name' => 'English',
|
||||
'native' => 'English',
|
||||
'direction' => '0',
|
||||
'enabled' => '1',
|
||||
'plurals' => '0',
|
||||
'formula' => '',
|
||||
'domain' => '',
|
||||
'prefix' => '',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
],
|
||||
[
|
||||
'language' => 'fr',
|
||||
'name' => 'French',
|
||||
'native' => 'Français',
|
||||
'direction' => '0',
|
||||
'enabled' => '0',
|
||||
'plurals' => '2',
|
||||
'formula' => '($n>1)',
|
||||
'domain' => '',
|
||||
'prefix' => 'fr',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
],
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,28 +17,28 @@ class ArgumentLanguageTest extends LanguageTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view');
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the language argument.
|
||||
*/
|
||||
public function testArgument() {
|
||||
$view = Views::getView('test_view');
|
||||
foreach (array('en' => 'John', 'xx-lolspeak' => 'George') as $langcode => $name) {
|
||||
foreach (['en' => 'John', 'xx-lolspeak' => 'George'] as $langcode => $name) {
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('arguments', array(
|
||||
'langcode' => array(
|
||||
$view->displayHandlers->get('default')->overrideOption('arguments', [
|
||||
'langcode' => [
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
),
|
||||
));
|
||||
$this->executeView($view, array($langcode));
|
||||
],
|
||||
]);
|
||||
$this->executeView($view, [$langcode]);
|
||||
|
||||
$expected = array(array(
|
||||
$expected = [[
|
||||
'name' => $name,
|
||||
));
|
||||
$this->assertIdenticalResultset($view, $expected, array('views_test_data_name' => 'name'));
|
||||
]];
|
||||
$this->assertIdenticalResultset($view, $expected, ['views_test_data_name' => 'name']);
|
||||
$view->destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class FieldLanguageTest extends LanguageTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view');
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the language field.
|
||||
|
@ -25,13 +25,13 @@ class FieldLanguageTest extends LanguageTestBase {
|
|||
public function testField() {
|
||||
$view = Views::getView('test_view');
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', array(
|
||||
'langcode' => array(
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', [
|
||||
'langcode' => [
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual($view->field['langcode']->advancedRender($view->result[0]), 'English');
|
||||
|
|
|
@ -17,29 +17,29 @@ class FilterLanguageTest extends LanguageTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view');
|
||||
public static $testViews = ['test_view'];
|
||||
|
||||
/**
|
||||
* Tests the language filter.
|
||||
*/
|
||||
public function testFilter() {
|
||||
$view = Views::getView('test_view');
|
||||
foreach (array('en' => 'John', 'xx-lolspeak' => 'George') as $langcode => $name) {
|
||||
foreach (['en' => 'John', 'xx-lolspeak' => 'George'] as $langcode => $name) {
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('filters', array(
|
||||
'langcode' => array(
|
||||
$view->displayHandlers->get('default')->overrideOption('filters', [
|
||||
'langcode' => [
|
||||
'id' => 'langcode',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'langcode',
|
||||
'value' => array($langcode),
|
||||
),
|
||||
));
|
||||
'value' => [$langcode],
|
||||
],
|
||||
]);
|
||||
$this->executeView($view);
|
||||
|
||||
$expected = array(array(
|
||||
$expected = [[
|
||||
'name' => $name,
|
||||
));
|
||||
$this->assertIdenticalResultset($view, $expected, array('views_test_data_name' => 'name'));
|
||||
]];
|
||||
$this->assertIdenticalResultset($view, $expected, ['views_test_data_name' => 'name']);
|
||||
|
||||
$expected = [
|
||||
'***LANGUAGE_site_default***',
|
||||
|
|
|
@ -15,14 +15,14 @@ abstract class LanguageTestBase extends ViewsKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'language');
|
||||
public static $modules = ['system', 'language'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp();
|
||||
$this->installConfig(array('language'));
|
||||
$this->installConfig(['language']);
|
||||
|
||||
// Create another language beside English.
|
||||
ConfigurableLanguage::create(array('id' => 'xx-lolspeak', 'label' => 'Lolspeak'))->save();
|
||||
ConfigurableLanguage::create(['id' => 'xx-lolspeak', 'label' => 'Lolspeak'])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,12 +30,12 @@ abstract class LanguageTestBase extends ViewsKernelTestBase {
|
|||
*/
|
||||
protected function schemaDefinition() {
|
||||
$schema = parent::schemaDefinition();
|
||||
$schema['views_test_data']['fields']['langcode'] = array(
|
||||
$schema['views_test_data']['fields']['langcode'] = [
|
||||
'description' => 'The {language}.langcode of this beatle.',
|
||||
'type' => 'varchar',
|
||||
'length' => 12,
|
||||
'default' => '',
|
||||
);
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
@ -45,19 +45,19 @@ abstract class LanguageTestBase extends ViewsKernelTestBase {
|
|||
*/
|
||||
protected function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test_data']['langcode'] = array(
|
||||
$data['views_test_data']['langcode'] = [
|
||||
'title' => t('Langcode'),
|
||||
'help' => t('Langcode'),
|
||||
'field' => array(
|
||||
'field' => [
|
||||
'id' => 'language',
|
||||
),
|
||||
'argument' => array(
|
||||
],
|
||||
'argument' => [
|
||||
'id' => 'language',
|
||||
),
|
||||
'filter' => array(
|
||||
],
|
||||
'filter' => [
|
||||
'id' => 'language',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ class ConfigurableLanguageUnitTest extends UnitTestCase {
|
|||
// Direction of language writing, an integer. Usually either
|
||||
// ConfigurableLanguage::DIRECTION_LTR or
|
||||
// ConfigurableLanguage::DIRECTION_RTL.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('direction' => ConfigurableLanguage::DIRECTION_LTR), 'configurable_language');
|
||||
$configurableLanguage = new ConfigurableLanguage(['direction' => ConfigurableLanguage::DIRECTION_LTR], 'configurable_language');
|
||||
$this->assertEquals(ConfigurableLanguage::DIRECTION_LTR, $configurableLanguage->getDirection());
|
||||
|
||||
// Test direction again, setting direction to RTL.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('direction' => ConfigurableLanguage::DIRECTION_RTL), 'configurable_language');
|
||||
$configurableLanguage = new ConfigurableLanguage(['direction' => ConfigurableLanguage::DIRECTION_RTL], 'configurable_language');
|
||||
$this->assertEquals(ConfigurableLanguage::DIRECTION_RTL, $configurableLanguage->getDirection());
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class ConfigurableLanguageUnitTest extends UnitTestCase {
|
|||
public function testWeight() {
|
||||
// The weight, an integer. Used to order languages with larger positive
|
||||
// weights sinking items toward the bottom of lists.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('weight' => -5), 'configurable_language');
|
||||
$configurableLanguage = new ConfigurableLanguage(['weight' => -5], 'configurable_language');
|
||||
$this->assertEquals($configurableLanguage->getWeight(), -5);
|
||||
$this->assertEquals($configurableLanguage->setWeight(13)->getWeight(), 13);
|
||||
}
|
||||
|
|
|
@ -86,17 +86,17 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
$target_entity_type->expects($this->any())
|
||||
->method('getBundleConfigDependency')
|
||||
->will($this->returnValue(array('type' => 'config', 'name' => 'test.test_entity_type.id')));
|
||||
->will($this->returnValue(['type' => 'config', 'name' => 'test.test_entity_type.id']));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with('test_entity_type')
|
||||
->will($this->returnValue($target_entity_type));
|
||||
|
||||
$config = new ContentLanguageSettings(array(
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$dependencies = $config->calculateDependencies()->getDependencies();
|
||||
$this->assertContains('test.test_entity_type.id', $dependencies['config']);
|
||||
}
|
||||
|
@ -105,10 +105,10 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
* @covers ::id
|
||||
*/
|
||||
public function testId() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$this->assertSame('test_entity_type.test_bundle', $config->id());
|
||||
}
|
||||
|
||||
|
@ -116,10 +116,10 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
* @covers ::getTargetEntityTypeId
|
||||
*/
|
||||
public function testTargetEntityTypeId() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$this->assertSame('test_entity_type', $config->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
|
@ -127,10 +127,10 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
* @covers ::getTargetBundle
|
||||
*/
|
||||
public function testTargetBundle() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$this->assertSame('test_bundle', $config->getTargetBundle());
|
||||
}
|
||||
|
||||
|
@ -146,16 +146,16 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
|
||||
public function providerDefaultLangcode() {
|
||||
$langcode = $this->randomMachineName();
|
||||
$config = new ContentLanguageSettings(array(
|
||||
$config = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$config->setDefaultLangcode($langcode);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
$defaultConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$config, $langcode],
|
||||
|
@ -174,22 +174,22 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
public function providerLanguageAlterable() {
|
||||
$alterableConfig = new ContentLanguageSettings(array(
|
||||
$alterableConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$alterableConfig->setLanguageAlterable(TRUE);
|
||||
|
||||
$nonAlterableConfig = new ContentLanguageSettings(array(
|
||||
$nonAlterableConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$nonAlterableConfig->setLanguageAlterable(FALSE);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
$defaultConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$alterableConfig, TRUE],
|
||||
|
@ -208,22 +208,22 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
public function providerIsDefaultConfiguration() {
|
||||
$alteredLanguage = new ContentLanguageSettings(array(
|
||||
$alteredLanguage = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$alteredLanguage->setLanguageAlterable(TRUE);
|
||||
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings(array(
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$alteredDefaultLangcode->setDefaultLangcode($this->randomMachineName());
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
$defaultConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$alteredLanguage, FALSE],
|
||||
|
@ -240,10 +240,10 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $existing_config = NULL, $expected_langcode, $expected_language_alterable) {
|
||||
list($type, $bundle) = explode('.', $config_id);
|
||||
|
||||
$nullConfig = new ContentLanguageSettings(array(
|
||||
$nullConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => $type,
|
||||
'target_bundle' => $bundle,
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$this->configEntityStorageInterface
|
||||
->expects($this->any())
|
||||
->method('load')
|
||||
|
@ -271,23 +271,23 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
public function providerLoadByEntityTypeBundle() {
|
||||
$alteredLanguage = new ContentLanguageSettings(array(
|
||||
$alteredLanguage = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$alteredLanguage->setLanguageAlterable(TRUE);
|
||||
|
||||
$langcode = $this->randomMachineName();
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings(array(
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
$alteredDefaultLangcode->setDefaultLangcode($langcode);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
$defaultConfig = new ContentLanguageSettings([
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
], 'language_content_settings');
|
||||
|
||||
return [
|
||||
['test_entity_type.test_bundle', $alteredLanguage, LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE],
|
||||
|
|
|
@ -33,10 +33,10 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
|
|||
$language_en->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('en'));
|
||||
$languages = array(
|
||||
$languages = [
|
||||
'de' => $language_de,
|
||||
'en' => $language_en,
|
||||
);
|
||||
];
|
||||
$this->languages = $languages;
|
||||
|
||||
// Create a language manager stub.
|
||||
|
@ -126,7 +126,7 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
|
|||
// No configuration.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => array(),
|
||||
'prefixes' => [],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// Non-matching prefix.
|
||||
|
@ -168,7 +168,7 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
|
|||
],
|
||||
]);
|
||||
|
||||
$request = Request::create('', 'GET', array(), array(), array(), array('HTTP_HOST' => $http_host));
|
||||
$request = Request::create('', 'GET', [], [], [], ['HTTP_HOST' => $http_host]);
|
||||
$method = new LanguageNegotiationUrl();
|
||||
$method->setLanguageManager($this->languageManager);
|
||||
$method->setConfig($config);
|
||||
|
@ -193,60 +193,60 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
|
|||
*/
|
||||
public function providerTestDomain() {
|
||||
|
||||
$domain_configuration[] = array(
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(
|
||||
'domains' => [
|
||||
'de' => 'http://example.de',
|
||||
),
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
];
|
||||
// No configuration.
|
||||
$domain_configuration[] = array(
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(),
|
||||
'domains' => [],
|
||||
'expected_langcode' => FALSE,
|
||||
);
|
||||
];
|
||||
// HTTP host with a port.
|
||||
$domain_configuration[] = array(
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.de:8080',
|
||||
'domains' => array(
|
||||
'domains' => [
|
||||
'de' => 'http://example.de',
|
||||
),
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
];
|
||||
// Domain configuration with https://.
|
||||
$domain_configuration[] = array(
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(
|
||||
'domains' => [
|
||||
'de' => 'https://example.de',
|
||||
),
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
];
|
||||
// Non-matching HTTP host.
|
||||
$domain_configuration[] = array(
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'domains' => [
|
||||
'de' => 'http://example.com',
|
||||
),
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
];
|
||||
// Testing a non-existing language.
|
||||
$domain_configuration[] = array(
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'domains' => [
|
||||
'it' => 'http://example.it',
|
||||
),
|
||||
],
|
||||
'expected_langcode' => FALSE,
|
||||
);
|
||||
];
|
||||
// Multiple domain configurations.
|
||||
$domain_configuration[] = array(
|
||||
$domain_configuration[] = [
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'domains' => [
|
||||
'de' => 'http://example.de',
|
||||
'en' => 'http://example.com',
|
||||
),
|
||||
],
|
||||
'expected_langcode' => 'en',
|
||||
);
|
||||
];
|
||||
return $domain_configuration;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
|
|||
class LanguageLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->directoryList = array(
|
||||
$this->directoryList = [
|
||||
'language' => 'core/modules/language',
|
||||
);
|
||||
];
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
@ -31,19 +31,19 @@ class LanguageLocalTasksTest extends LocalTaskIntegrationTestBase {
|
|||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function getLanguageAdminOverviewRoutes() {
|
||||
return array(
|
||||
array('entity.configurable_language.collection', array(array('entity.configurable_language.collection', 'language.negotiation'))),
|
||||
array('language.negotiation', array(array('entity.configurable_language.collection', 'language.negotiation'))),
|
||||
);
|
||||
return [
|
||||
['entity.configurable_language.collection', [['entity.configurable_language.collection', 'language.negotiation']]],
|
||||
['language.negotiation', [['entity.configurable_language.collection', 'language.negotiation']]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language edit local tasks existence.
|
||||
*/
|
||||
public function testLanguageEditLocalTasks() {
|
||||
$this->assertLocalTasks('entity.configurable_language.edit_form', array(
|
||||
0 => array('entity.configurable_language.edit_form'),
|
||||
));
|
||||
$this->assertLocalTasks('entity.configurable_language.edit_form', [
|
||||
0 => ['entity.configurable_language.edit_form'],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\language\Unit\Migrate;
|
||||
|
||||
use Drupal\language\Plugin\migrate\source\Language;
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\source\Language
|
||||
* @group language
|
||||
*/
|
||||
class LanguageTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = Language::class;
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'language',
|
||||
),
|
||||
);
|
||||
|
||||
protected $databaseContents = array(
|
||||
'languages' => array(
|
||||
array(
|
||||
'language' => 'en',
|
||||
'name' => 'English',
|
||||
'native' => 'English',
|
||||
'direction' => '0',
|
||||
'enabled' => '1',
|
||||
'plurals' => '0',
|
||||
'formula' => '',
|
||||
'domain' => '',
|
||||
'prefix' => '',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
),
|
||||
array(
|
||||
'language' => 'fr',
|
||||
'name' => 'French',
|
||||
'native' => 'Français',
|
||||
'direction' => '0',
|
||||
'enabled' => '0',
|
||||
'plurals' => '2',
|
||||
'formula' => '($n>1)',
|
||||
'domain' => '',
|
||||
'prefix' => 'fr',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'language' => 'en',
|
||||
'name' => 'English',
|
||||
'native' => 'English',
|
||||
'direction' => '0',
|
||||
'enabled' => '1',
|
||||
'plurals' => '0',
|
||||
'formula' => '',
|
||||
'domain' => '',
|
||||
'prefix' => '',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
),
|
||||
array(
|
||||
'language' => 'fr',
|
||||
'name' => 'French',
|
||||
'native' => 'Français',
|
||||
'direction' => '0',
|
||||
'enabled' => '0',
|
||||
'plurals' => '2',
|
||||
'formula' => '($n>1)',
|
||||
'domain' => '',
|
||||
'prefix' => 'fr',
|
||||
'weight' => '0',
|
||||
'javascript' => '',
|
||||
),
|
||||
);
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\language\Unit\process;
|
|||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageNegotiation;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
use Drupal\migrate\MigrateException;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageNegotiation
|
||||
|
@ -75,12 +76,10 @@ class LanguageNegotiationTest extends MigrateProcessTestCase {
|
|||
|
||||
/**
|
||||
* Tests string input.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The input should be an array
|
||||
*/
|
||||
public function testStringInput() {
|
||||
$this->plugin = new LanguageNegotiation([], 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'The input should be an array');
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\language\Unit\process;
|
|||
|
||||
use Drupal\language\Plugin\migrate\process\LanguageTypes;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
use Drupal\migrate\MigrateException;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageTypes
|
||||
|
@ -49,12 +50,10 @@ class LanguageTypesTest extends MigrateProcessTestCase {
|
|||
|
||||
/**
|
||||
* Tests string input.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The input should be an array
|
||||
*/
|
||||
public function testStringInput() {
|
||||
$this->plugin = new LanguageTypes([], 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'The input should be an array');
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue