Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -57,10 +57,10 @@ function locale_test_locale_translation_projects_alter(&$projects) {
$remote_url = $url . PublicStream::basePath() . '/remote/';
// Completely replace the project data with a set of test projects.
$projects = array(
'contrib_module_one' => array(
$projects = [
'contrib_module_one' => [
'name' => 'contrib_module_one',
'info' => array(
'info' => [
'name' => 'Contributed module one',
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
'package' => 'Other',
@ -68,14 +68,14 @@ function locale_test_locale_translation_projects_alter(&$projects) {
'project' => 'contrib_module_one',
'datestamp' => '1344471537',
'_info_file_ctime' => 1348767306,
),
],
'datestamp' => '1344471537',
'project_type' => 'module',
'project_status' => TRUE,
),
'contrib_module_two' => array(
],
'contrib_module_two' => [
'name' => 'contrib_module_two',
'info' => array(
'info' => [
'name' => 'Contributed module two',
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
'package' => 'Other',
@ -83,14 +83,14 @@ function locale_test_locale_translation_projects_alter(&$projects) {
'project' => 'contrib_module_two',
'datestamp' => '1344471537',
'_info_file_ctime' => 1348767306,
),
],
'datestamp' => '1344471537',
'project_type' => 'module',
'project_status' => TRUE,
),
'contrib_module_three' => array(
],
'contrib_module_three' => [
'name' => 'contrib_module_three',
'info' => array(
'info' => [
'name' => 'Contributed module three',
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
'package' => 'Other',
@ -98,14 +98,14 @@ function locale_test_locale_translation_projects_alter(&$projects) {
'project' => 'contrib_module_three',
'datestamp' => '1344471537',
'_info_file_ctime' => 1348767306,
),
],
'datestamp' => '1344471537',
'project_type' => 'module',
'project_status' => TRUE,
),
'locale_test' => array(
],
'locale_test' => [
'name' => 'locale_test',
'info' => array(
'info' => [
'name' => 'Locale test',
'interface translation project' => 'locale_test',
'interface translation server pattern' => 'core/modules/locale/tests/test.%language.po',
@ -114,14 +114,14 @@ function locale_test_locale_translation_projects_alter(&$projects) {
'project' => 'locale_test',
'_info_file_ctime' => 1348767306,
'datestamp' => 0,
),
],
'datestamp' => 0,
'project_type' => 'module',
'project_status' => TRUE,
),
'custom_module_one' => array(
],
'custom_module_one' => [
'name' => 'custom_module_one',
'info' => array(
'info' => [
'name' => 'Custom module one',
'interface translation project' => 'custom_module_one',
'interface translation server pattern' => 'translations://custom_module_one.%language.po',
@ -130,12 +130,12 @@ function locale_test_locale_translation_projects_alter(&$projects) {
'project' => 'custom_module_one',
'_info_file_ctime' => 1348767306,
'datestamp' => 0,
),
],
'datestamp' => 0,
'project_type' => 'module',
'project_status' => TRUE,
),
);
],
];
}
}

View file

@ -27,14 +27,14 @@ function locale_test_development_release_system_info_alter(&$info, Extension $fi
function locale_test_development_release_locale_translation_projects_alter(&$projects) {
$projects['contrib'] = [
'name' => 'contrib',
'info' => array(
'info' => [
'name' => 'Contributed module',
'package' => 'Other',
'version' => '12.x-10.4-unstable11+14-dev',
'project' => 'contrib_module',
'datestamp' => '0',
'_info_file_ctime' => 1442933959,
),
],
'datestamp' => '0',
'project_type' => 'module',
'project_status' => TRUE,

View file

@ -0,0 +1,202 @@
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\node\NodeInterface;
/**
* Tests you can enable multilingual support on content types and configure a
* language for a node.
*
* @group locale
*/
class LocaleContentTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'locale'];
/**
* Verifies that machine name fields are always LTR.
*/
public function testMachineNameLTR() {
// User to add and remove language.
$admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages', 'administer site configuration']);
// Log in as admin.
$this->drupalLogin($admin_user);
// Verify that the machine name field is LTR for a new content type.
$this->drupalGet('admin/structure/types/add');
$this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when no additional language is configured.');
// Install the Arabic language (which is RTL) and configure as the default.
$edit = [];
$edit['predefined_langcode'] = 'ar';
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
$edit = [
'site_default_language' => 'ar',
];
$this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
// Verify that the machine name field is still LTR for a new content type.
$this->drupalGet('admin/structure/types/add');
$this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when the default language is RTL.');
}
/**
* Test if a content type can be set to multilingual and language is present.
*/
public function testContentTypeLanguageConfiguration() {
$type1 = $this->drupalCreateContentType();
$type2 = $this->drupalCreateContentType();
// User to add and remove language.
$admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages']);
// User to create a node.
$web_user = $this->drupalCreateUser(["create {$type1->id()} content", "create {$type2->id()} content", "edit any {$type2->id()} content"]);
// Add custom language.
$this->drupalLogin($admin_user);
// Code for the language.
$langcode = 'xx';
// The English name for the language.
$name = $this->randomMachineName(16);
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
];
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
// Set the content type to use multilingual support.
$this->drupalGet("admin/structure/types/manage/{$type2->id()}");
$this->assertText(t('Language settings'), 'Multilingual support widget present on content type configuration form.');
$edit = [
'language_configuration[language_alterable]' => TRUE,
];
$this->drupalPostForm("admin/structure/types/manage/{$type2->id()}", $edit, t('Save content type'));
$this->assertRaw(t('The content type %type has been updated.', ['%type' => $type2->label()]));
$this->drupalLogout();
\Drupal::languageManager()->reset();
// Verify language selection is not present on the node add form.
$this->drupalLogin($web_user);
$this->drupalGet("node/add/{$type1->id()}");
// Verify language select list is not present.
$this->assertNoFieldByName('langcode[0][value]', NULL, 'Language select not present on the node add form.');
// Verify language selection appears on the node add form.
$this->drupalGet("node/add/{$type2->id()}");
// Verify language select list is present.
$this->assertFieldByName('langcode[0][value]', NULL, 'Language select present on the node add form.');
// Ensure language appears.
$this->assertText($name, 'Language present.');
// Create a node.
$node_title = $this->randomMachineName();
$node_body = $this->randomMachineName();
$edit = [
'type' => $type2->id(),
'title' => $node_title,
'body' => [['value' => $node_body]],
'langcode' => $langcode,
];
$node = $this->drupalCreateNode($edit);
// Edit the content and ensure correct language is selected.
$path = 'node/' . $node->id() . '/edit';
$this->drupalGet($path);
$this->assertRaw('<option value="' . $langcode . '" selected="selected">' . $name . '</option>', 'Correct language selected.');
// Ensure we can change the node language.
$edit = [
'langcode[0][value]' => 'en',
];
$this->drupalPostForm($path, $edit, t('Save'));
$this->assertText(t('@title has been updated.', ['@title' => $node_title]));
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/' . $node->id()]);
$this->assert(isset($view_link), 'The message area contains the link to the edited node');
$this->drupalLogout();
}
/**
* Test if a dir and lang tags exist in node's attributes.
*/
public function testContentTypeDirLang() {
$type = $this->drupalCreateContentType();
// User to add and remove language.
$admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages']);
// User to create a node.
$web_user = $this->drupalCreateUser(["create {$type->id()} content", "edit own {$type->id()} content"]);
// Log in as admin.
$this->drupalLogin($admin_user);
// Install Arabic language.
$edit = [];
$edit['predefined_langcode'] = 'ar';
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
// Install Spanish language.
$edit = [];
$edit['predefined_langcode'] = 'es';
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
\Drupal::languageManager()->reset();
// Set the content type to use multilingual support.
$this->drupalGet("admin/structure/types/manage/{$type->id()}");
$edit = [
'language_configuration[language_alterable]' => TRUE,
];
$this->drupalPostForm("admin/structure/types/manage/{$type->id()}", $edit, t('Save content type'));
$this->assertRaw(t('The content type %type has been updated.', ['%type' => $type->label()]));
$this->drupalLogout();
// Log in as web user to add new node.
$this->drupalLogin($web_user);
// Create three nodes: English, Arabic and Spanish.
$nodes = [];
foreach (['en', 'es', 'ar'] as $langcode) {
$nodes[$langcode] = $this->drupalCreateNode([
'langcode' => $langcode,
'type' => $type->id(),
'promote' => NodeInterface::PROMOTED,
]);
}
// Check if English node does not have lang tag.
$this->drupalGet('node/' . $nodes['en']->id());
$element = $this->cssSelect('article.node[lang="en"]');
$this->assertTrue(empty($element), 'The lang tag has not been assigned to the English node.');
// Check if English node does not have dir tag.
$element = $this->cssSelect('article.node[dir="ltr"]');
$this->assertTrue(empty($element), 'The dir tag has not been assigned to the English node.');
// Check if Arabic node has lang="ar" & dir="rtl" tags.
$this->drupalGet('node/' . $nodes['ar']->id());
$element = $this->cssSelect('article.node[lang="ar"][dir="rtl"]');
$this->assertTrue(!empty($element), 'The lang and dir tags have been assigned correctly to the Arabic node.');
// Check if Spanish node has lang="es" tag.
$this->drupalGet('node/' . $nodes['es']->id());
$element = $this->cssSelect('article.node[lang="es"]');
$this->assertTrue(!empty($element), 'The lang tag has been assigned correctly to the Spanish node.');
// Check if Spanish node does not have dir="ltr" tag.
$element = $this->cssSelect('article.node[lang="es"][dir="ltr"]');
$this->assertTrue(empty($element), 'The dir tag has not been assigned to the Spanish node.');
}
}

View file

@ -0,0 +1,58 @@
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
/**
* Tests LocaleLookup.
*
* @group locale
*/
class LocaleLocaleLookupTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['locale', 'locale_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Change the language default object to different values.
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->config('system.site')->set('default_langcode', 'fr')->save();
$this->drupalLogin($this->rootUser);
}
/**
* Tests that there are no circular dependencies.
*/
public function testCircularDependency() {
// Ensure that we can enable early_translation_test on a non-english site.
$this->drupalPostForm('admin/modules', ['modules[early_translation_test][enable]' => TRUE], t('Install'));
$this->assertResponse(200);
}
/**
* Test language fallback defaults.
*/
public function testLanguageFallbackDefaults() {
$this->drupalGet('');
// Ensure state of fallback languages persisted by
// locale_test_language_fallback_candidates_locale_lookup_alter() is empty.
$this->assertEqual(\Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_candidates'), []);
// Make sure there is enough information provided for alter hooks.
$context = \Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_context');
$this->assertEqual($context['langcode'], 'fr');
$this->assertEqual($context['operation'], 'locale_lookup');
}
}

View file

@ -0,0 +1,151 @@
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
/**
* Tests you can configure a language for individual URL aliases.
*
* @group locale
*/
class LocalePathTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'locale', 'path', 'views'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
$this->config('system.site')->set('page.front', '/node')->save();
}
/**
* Test if a language can be associated with a path alias.
*/
public function testPathLanguageConfiguration() {
// User to add and remove language.
$admin_user = $this->drupalCreateUser(['administer languages', 'create page content', 'administer url aliases', 'create url aliases', 'access administration pages', 'access content overview']);
// Add custom language.
$this->drupalLogin($admin_user);
// Code for the language.
$langcode = 'xx';
// The English name for the language.
$name = $this->randomMachineName(16);
// The domain prefix.
$prefix = $langcode;
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
];
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
// Set path prefix.
$edit = ["prefix[$langcode]" => $prefix];
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
// Check that the "xx" front page is readily available because path prefix
// negotiation is pre-configured.
$this->drupalGet($prefix);
$this->assertText(t('Welcome to Drupal'), 'The "xx" front page is readibly available.');
// Create a node.
$node = $this->drupalCreateNode(['type' => 'page']);
// Create a path alias in default language (English).
$path = 'admin/config/search/path/add';
$english_path = $this->randomMachineName(8);
$edit = [
'source' => '/node/' . $node->id(),
'alias' => '/' . $english_path,
'langcode' => 'en',
];
$this->drupalPostForm($path, $edit, t('Save'));
// Create a path alias in new custom language.
$custom_language_path = $this->randomMachineName(8);
$edit = [
'source' => '/node/' . $node->id(),
'alias' => '/' . $custom_language_path,
'langcode' => $langcode,
];
$this->drupalPostForm($path, $edit, t('Save'));
// Confirm English language path alias works.
$this->drupalGet($english_path);
$this->assertText($node->label(), 'English alias works.');
// Confirm custom language path alias works.
$this->drupalGet($prefix . '/' . $custom_language_path);
$this->assertText($node->label(), 'Custom language alias works.');
// Create a custom path.
$custom_path = $this->randomMachineName(8);
// Check priority of language for alias by source path.
$edit = [
'source' => '/node/' . $node->id(),
'alias' => '/' . $custom_path,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
];
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
$lookup_path = $this->container->get('path.alias_manager')->getAliasByPath('/node/' . $node->id(), 'en');
$this->assertEqual('/' . $english_path, $lookup_path, 'English language alias has priority.');
// Same check for language 'xx'.
$lookup_path = $this->container->get('path.alias_manager')->getAliasByPath('/node/' . $node->id(), $prefix);
$this->assertEqual('/' . $custom_language_path, $lookup_path, 'Custom language alias has priority.');
$this->container->get('path.alias_storage')->delete($edit);
// Create language nodes to check priority of aliases.
$first_node = $this->drupalCreateNode(['type' => 'page', 'promote' => 1, 'langcode' => 'en']);
$second_node = $this->drupalCreateNode(['type' => 'page', 'promote' => 1, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
// Assign a custom path alias to the first node with the English language.
$edit = [
'source' => '/node/' . $first_node->id(),
'alias' => '/' . $custom_path,
'langcode' => $first_node->language()->getId(),
];
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
// Assign a custom path alias to second node with
// LanguageInterface::LANGCODE_NOT_SPECIFIED.
$edit = [
'source' => '/node/' . $second_node->id(),
'alias' => '/' . $custom_path,
'langcode' => $second_node->language()->getId(),
];
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
// Test that both node titles link to our path alias.
$this->drupalGet('admin/content');
$custom_path_url = Url::fromUserInput('/' . $custom_path)->toString();
$elements = $this->xpath('//a[@href=:href and normalize-space(text())=:title]', [':href' => $custom_path_url, ':title' => $first_node->label()]);
$this->assertTrue(!empty($elements), 'First node links to the path alias.');
$elements = $this->xpath('//a[@href=:href and normalize-space(text())=:title]', [':href' => $custom_path_url, ':title' => $second_node->label()]);
$this->assertTrue(!empty($elements), 'Second node links to the path alias.');
// Confirm that the custom path leads to the first node.
$this->drupalGet($custom_path);
$this->assertText($first_node->label(), 'Custom alias returns first node.');
// Confirm that the custom path with prefix leads to the second node.
$this->drupalGet($prefix . '/' . $custom_path);
$this->assertText($second_node->label(), 'Custom alias with prefix returns second node.');
}
}

View file

@ -0,0 +1,205 @@
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the locale string storage, string objects and data API.
*
* @group locale
*/
class LocaleStringTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['locale'];
/**
* The locale storage.
*
* @var \Drupal\locale\StringStorageInterface
*/
protected $storage;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add a default locale storage for all these tests.
$this->storage = $this->container->get('locale.storage');
// Create two languages: Spanish and German.
foreach (['es', 'de'] as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)->save();
}
}
/**
* Test CRUD API.
*/
public function testStringCRUDAPI() {
// Create source string.
$source = $this->buildSourceString();
$source->save();
$this->assertTrue($source->lid, format_string('Successfully created string %string', ['%string' => $source->source]));
// Load strings by lid and source.
$string1 = $this->storage->findString(['lid' => $source->lid]);
$this->assertEqual($source, $string1, 'Successfully retrieved string by identifier.');
$string2 = $this->storage->findString(['source' => $source->source, 'context' => $source->context]);
$this->assertEqual($source, $string2, 'Successfully retrieved string by source and context.');
$string3 = $this->storage->findString(['source' => $source->source, 'context' => '']);
$this->assertFalse($string3, 'Cannot retrieve string with wrong context.');
// Check version handling and updating.
$this->assertEqual($source->version, 'none', 'String originally created without version.');
$string = $this->storage->findTranslation(['lid' => $source->lid]);
$this->assertEqual($string->version, \Drupal::VERSION, 'Checked and updated string version to Drupal version.');
// Create translation and find it by lid and source.
$langcode = 'es';
$translation = $this->createTranslation($source, $langcode);
$this->assertEqual($translation->customized, LOCALE_NOT_CUSTOMIZED, 'Translation created as not customized by default.');
$string1 = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
$this->assertEqual($string1->translation, $translation->translation, 'Successfully loaded translation by string identifier.');
$string2 = $this->storage->findTranslation(['language' => $langcode, 'source' => $source->source, 'context' => $source->context]);
$this->assertEqual($string2->translation, $translation->translation, 'Successfully loaded translation by source and context.');
$translation
->setCustomized()
->save();
$translation = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
$this->assertEqual($translation->customized, LOCALE_CUSTOMIZED, 'Translation successfully marked as customized.');
// Delete translation.
$translation->delete();
$deleted = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
$this->assertFalse(isset($deleted->translation), 'Successfully deleted translation string.');
// Create some translations and then delete string and all of its
// translations.
$lid = $source->lid;
$this->createAllTranslations($source);
$search = $this->storage->getTranslations(['lid' => $source->lid]);
$this->assertEqual(count($search), 3, 'Created and retrieved all translations for our source string.');
$source->delete();
$string = $this->storage->findString(['lid' => $lid]);
$this->assertFalse($string, 'Successfully deleted source string.');
$deleted = $search = $this->storage->getTranslations(['lid' => $lid]);
$this->assertFalse($deleted, 'Successfully deleted all translation strings.');
// Tests that locations of different types and arbitrary lengths can be
// added to a source string. Too long locations will be cut off.
$source_string = $this->buildSourceString();
$source_string->addLocation('javascript', $this->randomString(8));
$source_string->addLocation('configuration', $this->randomString(50));
$source_string->addLocation('code', $this->randomString(100));
$source_string->addLocation('path', $location = $this->randomString(300));
$source_string->save();
$rows = db_query('SELECT * FROM {locales_location} WHERE sid = :sid', [':sid' => $source_string->lid])->fetchAllAssoc('type');
$this->assertEqual(count($rows), 4, '4 source locations have been persisted.');
$this->assertEqual($rows['path']->name, substr($location, 0, 255), 'Too long location has been limited to 255 characters.');
}
/**
* Test Search API loading multiple objects.
*/
public function testStringSearchAPI() {
$language_count = 3;
// Strings 1 and 2 will have some common prefix.
// Source 1 will have all translations, not customized.
// Source 2 will have all translations, customized.
// Source 3 will have no translations.
$prefix = $this->randomMachineName(100);
$source1 = $this->buildSourceString(['source' => $prefix . $this->randomMachineName(100)])->save();
$source2 = $this->buildSourceString(['source' => $prefix . $this->randomMachineName(100)])->save();
$source3 = $this->buildSourceString()->save();
// Load all source strings.
$strings = $this->storage->getStrings([]);
$this->assertEqual(count($strings), 3, 'Found 3 source strings in the database.');
// Load all source strings matching a given string.
$filter_options['filters'] = ['source' => $prefix];
$strings = $this->storage->getStrings([], $filter_options);
$this->assertEqual(count($strings), 2, 'Found 2 strings using some string filter.');
// Not customized translations.
$translate1 = $this->createAllTranslations($source1);
// Customized translations.
$this->createAllTranslations($source2, ['customized' => LOCALE_CUSTOMIZED]);
// Try quick search function with different field combinations.
$langcode = 'es';
$found = $this->storage->findTranslation(['language' => $langcode, 'source' => $source1->source, 'context' => $source1->context]);
$this->assertTrue($found && isset($found->language) && isset($found->translation) && !$found->isNew(), 'Translation found searching by source and context.');
$this->assertEqual($found->translation, $translate1[$langcode]->translation, 'Found the right translation.');
// Now try a translation not found.
$found = $this->storage->findTranslation(['language' => $langcode, 'source' => $source3->source, 'context' => $source3->context]);
$this->assertTrue($found && $found->lid == $source3->lid && !isset($found->translation) && $found->isNew(), 'Translation not found but source string found.');
// Load all translations. For next queries we'll be loading only translated
// strings.
$translations = $this->storage->getTranslations(['translated' => TRUE]);
$this->assertEqual(count($translations), 2 * $language_count, 'Created and retrieved all translations for source strings.');
// Load all customized translations.
$translations = $this->storage->getTranslations(['customized' => LOCALE_CUSTOMIZED, 'translated' => TRUE]);
$this->assertEqual(count($translations), $language_count, 'Retrieved all customized translations for source strings.');
// Load all Spanish customized translations.
$translations = $this->storage->getTranslations(['language' => 'es', 'customized' => LOCALE_CUSTOMIZED, 'translated' => TRUE]);
$this->assertEqual(count($translations), 1, 'Found only Spanish and customized translations.');
// Load all source strings without translation (1).
$translations = $this->storage->getStrings(['translated' => FALSE]);
$this->assertEqual(count($translations), 1, 'Found 1 source string without translations.');
// Load Spanish translations using string filter.
$filter_options['filters'] = ['source' => $prefix];
$translations = $this->storage->getTranslations(['language' => 'es'], $filter_options);
$this->assertEqual(count($translations), 2, 'Found 2 translations using some string filter.');
}
/**
* Creates random source string object.
*
* @return \Drupal\locale\StringInterface
* A locale string.
*/
public function buildSourceString($values = []) {
return $this->storage->createString($values += [
'source' => $this->randomMachineName(100),
'context' => $this->randomMachineName(20),
]);
}
/**
* Creates translations for source string and all languages.
*/
public function createAllTranslations($source, $values = []) {
$list = [];
/* @var $language_manager \Drupal\Core\Language\LanguageManagerInterface */
$language_manager = $this->container->get('language_manager');
foreach ($language_manager->getLanguages() as $language) {
$list[$language->getId()] = $this->createTranslation($source, $language->getId(), $values);
}
return $list;
}
/**
* Creates single translation for source string.
*/
public function createTranslation($source, $langcode, $values = []) {
return $this->storage->createTranslation($values + [
'lid' => $source->lid,
'language' => $langcode,
'translation' => $this->randomMachineName(100),
])->save();
}
}

