Mercurial > hg > isophonics-drupal-site
comparison core/modules/locale/tests/src/Unit/LocaleLookupTest.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\Unit; | 3 namespace Drupal\Tests\locale\Unit; |
4 | 4 |
5 use Drupal\Core\DependencyInjection\ContainerBuilder; | 5 use Drupal\Core\DependencyInjection\ContainerBuilder; |
6 use Drupal\Core\StringTranslation\PluralTranslatableMarkup; | |
6 use Drupal\locale\LocaleLookup; | 7 use Drupal\locale\LocaleLookup; |
7 use Drupal\Tests\UnitTestCase; | 8 use Drupal\Tests\UnitTestCase; |
8 use Symfony\Component\HttpFoundation\Request; | 9 use Symfony\Component\HttpFoundation\Request; |
9 use Symfony\Component\HttpFoundation\RequestStack; | 10 use Symfony\Component\HttpFoundation\RequestStack; |
10 | 11 |
264 ->method('persist'); | 265 ->method('persist'); |
265 | 266 |
266 $this->assertTrue($locale_lookup->get('test')); | 267 $this->assertTrue($locale_lookup->get('test')); |
267 } | 268 } |
268 | 269 |
270 /** | |
271 * Tests locale lookups with old plural style of translations. | |
272 * | |
273 * @param array $translations | |
274 * The source with translations. | |
275 * @param string $langcode | |
276 * The language code of translation string. | |
277 * @param string $string | |
278 * The string for translation. | |
279 * @param bool $is_fix | |
280 * The flag about expected fix translation. | |
281 * | |
282 * @covers ::resolveCacheMiss | |
283 * @dataProvider providerFixOldPluralTranslationProvider | |
284 */ | |
285 public function testFixOldPluralStyleTranslations($translations, $langcode, $string, $is_fix) { | |
286 $this->storage->expects($this->any()) | |
287 ->method('findTranslation') | |
288 ->will($this->returnCallback(function ($argument) use ($translations) { | |
289 if (isset($translations[$argument['language']][$argument['source']])) { | |
290 return (object) ['translation' => $translations[$argument['language']][$argument['source']]]; | |
291 } | |
292 return TRUE; | |
293 })); | |
294 $this->languageManager->expects($this->any()) | |
295 ->method('getFallbackCandidates') | |
296 ->will($this->returnCallback(function (array $context = []) { | |
297 switch ($context['langcode']) { | |
298 case 'by': | |
299 return ['ru']; | |
300 } | |
301 })); | |
302 $this->cache->expects($this->once()) | |
303 ->method('get') | |
304 ->with('locale:' . $langcode . '::anonymous', FALSE); | |
305 | |
306 $locale_lookup = new LocaleLookup($langcode, '', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack); | |
307 $this->assertSame($is_fix, strpos($locale_lookup->get($string), '@count[2]') === FALSE); | |
308 } | |
309 | |
310 /** | |
311 * Provides test data for testResolveCacheMissWithFallback(). | |
312 */ | |
313 public function providerFixOldPluralTranslationProvider() { | |
314 $translations = [ | |
315 'by' => [ | |
316 'word1' => '@count[2] word-by', | |
317 'word2' => implode(PluralTranslatableMarkup::DELIMITER, ['word-by', '@count[2] word-by']), | |
318 ], | |
319 'ru' => [ | |
320 'word3' => '@count[2] word-ru', | |
321 'word4' => implode(PluralTranslatableMarkup::DELIMITER, ['word-ru', '@count[2] word-ru']), | |
322 ], | |
323 ]; | |
324 return [ | |
325 'no-plural' => [$translations, 'by', 'word1', FALSE], | |
326 'no-plural from other language' => [$translations, 'by', 'word3', FALSE], | |
327 'plural' => [$translations, 'by', 'word2', TRUE], | |
328 'plural from other language' => [$translations, 'by', 'word4', TRUE], | |
329 ]; | |
330 } | |
331 | |
269 } | 332 } |