diff --git a/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php b/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php index 27bae5e2da..0938895083 100644 --- a/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php @@ -2,9 +2,9 @@ namespace Drupal\Tests\locale\Functional; +use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\Core\Cache\CacheCollectorHelper; /** * Tests LocaleLookup. @@ -56,4 +56,46 @@ public function testLanguageFallbackDefaults() { $this->assertEqual($context['operation'], 'locale_lookup'); } + /** + * Test old plural style @count[number] fix. + * + * @dataProvider providerTestFixOldPluralStyle + */ + public function testFixOldPluralStyle($translation_value, $expected) { + /** @var \Drupal\locale\StringDatabaseStorage $string_storage */ + $string_storage = \Drupal::service('locale.storage'); + + $string = $string_storage->findString(['source' => 'Member for', 'context' => '']); + + // Create translation with old @count[2] plural style. + $string_storage->createTranslation([ + 'lid' => $string->getId(), + 'language' => 'fr', + 'translation' => $translation_value, + ])->save(); + + drupal_flush_all_caches(); + $this->drupalGet(''); + $this->assertSession()->pageTextContains($expected); + + // Assert that source not changed. + $translation = $string_storage->findTranslation(['language' => 'fr', 'lid' => $string->getId()])->translation; + $this->assertSame($translation_value, $translation); + } + + /** + * 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'], + ]; + } + }