Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
52
core/modules/locale/tests/locale_test.js
Normal file
52
core/modules/locale/tests/locale_test.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @file
|
||||
* JavaScript for locale_test.module.
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
Drupal.t("Standard Call t");
|
||||
Drupal
|
||||
.
|
||||
t
|
||||
(
|
||||
"Whitespace Call t"
|
||||
)
|
||||
;
|
||||
|
||||
Drupal.t('Single Quote t');
|
||||
Drupal.t('Single Quote \'Escaped\' t');
|
||||
Drupal.t('Single Quote ' + 'Concat ' + 'strings ' + 't');
|
||||
|
||||
Drupal.t("Double Quote t");
|
||||
Drupal.t("Double Quote \"Escaped\" t");
|
||||
Drupal.t("Double Quote " + "Concat " + "strings " + "t");
|
||||
|
||||
Drupal.t("Context Unquoted t", {}, {context: "Context string unquoted"});
|
||||
Drupal.t("Context Single Quoted t", {}, {'context': "Context string single quoted"});
|
||||
Drupal.t("Context Double Quoted t", {}, {"context": "Context string double quoted"});
|
||||
|
||||
Drupal.t("Context !key Args t", {'!key': 'value'}, {context: "Context string"});
|
||||
|
||||
Drupal.formatPlural(1, "Standard Call plural", "Standard Call @count plural");
|
||||
Drupal
|
||||
.
|
||||
formatPlural
|
||||
(
|
||||
1,
|
||||
"Whitespace Call plural",
|
||||
"Whitespace Call @count plural"
|
||||
)
|
||||
;
|
||||
|
||||
Drupal.formatPlural(1, 'Single Quote plural', 'Single Quote @count plural');
|
||||
Drupal.formatPlural(1, 'Single Quote \'Escaped\' plural', 'Single Quote \'Escaped\' @count plural');
|
||||
|
||||
Drupal.formatPlural(1, "Double Quote plural", "Double Quote @count plural");
|
||||
Drupal.formatPlural(1, "Double Quote \"Escaped\" plural", "Double Quote \"Escaped\" @count plural");
|
||||
|
||||
Drupal.formatPlural(1, "Context Unquoted plural", "Context Unquoted @count plural", {}, {context: "Context string unquoted"});
|
||||
Drupal.formatPlural(1, "Context Single Quoted plural", "Context Single Quoted @count plural", {}, {'context': "Context string single quoted"});
|
||||
Drupal.formatPlural(1, "Context Double Quoted plural", "Context Double Quoted @count plural", {}, {"context": "Context string double quoted"});
|
||||
|
||||
Drupal.formatPlural(1, "Context !key Args plural", "Context !key Args @count plural", {'!key': 'value'}, {context: "Context string"});
|
|
@ -0,0 +1,7 @@
|
|||
name: 'Early translation test'
|
||||
type: module
|
||||
description: 'Support module for testing early bootstrap getting of annotations with translations.'
|
||||
core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
services:
|
||||
early_translation_test.authentication.early_translation_test:
|
||||
class: Drupal\early_translation_test\Auth
|
||||
arguments: ['@entity.manager']
|
||||
tags:
|
||||
- { name: authentication_provider, provider_id: 'early_translation_test', priority: 100 }
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\early_translation_test\Auth.
|
||||
*/
|
||||
|
||||
namespace Drupal\early_translation_test;
|
||||
|
||||
use Drupal\Core\Authentication\AuthenticationProviderInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Test authentication provider.
|
||||
*/
|
||||
class Auth implements AuthenticationProviderInterface {
|
||||
|
||||
/**
|
||||
* The user storage.
|
||||
*
|
||||
* @var \Drupal\user\UserStorageInterface
|
||||
*/
|
||||
protected $userStorage;
|
||||
|
||||
/**
|
||||
* Constructs an authentication provider object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager service.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager) {
|
||||
// Authentication providers are called early during in the bootstrap.
|
||||
// Getting the user storage used to result in a circular reference since
|
||||
// translation involves a call to \Drupal\locale\LocaleLookup that tries to
|
||||
// get the user roles.
|
||||
// @see https://www.drupal.org/node/2241461
|
||||
$this->userStorage = $entity_manager->getStorage('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applies(Request $request) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(Request $request) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
test: German test
|
|
@ -0,0 +1 @@
|
|||
test: Test
|
|
@ -0,0 +1 @@
|
|||
test: English test
|
|
@ -0,0 +1,21 @@
|
|||
# Schema for the configuration files of the Locale Test module.
|
||||
|
||||
locale_test.no_translation:
|
||||
type: config_object
|
||||
label: 'No traslation settings'
|
||||
mapping:
|
||||
test:
|
||||
type: string
|
||||
label: 'Test'
|
||||
# See \Drupal\locale\Tests\LocaleConfigSubscriberTest
|
||||
translatable: true
|
||||
|
||||
locale_test.translation:
|
||||
type: config_object
|
||||
label: 'translation settings'
|
||||
mapping:
|
||||
test:
|
||||
type: string
|
||||
label: 'Test'
|
||||
# See \Drupal\locale\Tests\LocaleConfigSubscriberTest
|
||||
translatable: true
|
|
@ -0,0 +1,9 @@
|
|||
name: 'Locale test'
|
||||
type: module
|
||||
description: 'Support module for locale module testing.'
|
||||
package: Testing
|
||||
version: '1.2'
|
||||
core: 8.x
|
||||
hidden: true
|
||||
'interface translation project': locale_test
|
||||
'interface translation server pattern': core/modules/locale/test/test.%language.po
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the locale_test module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function locale_test_uninstall() {
|
||||
// Clear variables.
|
||||
\Drupal::state()->delete('locale.test_system_info_alter');
|
||||
\Drupal::state()->delete('locale.test_projects_alter');
|
||||
}
|
144
core/modules/locale/tests/modules/locale_test/locale_test.module
Normal file
144
core/modules/locale/tests/modules/locale_test/locale_test.module
Normal file
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Simulate a custom module with a local po file.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Extension\Extension;
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
|
||||
/**
|
||||
* Implements hook_system_info_alter().
|
||||
*
|
||||
* Make the test scripts to be believe this is not a hidden test module, but
|
||||
* a regular custom module.
|
||||
*/
|
||||
function locale_test_system_info_alter(&$info, Extension $file, $type) {
|
||||
// Only modify the system info if required.
|
||||
// By default the locale_test modules are hidden and have a project specified.
|
||||
// To test the module detection process by locale_project_list() the
|
||||
// test modules should mimic a custom module. I.e. be non-hidden.
|
||||
if (\Drupal::state()->get('locale.test_system_info_alter')) {
|
||||
if ($file->getName() == 'locale_test' || $file->getName() == 'locale_test_translate') {
|
||||
// Don't hide the module.
|
||||
$info['hidden'] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_locale_translation_projects_alter().
|
||||
*
|
||||
* The translation status process by default checks the status of the installed
|
||||
* projects. This function replaces the data of the installed modules by a
|
||||
* predefined set of modules with fixed file names and release versions. Project
|
||||
* names, versions, timestamps etc must be fixed because they must match the
|
||||
* files created by the test script.
|
||||
*
|
||||
* The "locale.test_projects_alter" state variable must be set by the
|
||||
* test script in order for this hook to take effect.
|
||||
*/
|
||||
function locale_test_locale_translation_projects_alter(&$projects) {
|
||||
// Drupal core should not be translated. By overriding the server pattern we
|
||||
// make sure that no translation for drupal core will be found and that the
|
||||
// translation update system will not go out to l.d.o to check.
|
||||
$projects['drupal']['server_pattern'] = 'translations://';
|
||||
|
||||
if (\Drupal::state()->get('locale.test_projects_alter')) {
|
||||
|
||||
// Instead of the default ftp.drupal.org we use the file system of the test
|
||||
// instance to simulate a remote file location.
|
||||
$url = \Drupal::url('<front>', [], ['absolute' => TRUE]);
|
||||
$remote_url = $url . PublicStream::basePath() . '/remote/';
|
||||
|
||||
// Completely replace the project data with a set of test projects.
|
||||
$projects = array(
|
||||
'contrib_module_one' => array(
|
||||
'name' => 'contrib_module_one',
|
||||
'info' => array(
|
||||
'name' => 'Contributed module one',
|
||||
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
|
||||
'package' => 'Other',
|
||||
'version' => '8.x-1.1',
|
||||
'project' => 'contrib_module_one',
|
||||
'datestamp' => '1344471537',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
),
|
||||
'datestamp' => '1344471537',
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
'contrib_module_two' => array(
|
||||
'name' => 'contrib_module_two',
|
||||
'info' => array(
|
||||
'name' => 'Contributed module two',
|
||||
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
|
||||
'package' => 'Other',
|
||||
'version' => '8.x-2.0-beta4',
|
||||
'project' => 'contrib_module_two',
|
||||
'datestamp' => '1344471537',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
),
|
||||
'datestamp' => '1344471537',
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
'contrib_module_three' => array(
|
||||
'name' => 'contrib_module_three',
|
||||
'info' => array(
|
||||
'name' => 'Contributed module three',
|
||||
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
|
||||
'package' => 'Other',
|
||||
'version' => '8.x-1.0',
|
||||
'project' => 'contrib_module_three',
|
||||
'datestamp' => '1344471537',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
),
|
||||
'datestamp' => '1344471537',
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
'locale_test' => array(
|
||||
'name' => 'locale_test',
|
||||
'info' => array(
|
||||
'name' => 'Locale test',
|
||||
'interface translation project' => 'locale_test',
|
||||
'interface translation server pattern' => 'core/modules/locale/tests/test.%language.po',
|
||||
'package' => 'Other',
|
||||
'version' => NULL,
|
||||
'project' => 'locale_test',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
'datestamp' => 0,
|
||||
),
|
||||
'datestamp' => 0,
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
'custom_module_one' => array(
|
||||
'name' => 'custom_module_one',
|
||||
'info' => array(
|
||||
'name' => 'Custom module one',
|
||||
'interface translation project' => 'custom_module_one',
|
||||
'interface translation server pattern' => 'translations://custom_module_one.%language.po',
|
||||
'package' => 'Other',
|
||||
'version' => NULL,
|
||||
'project' => 'custom_module_one',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
'datestamp' => 0,
|
||||
),
|
||||
'datestamp' => 0,
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_language_fallback_candidates_OPERATION_alter().
|
||||
*/
|
||||
function locale_test_language_fallback_candidates_locale_lookup_alter(array &$candidates, array $context) {
|
||||
\Drupal::state()->set('locale.test_language_fallback_candidates_locale_lookup_alter_candidates', $candidates);
|
||||
\Drupal::state()->set('locale.test_language_fallback_candidates_locale_lookup_alter_context', $context);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
name: 'Locale Test Not Development Release'
|
||||
type: module
|
||||
description: 'The first release with the same major release number which is not a development release.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
hidden: true
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Simulate a Drupal version.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Extension\Extension;
|
||||
|
||||
/**
|
||||
* Implements hook_system_info_alter().
|
||||
*
|
||||
* Change the core version number to a development one for testing.
|
||||
* 8.0.0-alpha102-dev is the simulated version.
|
||||
*/
|
||||
function locale_test_not_development_release_system_info_alter(&$info, Extension $file, $type) {
|
||||
if (isset($info['package']) && $info['package'] == 'Core') {
|
||||
$info['version'] = '8.0.0-alpha102-dev';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name: 'Locale test translate'
|
||||
type: module
|
||||
description: 'Translation test module for locale module testing.'
|
||||
package: Testing
|
||||
version: '1.3'
|
||||
core: 8.x
|
||||
hidden: true
|
||||
'interface translation project': locale_test_translate
|
||||
'interface translation server pattern': core/modules/locale/tests/test.%language.po
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Simulates a custom module with a local po file.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Extension\Extension;
|
||||
|
||||
/**
|
||||
* Implements hook_system_info_alter().
|
||||
*
|
||||
* By default this modules is hidden but once enabled it behaves like a normal
|
||||
* (not hidden) module. This hook implementation changes the .info.yml data by
|
||||
* setting the hidden status to FALSE.
|
||||
*/
|
||||
function locale_test_translate_system_info_alter(&$info, Extension $file, $type) {
|
||||
if ($file->getName() == 'locale_test_translate') {
|
||||
// Don't hide the module.
|
||||
$info['hidden'] = FALSE;
|
||||
}
|
||||
}
|
274
core/modules/locale/tests/src/Unit/LocaleLookupTest.php
Normal file
274
core/modules/locale/tests/src/Unit/LocaleLookupTest.php
Normal file
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\locale\Unit\LocaleLookupTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\locale\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\locale\LocaleLookup;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\locale\LocaleLookup
|
||||
* @group locale
|
||||
*/
|
||||
class LocaleLookupTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* A mocked storage to use when instantiating LocaleTranslation objects.
|
||||
*
|
||||
* @var \Drupal\locale\StringStorageInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* A mocked cache object.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* A mocked lock object.
|
||||
*
|
||||
* @var \Drupal\Core\Lock\LockBackendInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $lock;
|
||||
|
||||
/**
|
||||
* A mocked user object built from AccountInterface.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* A mocked config factory built with UnitTestCase::getConfigFactoryStub().
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockBuilder
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* A mocked language manager built from LanguageManagerInterface.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The request stack.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->storage = $this->getMock('Drupal\locale\StringStorageInterface');
|
||||
$this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
|
||||
$this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface');
|
||||
$this->lock->expects($this->never())
|
||||
->method($this->anything());
|
||||
|
||||
$this->user = $this->getMock('Drupal\Core\Session\AccountInterface');
|
||||
$this->user->expects($this->any())
|
||||
->method('getRoles')
|
||||
->will($this->returnValue(array('anonymous')));
|
||||
|
||||
$this->configFactory = $this->getConfigFactoryStub(array('locale.settings' => array('cache_strings' => FALSE)));
|
||||
|
||||
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
$this->requestStack = new RequestStack();
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('current_user', $this->user);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests locale lookups without fallback.
|
||||
*
|
||||
* @covers ::resolveCacheMiss
|
||||
*/
|
||||
public function testResolveCacheMissWithoutFallback() {
|
||||
$args = array(
|
||||
'language' => 'en',
|
||||
'source' => 'test',
|
||||
'context' => 'irrelevant',
|
||||
);
|
||||
|
||||
$result = (object) array(
|
||||
'translation' => 'test',
|
||||
);
|
||||
|
||||
$this->cache->expects($this->once())
|
||||
->method('get')
|
||||
->with('locale:en:irrelevant:0', FALSE);
|
||||
|
||||
$this->storage->expects($this->once())
|
||||
->method('findTranslation')
|
||||
->with($this->equalTo($args))
|
||||
->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'))
|
||||
->getMock();
|
||||
$locale_lookup->expects($this->never())
|
||||
->method('persist');
|
||||
$this->assertSame('test', $locale_lookup->get('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests locale lookups with fallback.
|
||||
*
|
||||
* Note that context is irrelevant here. It is not used but it is required.
|
||||
*
|
||||
* @covers ::resolveCacheMiss
|
||||
*
|
||||
* @dataProvider resolveCacheMissWithFallbackProvider
|
||||
*/
|
||||
public function testResolveCacheMissWithFallback($langcode, $string, $context, $expected) {
|
||||
// These are fake words!
|
||||
$translations = array(
|
||||
'en' => array(
|
||||
'test' => 'test',
|
||||
'fake' => 'fake',
|
||||
'missing pl' => 'missing pl',
|
||||
'missing cs' => 'missing cs',
|
||||
'missing both' => 'missing both',
|
||||
),
|
||||
'pl' => array(
|
||||
'test' => 'test po polsku',
|
||||
'fake' => 'ściema',
|
||||
'missing cs' => 'zaginiony czech',
|
||||
),
|
||||
'cs' => array(
|
||||
'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 TRUE;
|
||||
}));
|
||||
|
||||
$this->languageManager->expects($this->any())
|
||||
->method('getFallbackCandidates')
|
||||
->will($this->returnCallback(function (array $context = array()) {
|
||||
switch ($context['langcode']) {
|
||||
case 'pl':
|
||||
return array('cs', 'en');
|
||||
|
||||
case 'cs':
|
||||
return array('en');
|
||||
|
||||
default:
|
||||
return array();
|
||||
}
|
||||
}));
|
||||
|
||||
$this->cache->expects($this->once())
|
||||
->method('get')
|
||||
->with('locale:' . $langcode . ':' . $context . ':0', FALSE);
|
||||
|
||||
$locale_lookup = new LocaleLookup($langcode, $context, $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack);
|
||||
$this->assertSame($expected, $locale_lookup->get($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'),
|
||||
|
||||
// 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'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests locale lookups with persistent tracking.
|
||||
*
|
||||
* @covers ::resolveCacheMiss
|
||||
*/
|
||||
public function testResolveCacheMissWithPersist() {
|
||||
$args = array(
|
||||
'language' => 'en',
|
||||
'source' => 'test',
|
||||
'context' => 'irrelevant',
|
||||
);
|
||||
|
||||
$result = (object) array(
|
||||
'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)));
|
||||
$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'))
|
||||
->getMock();
|
||||
$locale_lookup->expects($this->once())
|
||||
->method('persist');
|
||||
|
||||
$this->assertSame('test', $locale_lookup->get('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests locale lookups without a found translation.
|
||||
*
|
||||
* @covers ::resolveCacheMiss
|
||||
*/
|
||||
public function testResolveCacheMissNoTranslation() {
|
||||
$string = $this->getMock('Drupal\locale\StringInterface');
|
||||
$string->expects($this->once())
|
||||
->method('addLocation')
|
||||
->will($this->returnSelf());
|
||||
$this->storage->expects($this->once())
|
||||
->method('findTranslation')
|
||||
->will($this->returnValue(NULL));
|
||||
$this->storage->expects($this->once())
|
||||
->method('createString')
|
||||
->will($this->returnValue($string));
|
||||
|
||||
$request = Request::create('/test');
|
||||
$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'))
|
||||
->getMock();
|
||||
$locale_lookup->expects($this->never())
|
||||
->method('persist');
|
||||
|
||||
$this->assertTrue($locale_lookup->get('test'));
|
||||
}
|
||||
|
||||
}
|
62
core/modules/locale/tests/src/Unit/LocaleTranslationTest.php
Normal file
62
core/modules/locale/tests/src/Unit/LocaleTranslationTest.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\locale\Unit\LocaleTranslationTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\locale\Unit;
|
||||
|
||||
use Drupal\locale\LocaleTranslation;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\locale\LocaleTranslation
|
||||
* @group locale
|
||||
*/
|
||||
class LocaleTranslationTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* A mocked storage to use when instantiating LocaleTranslation objects.
|
||||
*
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* A mocked language manager built from LanguageManagerInterface.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The request stack.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->storage = $this->getMock('Drupal\locale\StringStorageInterface');
|
||||
$this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
|
||||
$this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface');
|
||||
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
$this->requestStack = new RequestStack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for \Drupal\locale\LocaleTranslation::destruct().
|
||||
*/
|
||||
public function testDestruct() {
|
||||
$translation = new LocaleTranslation($this->storage, $this->cache, $this->lock, $this->getConfigFactoryStub(), $this->languageManager, $this->requestStack);
|
||||
// Prove that destruction works without errors when translations are empty.
|
||||
$this->assertAttributeEmpty('translations', $translation);
|
||||
$translation->destruct();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\locale\Unit\Menu\LocaleLocalTasksTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\locale\Unit\Menu;
|
||||
|
||||
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
|
||||
|
||||
/**
|
||||
* Tests locale local tasks.
|
||||
*
|
||||
* @group locale
|
||||
*/
|
||||
class LocaleLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->directoryList = array(
|
||||
'locale' => 'core/modules/locale',
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks locale listing local tasks.
|
||||
*
|
||||
* @dataProvider getLocalePageRoutes
|
||||
*/
|
||||
public function testLocalePageLocalTasks($route) {
|
||||
$tasks = array(
|
||||
0 => array('locale.translate_page', 'locale.translate_import', 'locale.translate_export','locale.settings'),
|
||||
);
|
||||
$this->assertLocalTasks($route, $tasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
39
core/modules/locale/tests/src/Unit/StringBaseTest.php
Normal file
39
core/modules/locale/tests/src/Unit/StringBaseTest.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\locale\Unit\StringBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\locale\Unit;
|
||||
|
||||
use Drupal\locale\SourceString;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\locale\StringBase
|
||||
* @group locale
|
||||
*/
|
||||
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']);
|
||||
$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']);
|
||||
$string->delete();
|
||||
}
|
||||
|
||||
}
|
10
core/modules/locale/tests/test.af.po
Normal file
10
core/modules/locale/tests/test.af.po
Normal file
|
@ -0,0 +1,10 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Drupal 8\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
|
||||
|
||||
msgid "@site is currently under maintenance. We should be back shortly. Thank you for your patience."
|
||||
msgstr "Ons is tans besig met onderhoud op @site. Wees asseblief geduldig, ons sal binnekort weer terug wees."
|
28
core/modules/locale/tests/test.de.po
Normal file
28
core/modules/locale/tests/test.de.po
Normal file
|
@ -0,0 +1,28 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Drupal 7\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
|
||||
|
||||
msgid "Monday"
|
||||
msgstr "Montag"
|
||||
|
||||
msgid "Tuesday"
|
||||
msgstr "Dienstag"
|
||||
|
||||
msgid "Wednesday"
|
||||
msgstr "Mittwoch"
|
||||
|
||||
msgid "Thursday"
|
||||
msgstr "Donnerstag"
|
||||
|
||||
msgid "Friday"
|
||||
msgstr "Freitag"
|
||||
|
||||
msgid "Saturday"
|
||||
msgstr "Samstag"
|
||||
|
||||
msgid "Sunday"
|
||||
msgstr "Sonntag"
|
31
core/modules/locale/tests/test.nl.po
Normal file
31
core/modules/locale/tests/test.nl.po
Normal file
|
@ -0,0 +1,31 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Drupal 7\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
|
||||
|
||||
msgid "Monday"
|
||||
msgstr "maandag"
|
||||
|
||||
msgid "Tuesday"
|
||||
msgstr "dinsdag"
|
||||
|
||||
msgid "Wednesday"
|
||||
msgstr "woensdag"
|
||||
|
||||
msgid "Thursday"
|
||||
msgstr "donderdag"
|
||||
|
||||
msgid "Extraday"
|
||||
msgstr "extra dag"
|
||||
|
||||
msgid "Friday"
|
||||
msgstr "vrijdag"
|
||||
|
||||
msgid "Saturday"
|
||||
msgstr "zaterdag"
|
||||
|
||||
msgid "Sunday"
|
||||
msgstr "zondag"
|
40
core/modules/locale/tests/test.xx.po
Normal file
40
core/modules/locale/tests/test.xx.po
Normal file
|
@ -0,0 +1,40 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Drupal 7\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
|
||||
|
||||
msgid "Monday"
|
||||
msgstr "lundi"
|
||||
|
||||
msgid "Tuesday"
|
||||
msgstr "mardi"
|
||||
|
||||
msgid "Wednesday"
|
||||
msgstr "mercredi"
|
||||
|
||||
msgid "Thursday"
|
||||
msgstr "jeudi"
|
||||
|
||||
msgid "Friday"
|
||||
msgstr "vendredi"
|
||||
|
||||
msgid "Saturday"
|
||||
msgstr "samedi"
|
||||
|
||||
msgid "Sunday"
|
||||
msgstr "dimanche"
|
||||
|
||||
msgid "Allowed HTML source string"
|
||||
msgstr "<strong>Allowed HTML translation string</strong>"
|
||||
|
||||
msgid "Another allowed HTML source string"
|
||||
msgstr "<script>Disallowed HTML translation string</script>"
|
||||
|
||||
msgid "Source string for multiline translation"
|
||||
msgstr ""
|
||||
"Multiline translation string "
|
||||
"to make sure that "
|
||||
"import works with it."
|
Reference in a new issue