Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2774f77

Browse filesBrowse files
author
Yoann MOROCUTTI
committed
[ticket_43363] Test that default locale is correcly used within the pull command
1 parent ae262cf commit 2774f77
Copy full SHA for 2774f77

File tree

Expand file treeCollapse file tree

1 file changed

+78
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+78
-2
lines changed

‎src/Symfony/Component/Translation/Tests/Command/TranslationPullCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Command/TranslationPullCommandTest.php
+78-2Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,83 @@ public function testPullForceIntlIcuMessages()
348348
, file_get_contents($filenameFr));
349349
}
350350

351-
private function createCommandTester(ProviderInterface $provider, array $locales = ['en'], array $domains = ['messages']): CommandTester
351+
public function testPullMessagesWithDefaultLocale()
352+
{
353+
$arrayLoader = new ArrayLoader();
354+
$filenameFr = $this->createFile(['note' => 'NOTE'], 'fr');
355+
$filenameEn = $this->createFile(['note' => 'NOTE']);
356+
$locales = ['en', 'fr'];
357+
$domains = ['messages'];
358+
359+
$providerReadTranslatorBag = new TranslatorBag();
360+
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
361+
'note' => 'NOTE',
362+
'new.foo' => 'nouveauFoo',
363+
], 'fr'));
364+
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
365+
'note' => 'NOTE',
366+
'new.foo' => 'newFoo',
367+
], 'en'));
368+
369+
$provider = $this->createMock(ProviderInterface::class);
370+
$provider->expects($this->once())
371+
->method('read')
372+
->with($domains, $locales)
373+
->willReturn($providerReadTranslatorBag);
374+
375+
$provider->expects($this->once())
376+
->method('__toString')
377+
->willReturn('null://default');
378+
379+
$tester = $this->createCommandTester($provider, $locales, $domains, 'fr');
380+
$tester->execute(['--locales' => ['en', 'fr'], '--domains' => ['messages']]);
381+
382+
$this->assertStringContainsString('[OK] New translations from "null" has been written locally (for "en, fr" locale(s), and "messages" domain(s)).', trim($tester->getDisplay()));
383+
$this->assertXmlStringEqualsXmlString(<<<XLIFF
384+
<?xml version="1.0"?>
385+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
386+
<file source-language="fr" target-language="en" datatype="plaintext" original="file.ext">
387+
<header>
388+
<tool tool-id="symfony" tool-name="Symfony"/>
389+
</header>
390+
<body>
391+
<trans-unit id="994ixRL" resname="new.foo">
392+
<source>new.foo</source>
393+
<target>newFoo</target>
394+
</trans-unit>
395+
<trans-unit id="7bRlYkK" resname="note">
396+
<source>note</source>
397+
<target>NOTE</target>
398+
</trans-unit>
399+
</body>
400+
</file>
401+
</xliff>
402+
XLIFF
403+
, file_get_contents($filenameEn));
404+
$this->assertXmlStringEqualsXmlString(<<<XLIFF
405+
<?xml version="1.0"?>
406+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
407+
<file source-language="fr" target-language="fr" datatype="plaintext" original="file.ext">
408+
<header>
409+
<tool tool-id="symfony" tool-name="Symfony"/>
410+
</header>
411+
<body>
412+
<trans-unit id="994ixRL" resname="new.foo">
413+
<source>new.foo</source>
414+
<target>nouveauFoo</target>
415+
</trans-unit>
416+
<trans-unit id="7bRlYkK" resname="note">
417+
<source>note</source>
418+
<target>NOTE</target>
419+
</trans-unit>
420+
</body>
421+
</file>
422+
</xliff>
423+
XLIFF
424+
, file_get_contents($filenameFr));
425+
}
426+
427+
private function createCommandTester(ProviderInterface $provider, array $locales = ['en'], array $domains = ['messages'], $defaultLocale = 'en'): CommandTester
352428
{
353429
$writer = new TranslationWriter();
354430
$writer->addDumper('xlf', new XliffFileDumper());
@@ -360,7 +436,7 @@ private function createCommandTester(ProviderInterface $provider, array $locales
360436
$this->getProviderCollection($provider, $locales, $domains),
361437
$writer,
362438
$reader,
363-
'en',
439+
$defaultLocale,
364440
[$this->translationAppDir.'/translations']
365441
);
366442
$application = new Application();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.