Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  fix merge
  [HttpClient] mark test transient
  [Mime] Fix test
  [Translation] Fix TranslationPullCommand with ICU translations
  [PropertyInfo] Fix phpstan extractor issues
  Allow package-versions-deprecated plugin
  Update security.lb.xlf
  [Notifier] Use correct factory for the msteams transport
  Fix SessionListener without session in request
  Remove direct dependency on composer/package-versions-deprecated
  Remove the unused dependency on composer/package-versions-deprecated
  [Security/Http] Fix cookie clearing on logout
  [HttpClient] fix checking for recent curl consts
  • Loading branch information
nicolas-grekas committed Dec 25, 2021
2 parents 8523874 + ff8bb21 commit a16c33f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
13 changes: 12 additions & 1 deletion Catalogue/AbstractOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ public function __construct(MessageCatalogueInterface $source, MessageCatalogueI
public function getDomains(): array
{
if (null === $this->domains) {
$this->domains = array_values(array_unique(array_merge($this->source->getDomains(), $this->target->getDomains())));
$domains = [];
foreach ([$this->source, $this->target] as $catalogue) {
foreach ($catalogue->getDomains() as $domain) {
$domains[$domain] = $domain;

if ($catalogue->all($domainIcu = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX)) {
$domains[$domainIcu] = $domainIcu;
}
}
}

$this->domains = array_values($domains);
}

return $this->domains;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Catalogue/MergeOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testGetResultFromIntlDomain()
$this->assertEquals(
new MessageCatalogue('en', [
'messages' => ['a' => 'old_a', 'b' => 'old_b'],
'messages+intl-icu' => ['d' => 'old_d', 'c' => 'new_c'],
'messages+intl-icu' => ['d' => 'old_d', 'c' => 'new_c', 'a' => 'new_a'],
]),
$this->createOperation(
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b'], 'messages+intl-icu' => ['d' => 'old_d']]),
Expand Down
3 changes: 2 additions & 1 deletion Tests/Catalogue/TargetOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function testGetResultWithMixedDomains()
$this->assertEquals(
new MessageCatalogue('en', [
'messages' => ['a' => 'old_a'],
'messages+intl-icu' => ['a' => 'new_a'],
]),
$this->createOperation(
new MessageCatalogue('en', ['messages' => ['a' => 'old_a']]),
Expand Down Expand Up @@ -103,7 +104,7 @@ public function testGetResultWithMixedDomains()
$this->assertEquals(
new MessageCatalogue('en', [
'messages' => ['a' => 'old_a'],
'messages+intl-icu' => ['b' => 'new_b'],
'messages+intl-icu' => ['b' => 'new_b', 'a' => 'new_a'],
]),
$this->createOperation(
new MessageCatalogue('en', ['messages' => ['a' => 'old_a']]),
Expand Down
48 changes: 45 additions & 3 deletions Tests/Command/TranslationPullCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,27 @@ public function testPullNewXlf12Messages()
{
$arrayLoader = new ArrayLoader();
$filenameEn = $this->createFile();
$filenameEnIcu = $this->createFile(['say_hello' => 'Welcome, {firstname}!'], 'en', 'messages+intl-icu.%locale%.xlf');
$filenameFr = $this->createFile(['note' => 'NOTE'], 'fr');
$filenameFrIcu = $this->createFile(['say_hello' => 'Bonjour, {firstname}!'], 'fr', 'messages+intl-icu.%locale%.xlf');
$locales = ['en', 'fr'];
$domains = ['messages'];
$domains = ['messages', 'messages+intl-icu'];

$providerReadTranslatorBag = new TranslatorBag();
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
'note' => 'NOTE',
'new.foo' => 'newFoo',
], 'en'));
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
'say_hello' => 'Welcome, {firstname}!',
], 'en', 'messages+intl-icu'));
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
'note' => 'NOTE',
'new.foo' => 'nouveauFoo',
], 'fr'));
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
'say_hello' => 'Bonjour, {firstname}!',
], 'fr', 'messages+intl-icu'));

$provider = $this->createMock(ProviderInterface::class);
$provider->expects($this->once())
Expand All @@ -72,9 +80,9 @@ public function testPullNewXlf12Messages()
->willReturn('null://default');

$tester = $this->createCommandTester($provider, $locales, $domains);
$tester->execute(['--locales' => ['en', 'fr'], '--domains' => ['messages']]);
$tester->execute(['--locales' => ['en', 'fr'], '--domains' => ['messages', 'messages+intl-icu']]);

$this->assertStringContainsString('[OK] New translations from "null" has been written locally (for "en, fr" locale(s), and "messages" domain(s)).', trim($tester->getDisplay()));
$this->assertStringContainsString('[OK] New translations from "null" has been written locally (for "en, fr" locale(s), and "messages, messages+intl-icu"', trim($tester->getDisplay()));
$this->assertXmlStringEqualsXmlString(<<<XLIFF
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
Expand All @@ -98,6 +106,23 @@ public function testPullNewXlf12Messages()
, file_get_contents($filenameEn));
$this->assertXmlStringEqualsXmlString(<<<XLIFF
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="1IHotcu" resname="say_hello">
<source>say_hello</source>
<target>Welcome, {firstname}!</target>
</trans-unit>
</body>
</file>
</xliff>
XLIFF
, file_get_contents($filenameEnIcu));
$this->assertXmlStringEqualsXmlString(<<<XLIFF
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
<header>
Expand All @@ -117,6 +142,23 @@ public function testPullNewXlf12Messages()
</xliff>
XLIFF
, file_get_contents($filenameFr));
$this->assertXmlStringEqualsXmlString(<<<XLIFF
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="1IHotcu" resname="say_hello">
<source>say_hello</source>
<target>Bonjour, {firstname}!</target>
</trans-unit>
</body>
</file>
</xliff>
XLIFF
, file_get_contents($filenameFrIcu));
}

public function testPullNewXlf20Messages()
Expand Down

0 comments on commit a16c33f

Please sign in to comment.