public function LocaleLookupTest::testFixOldPluralStyleTranslations in Drupal 9
Same name and namespace in other branches
- 8 core/modules/locale/tests/src/Unit/LocaleLookupTest.php \Drupal\Tests\locale\Unit\LocaleLookupTest::testFixOldPluralStyleTranslations()
Tests locale lookups with old plural style of translations.
@covers ::resolveCacheMiss @dataProvider providerFixOldPluralTranslationProvider
Parameters
array $translations: The source with translations.
string $langcode: The language code of translation string.
string $string: The string for translation.
bool $is_fix: The flag about expected fix translation.
File
- core/
modules/ locale/ tests/ src/ Unit/ LocaleLookupTest.php, line 290
Class
- LocaleLookupTest
- @coversDefaultClass \Drupal\locale\LocaleLookup @group locale
Namespace
Drupal\Tests\locale\UnitCode
public function testFixOldPluralStyleTranslations($translations, $langcode, $string, $is_fix) {
$this->storage
->expects($this
->any())
->method('findTranslation')
->willReturnCallback(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')
->willReturnCallback(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);
if ($is_fix) {
$this
->assertStringNotContainsString('@count[2]', $locale_lookup
->get($string));
}
else {
$this
->assertStringContainsString('@count[2]', $locale_lookup
->get($string));
}
}