function LocaleLookupTest::testFixOldPluralStyleTranslations

Same name in other branches
  1. 9 core/modules/locale/tests/src/Unit/LocaleLookupTest.php \Drupal\Tests\locale\Unit\LocaleLookupTest::testFixOldPluralStyleTranslations()
  2. 10 core/modules/locale/tests/src/Unit/LocaleLookupTest.php \Drupal\Tests\locale\Unit\LocaleLookupTest::testFixOldPluralStyleTranslations()
  3. 11.x 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 285

Class

LocaleLookupTest
@coversDefaultClass \Drupal\locale\LocaleLookup @group locale

Namespace

Drupal\Tests\locale\Unit

Code

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);
    if ($is_fix) {
        $this->assertStringNotContainsString('@count[2]', $locale_lookup->get($string));
    }
    else {
        $this->assertStringContainsString('@count[2]', $locale_lookup->get($string));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.