Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Tests\locale\Functional; | 3 namespace Drupal\Tests\locale\Functional; |
4 | 4 |
5 use Drupal\Core\StringTranslation\PluralTranslatableMarkup; | |
5 use Drupal\language\Entity\ConfigurableLanguage; | 6 use Drupal\language\Entity\ConfigurableLanguage; |
6 use Drupal\Tests\BrowserTestBase; | 7 use Drupal\Tests\BrowserTestBase; |
7 | 8 |
8 /** | 9 /** |
9 * Tests LocaleLookup. | 10 * Tests LocaleLookup. |
53 $context = \Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_context'); | 54 $context = \Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_context'); |
54 $this->assertEqual($context['langcode'], 'fr'); | 55 $this->assertEqual($context['langcode'], 'fr'); |
55 $this->assertEqual($context['operation'], 'locale_lookup'); | 56 $this->assertEqual($context['operation'], 'locale_lookup'); |
56 } | 57 } |
57 | 58 |
59 /** | |
60 * Test old plural style @count[number] fix. | |
61 * | |
62 * @dataProvider providerTestFixOldPluralStyle | |
63 */ | |
64 public function testFixOldPluralStyle($translation_value, $expected) { | |
65 $string_storage = \Drupal::service('locale.storage'); | |
66 $string = $string_storage->findString(['source' => 'Member for', 'context' => '']); | |
67 $lid = $string->getId(); | |
68 $string_storage->createTranslation([ | |
69 'lid' => $lid, | |
70 'language' => 'fr', | |
71 'translation' => $translation_value, | |
72 ])->save(); | |
73 _locale_refresh_translations(['fr'], [$lid]); | |
74 | |
75 // Check that 'count[2]' was fixed for render value. | |
76 $this->drupalGet(''); | |
77 $this->assertSession()->pageTextContains($expected); | |
78 | |
79 // Check that 'count[2]' was saved for source value. | |
80 $translation = $string_storage->findTranslation(['language' => 'fr', 'lid' => $lid])->translation; | |
81 $this->assertSame($translation_value, $translation, 'Source value not changed'); | |
82 $this->assertNotFalse(strpos($translation, '@count[2]'), 'Source value contains @count[2]'); | |
83 } | |
84 | |
85 /** | |
86 * Provides data for testFixOldPluralStyle(). | |
87 * | |
88 * @return array | |
89 * An array of test data: | |
90 * - translation value | |
91 * - expected result | |
92 */ | |
93 public function providerTestFixOldPluralStyle() { | |
94 return [ | |
95 'non-plural translation' => ['@count[2] non-plural test', '@count[2] non-plural test'], | |
96 'plural translation' => ['@count[2] plural test' . PluralTranslatableMarkup::DELIMITER, '@count plural test'], | |
97 ]; | |
98 } | |
99 | |
58 } | 100 } |