diff core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children af1871eacc83
line wrap: on
line diff
--- a/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php	Fri Feb 23 15:51:18 2018 +0000
+++ b/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php	Fri Feb 23 15:52:07 2018 +0000
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\locale\Functional;
 
+use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
 use Drupal\language\Entity\ConfigurableLanguage;
 use Drupal\Tests\BrowserTestBase;
 
@@ -55,4 +56,45 @@
     $this->assertEqual($context['operation'], 'locale_lookup');
   }
 
+  /**
+   * Test old plural style @count[number] fix.
+   *
+   * @dataProvider providerTestFixOldPluralStyle
+   */
+  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->assertNotFalse(strpos($translation, '@count[2]'), 'Source value contains @count[2]');
+  }
+
+  /**
+   * 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'],
+    ];
+  }
+
 }