updated core
This commit is contained in:
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -8,8 +8,8 @@ hidden: true
|
||||
'interface translation project': locale_test
|
||||
'interface translation server pattern': core/modules/locale/test/test.%language.po
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
# core: 8.x
|
||||
hidden: true
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
+3
-3
@@ -8,8 +8,8 @@ hidden: true
|
||||
'interface translation project': locale_test_translate
|
||||
'interface translation server pattern': core/modules/locale/tests/test.%language.po
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -21,7 +21,7 @@ class LocaleFileSystemFormTest extends BrowserTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(){
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$account = $this->drupalCreateUser(['administer site configuration']);
|
||||
$this->drupalLogin($account);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\locale\Functional;
|
||||
|
||||
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
@@ -55,4 +56,45 @@ class LocaleLocaleLookupTest extends BrowserTestBase {
|
||||
$this->assertEqual($context['operation'], 'locale_lookup');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test old plural style @count[number] fix.
|
||||
*
|
||||
* @dataProvider providerTestFixOldPluralStyle
|
||||
*/
|
||||
public function testFixOldPluralStyle($translation_value, $expected) {
|
||||
$string_storage = \Drupal::service('locale.storage');
|
||||
$string = $string_storage->findString(['source' => 'Member for', 'context' => '']);
|
||||
$lid = $string->getId();
|
||||
$string_storage->createTranslation([
|
||||
'lid' => $lid,
|
||||
'language' => 'fr',
|
||||
'translation' => $translation_value,
|
||||
])->save();
|
||||
_locale_refresh_translations(['fr'], [$lid]);
|
||||
|
||||
// Check that 'count[2]' was fixed for render value.
|
||||
$this->drupalGet('');
|
||||
$this->assertSession()->pageTextContains($expected);
|
||||
|
||||
// Check that 'count[2]' was saved for source value.
|
||||
$translation = $string_storage->findTranslation(['language' => 'fr', 'lid' => $lid])->translation;
|
||||
$this->assertSame($translation_value, $translation, 'Source value not changed');
|
||||
$this->assertNotFalse(strpos($translation, '@count[2]'), 'Source value contains @count[2]');
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for testFixOldPluralStyle().
|
||||
*
|
||||
* @return array
|
||||
* An array of test data:
|
||||
* - translation value
|
||||
* - expected result
|
||||
*/
|
||||
public function providerTestFixOldPluralStyle() {
|
||||
return [
|
||||
'non-plural translation' => ['@count[2] non-plural test', '@count[2] non-plural test'],
|
||||
'plural translation' => ['@count[2] plural test' . PluralTranslatableMarkup::DELIMITER, '@count plural test'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\Tests\locale\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
|
||||
use Drupal\locale\LocaleLookup;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -266,4 +267,66 @@ class LocaleLookupTest extends UnitTestCase {
|
||||
$this->assertTrue($locale_lookup->get('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests locale lookups with old plural style of translations.
|
||||
*
|
||||
* @param array $translations
|
||||
* The source with translations.
|
||||
* @param string $langcode
|
||||
* The language code of translation string.
|
||||
* @param string $string
|
||||
* The string for translation.
|
||||
* @param bool $is_fix
|
||||
* The flag about expected fix translation.
|
||||
*
|
||||
* @covers ::resolveCacheMiss
|
||||
* @dataProvider providerFixOldPluralTranslationProvider
|
||||
*/
|
||||
public function testFixOldPluralStyleTranslations($translations, $langcode, $string, $is_fix) {
|
||||
$this->storage->expects($this->any())
|
||||
->method('findTranslation')
|
||||
->will($this->returnCallback(function ($argument) use ($translations) {
|
||||
if (isset($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 = []) {
|
||||
switch ($context['langcode']) {
|
||||
case 'by':
|
||||
return ['ru'];
|
||||
}
|
||||
}));
|
||||
$this->cache->expects($this->once())
|
||||
->method('get')
|
||||
->with('locale:' . $langcode . '::anonymous', FALSE);
|
||||
|
||||
$locale_lookup = new LocaleLookup($langcode, '', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack);
|
||||
$this->assertSame($is_fix, strpos($locale_lookup->get($string), '@count[2]') === FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for testResolveCacheMissWithFallback().
|
||||
*/
|
||||
public function providerFixOldPluralTranslationProvider() {
|
||||
$translations = [
|
||||
'by' => [
|
||||
'word1' => '@count[2] word-by',
|
||||
'word2' => implode(PluralTranslatableMarkup::DELIMITER, ['word-by', '@count[2] word-by']),
|
||||
],
|
||||
'ru' => [
|
||||
'word3' => '@count[2] word-ru',
|
||||
'word4' => implode(PluralTranslatableMarkup::DELIMITER, ['word-ru', '@count[2] word-ru']),
|
||||
],
|
||||
];
|
||||
return [
|
||||
'no-plural' => [$translations, 'by', 'word1', FALSE],
|
||||
'no-plural from other language' => [$translations, 'by', 'word3', FALSE],
|
||||
'plural' => [$translations, 'by', 'word2', TRUE],
|
||||
'plural from other language' => [$translations, 'by', 'word4', TRUE],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user