function LocaleLocaleLookupTest::testFixOldPluralStyle

Same name in other branches
  1. 8.9.x core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php \Drupal\Tests\locale\Functional\LocaleLocaleLookupTest::testFixOldPluralStyle()
  2. 10 core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php \Drupal\Tests\locale\Functional\LocaleLocaleLookupTest::testFixOldPluralStyle()
  3. 11.x core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php \Drupal\Tests\locale\Functional\LocaleLocaleLookupTest::testFixOldPluralStyle()

Tests old plural style @count[number] fix.

@dataProvider providerTestFixOldPluralStyle

File

core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php, line 70

Class

LocaleLocaleLookupTest
Tests LocaleLookup.

Namespace

Drupal\Tests\locale\Functional

Code

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->assertStringContainsString('@count[2]', $translation, 'Source value contains @count[2]');
}

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