function LocaleLookupTest::testFixOldPluralStyleTranslations

Same name and namespace in other branches
  1. 8.9.x 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 290

Class

LocaleLookupTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21locale%21src%21LocaleLookup.php/class/LocaleLookup/9" title="A cache collector to allow for dynamic building of the locale cache." class="local">\Drupal\locale\LocaleLookup</a> @group locale

Namespace

Drupal\Tests\locale\Unit

Code

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));
    }
}

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