View file

@ -0,0 +1,91 @@
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
/**
* Adds and configures languages to check field schema definition.
*
* @group locale
*/
class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['language', 'locale', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->config('system.site')->set('default_langcode', 'fr')->save();
// Make sure new entity type definitions are processed.
\Drupal::service('entity.definition_update_manager')->applyUpdates();
// Clear all caches so that the base field definition, its cache in the
// entity manager, the t() cache, etc. are all cleared.
drupal_flush_all_caches();
}
/**
* Tests that translated field descriptions do not affect the update system.
*/
public function testTranslatedSchemaDefinition() {
/** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
$stringStorage = \Drupal::service('locale.storage');
$source = $stringStorage->createString([
'source' => 'Revision ID',
])->save();
$stringStorage->createTranslation([
'lid' => $source->lid,
'language' => 'fr',
'translation' => 'Translated Revision ID',
])->save();
// Ensure that the field is translated when access through the API.
$this->assertEqual('Translated Revision ID', \Drupal::entityManager()->getBaseFieldDefinitions('node')['vid']->getLabel());
// Assert there are no updates.
$this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates());
}
/**
* Tests that translations do not affect the update system.
*/
public function testTranslatedUpdate() {
// Visit the update page to collect any strings that may be translatable.
$user = $this->drupalCreateUser(['administer software updates']);
$this->drupalLogin($user);
$update_url = $GLOBALS['base_url'] . '/update.php';
$this->drupalGet($update_url, ['external' => TRUE]);
/** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
$stringStorage = \Drupal::service('locale.storage');
$sources = $stringStorage->getStrings();
// Translate all source strings found.
foreach ($sources as $source) {
$stringStorage->createTranslation([
'lid' => $source->lid,
'language' => 'fr',
'translation' => $this->randomMachineName(100),
])->save();
}
// Ensure that there are no updates just due to translations. Check for
// markup and a link instead of specific text because text may be
// translated.
$this->drupalGet($update_url . '/selection', ['external' => TRUE]);
$this->assertRaw('messages--status', 'No pending updates.');
$this->assertNoLinkByHref('fr/update.php/run', 'No link to run updates.');
}
}

View file

@ -18,7 +18,7 @@ class LocaleConfigManagerTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array('system', 'language', 'locale', 'locale_test', 'block');
public static $modules = ['system', 'language', 'locale', 'locale_test', 'block'];
/**
* This test creates simple config on the fly breaking schema checking.
@ -31,8 +31,8 @@ class LocaleConfigManagerTest extends KernelTestBase {
* Tests hasTranslation().
*/
public function testHasTranslation() {
$this->installSchema('locale', array('locales_location', 'locales_source', 'locales_target'));
$this->installConfig(array('locale_test'));
$this->installSchema('locale', ['locales_location', 'locales_source', 'locales_target']);
$this->installConfig(['locale_test']);
$locale_config_manager = \Drupal::service('locale.config_manager');
$language = ConfigurableLanguage::createFromLangcode('de');
@ -48,8 +48,8 @@ class LocaleConfigManagerTest extends KernelTestBase {
* Tests getStringTranslation().
*/
public function testGetStringTranslation() {
$this->installSchema('locale', array('locales_location', 'locales_source', 'locales_target'));
$this->installConfig(array('locale_test'));
$this->installSchema('locale', ['locales_location', 'locales_source', 'locales_target']);
$this->installConfig(['locale_test']);
$locale_config_manager = \Drupal::service('locale.config_manager');
@ -80,7 +80,7 @@ class LocaleConfigManagerTest extends KernelTestBase {
$simple_config->set('foo', 'bar')->save();
$this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode($simple_config->getName()), 'Simple config created through the API is not treated as shipped configuration.');
$block = Block::create(array(
$block = Block::create([
'id' => 'test_default_config',
'theme' => 'classy',
'status' => TRUE,
@ -94,7 +94,7 @@ class LocaleConfigManagerTest extends KernelTestBase {
'primary' => TRUE,
'secondary' => TRUE,
],
));
]);
$block->save();
// Install the theme after creating the block as installing the theme will

View file

@ -124,7 +124,7 @@ class LocaleConfigSubscriberForeignTest extends LocaleConfigSubscriberTest {
$config_name = 'locale_test.translation';
ConfigurableLanguage::createFromLangcode('en')->save();
// Adding a language on the UI would normally call updateConfigTranslations.
$this->localeConfigManager->updateConfigTranslations(array($config_name), array('en'));
$this->localeConfigManager->updateConfigTranslations([$config_name], ['en']);
$this->assertConfigOverride($config_name, 'test', 'English test', 'en');
$this->configFactory->getEditable('locale.settings')->set('translate_english', TRUE)->save();

View file

@ -182,7 +182,7 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
* The language code.
*/
protected function setUpNoTranslation($config_name, $key, $source, $langcode) {
$this->localeConfigManager->updateConfigTranslations(array($config_name), array($langcode));
$this->localeConfigManager->updateConfigTranslations([$config_name], [$langcode]);
$this->assertNoConfigOverride($config_name, $key, $source, $langcode);
$this->assertNoTranslation($config_name, $langcode);
}
@ -222,7 +222,7 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
->save();
$this->configFactory->reset($config_name);
$this->localeConfigManager->reset();
$this->localeConfigManager->updateConfigTranslations(array($config_name), array($langcode));
$this->localeConfigManager->updateConfigTranslations([$config_name], [$langcode]);
if ($is_active) {
$this->assertActiveConfig($config_name, $key, $translation, $langcode);
@ -291,7 +291,7 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
->setString($translation)
->save();
$this->localeConfigManager->reset();
$this->localeConfigManager->updateConfigTranslations(array($config_name), array($langcode));
$this->localeConfigManager->updateConfigTranslations([$config_name], [$langcode]);
$this->configFactory->reset($config_name);
if ($is_active) {
@ -356,7 +356,7 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
->getStringTranslation($config_name, $langcode, $source_value, '')
->delete();
$this->localeConfigManager->reset();
$this->localeConfigManager->updateConfigTranslations(array($config_name), array($langcode));
$this->localeConfigManager->updateConfigTranslations([$config_name], [$langcode]);
$this->configFactory->reset($config_name);
$this->assertNoConfigOverride($config_name, $key, $source_value, $langcode);

View file

@ -2,7 +2,7 @@
namespace Drupal\Tests\locale\Kernel\Migrate;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
@ -17,7 +17,7 @@ class MigrateLocaleConfigsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('locale', 'language');
public static $modules = ['locale', 'language'];
/**
* {@inheritdoc}

View file

@ -76,9 +76,9 @@ class LocaleLookupTest extends UnitTestCase {
$this->user = $this->getMock('Drupal\Core\Session\AccountInterface');
$this->user->expects($this->any())
->method('getRoles')
->will($this->returnValue(array('anonymous')));
->will($this->returnValue(['anonymous']));
$this->configFactory = $this->getConfigFactoryStub(array('locale.settings' => array('cache_strings' => FALSE)));
$this->configFactory = $this->getConfigFactoryStub(['locale.settings' => ['cache_strings' => FALSE]]);
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$this->requestStack = new RequestStack();
@ -94,15 +94,15 @@ class LocaleLookupTest extends UnitTestCase {
* @covers ::resolveCacheMiss
*/
public function testResolveCacheMissWithoutFallback() {
$args = array(
$args = [
'language' => 'en',
'source' => 'test',
'context' => 'irrelevant',
);
];
$result = (object) array(
$result = (object) [
'translation' => 'test',
);
];
$this->cache->expects($this->once())
->method('get')
@ -114,8 +114,8 @@ class LocaleLookupTest extends UnitTestCase {
->will($this->returnValue($result));
$locale_lookup = $this->getMockBuilder('Drupal\locale\LocaleLookup')
->setConstructorArgs(array('en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack))
->setMethods(array('persist'))
->setConstructorArgs(['en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack])
->setMethods(['persist'])
->getMock();
$locale_lookup->expects($this->never())
->method('persist');
@ -133,46 +133,46 @@ class LocaleLookupTest extends UnitTestCase {
*/
public function testResolveCacheMissWithFallback($langcode, $string, $context, $expected) {
// These are fake words!
$translations = array(
'en' => array(
$translations = [
'en' => [
'test' => 'test',
'fake' => 'fake',
'missing pl' => 'missing pl',
'missing cs' => 'missing cs',
'missing both' => 'missing both',
),
'pl' => array(
],
'pl' => [
'test' => 'test po polsku',
'fake' => 'ściema',
'missing cs' => 'zaginiony czech',
),
'cs' => array(
],
'cs' => [
'test' => 'test v české',
'fake' => 'falešný',
'missing pl' => 'chybějící pl',
),
);
],
];
$this->storage->expects($this->any())
->method('findTranslation')
->will($this->returnCallback(function ($argument) use ($translations) {
if (isset($translations[$argument['language']][$argument['source']])) {
return (object) array('translation' => $translations[$argument['language']][$argument['source']]);
return (object) ['translation' => $translations[$argument['language']][$argument['source']]];
}
return TRUE;
}));
$this->languageManager->expects($this->any())
->method('getFallbackCandidates')
->will($this->returnCallback(function (array $context = array()) {
->will($this->returnCallback(function (array $context = []) {
switch ($context['langcode']) {
case 'pl':
return array('cs', 'en');
return ['cs', 'en'];
case 'cs':
return array('en');
return ['en'];
default:
return array();
return [];
}
}));
@ -188,20 +188,20 @@ class LocaleLookupTest extends UnitTestCase {
* Provides test data for testResolveCacheMissWithFallback().
*/
public function resolveCacheMissWithFallbackProvider() {
return array(
array('cs', 'test', 'irrelevant', 'test v české'),
array('cs', 'fake', 'irrelevant', 'falešný'),
array('cs', 'missing pl', 'irrelevant', 'chybějící pl'),
array('cs', 'missing cs', 'irrelevant', 'missing cs'),
array('cs', 'missing both', 'irrelevant', 'missing both'),
return [
['cs', 'test', 'irrelevant', 'test v české'],
['cs', 'fake', 'irrelevant', 'falešný'],
['cs', 'missing pl', 'irrelevant', 'chybějící pl'],
['cs', 'missing cs', 'irrelevant', 'missing cs'],
['cs', 'missing both', 'irrelevant', 'missing both'],
// Testing PL with fallback to cs, en.
array('pl', 'test', 'irrelevant', 'test po polsku'),
array('pl', 'fake', 'irrelevant', 'ściema'),
array('pl', 'missing pl', 'irrelevant', 'chybějící pl'),
array('pl', 'missing cs', 'irrelevant', 'zaginiony czech'),
array('pl', 'missing both', 'irrelevant', 'missing both'),
);
['pl', 'test', 'irrelevant', 'test po polsku'],
['pl', 'fake', 'irrelevant', 'ściema'],
['pl', 'missing pl', 'irrelevant', 'chybějící pl'],
['pl', 'missing cs', 'irrelevant', 'zaginiony czech'],
['pl', 'missing both', 'irrelevant', 'missing both'],
];
}
/**
@ -210,25 +210,25 @@ class LocaleLookupTest extends UnitTestCase {
* @covers ::resolveCacheMiss
*/
public function testResolveCacheMissWithPersist() {
$args = array(
$args = [
'language' => 'en',
'source' => 'test',
'context' => 'irrelevant',
);
];
$result = (object) array(
$result = (object) [
'translation' => 'test',
);
];
$this->storage->expects($this->once())
->method('findTranslation')
->with($this->equalTo($args))
->will($this->returnValue($result));
$this->configFactory = $this->getConfigFactoryStub(array('locale.settings' => array('cache_strings' => TRUE)));
$this->configFactory = $this->getConfigFactoryStub(['locale.settings' => ['cache_strings' => TRUE]]);
$locale_lookup = $this->getMockBuilder('Drupal\locale\LocaleLookup')
->setConstructorArgs(array('en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack))
->setMethods(array('persist'))
->setConstructorArgs(['en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack])
->setMethods(['persist'])
->getMock();
$locale_lookup->expects($this->once())
->method('persist');
@ -257,8 +257,8 @@ class LocaleLookupTest extends UnitTestCase {
$this->requestStack->push($request);
$locale_lookup = $this->getMockBuilder('Drupal\locale\LocaleLookup')
->setConstructorArgs(array('en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack))
->setMethods(array('persist'))
->setConstructorArgs(['en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack])
->setMethods(['persist'])
->getMock();
$locale_lookup->expects($this->never())
->method('persist');

View file

@ -15,9 +15,9 @@ class LocaleLocalTasksTest extends LocalTaskIntegrationTestBase {
* {@inheritdoc}
*/
protected function setUp() {
$this->directoryList = array(
$this->directoryList = [
'locale' => 'core/modules/locale',
);
];
parent::setUp();
}
@ -27,9 +27,9 @@ class LocaleLocalTasksTest extends LocalTaskIntegrationTestBase {
* @dataProvider getLocalePageRoutes
*/
public function testLocalePageLocalTasks($route) {
$tasks = array(
0 => array('locale.translate_page', 'locale.translate_import', 'locale.translate_export', 'locale.settings'),
);
$tasks = [
0 => ['locale.translate_page', 'locale.translate_import', 'locale.translate_export', 'locale.settings'],
];
$this->assertLocalTasks($route, $tasks);
}
@ -37,12 +37,12 @@ class LocaleLocalTasksTest extends LocalTaskIntegrationTestBase {
* Provides a list of routes to test.
*/
public function getLocalePageRoutes() {
return array(
array('locale.translate_page'),
array('locale.translate_import'),
array('locale.translate_export'),
array('locale.settings'),
);
return [
['locale.translate_page'],
['locale.translate_import'],
['locale.translate_export'],
['locale.settings'],
];
}
}

View file

@ -3,6 +3,7 @@
namespace Drupal\Tests\locale\Unit;
use Drupal\locale\SourceString;
use Drupal\locale\StringStorageException;
use Drupal\Tests\UnitTestCase;
/**
@ -13,22 +14,20 @@ class StringBaseTest extends UnitTestCase {
/**
* @covers ::save
* @expectedException \Drupal\locale\StringStorageException
* @expectedExceptionMessage The string cannot be saved because its not bound to a storage: test
*/
public function testSaveWithoutStorage() {
$string = new SourceString(['source' => 'test']);
$this->setExpectedException(StringStorageException::class, 'The string cannot be saved because its not bound to a storage: test');
$string->save();
}
/**
* @covers ::delete
* @expectedException \Drupal\locale\StringStorageException
* @expectedExceptionMessage The string cannot be deleted because its not bound to a storage: test
*/
public function testDeleteWithoutStorage() {
$string = new SourceString(['lid' => 1, 'source' => 'test']);
$this->setExpectedException(StringStorageException::class, 'The string cannot be deleted because its not bound to a storage: test');
$string->delete();
}