Skip to content

Commit 0d1950c

Browse files
committed
[Translator] Add functional test to ensure only enabled_locales are dumped
1 parent e1b43e7 commit 0d1950c

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

src/Translator/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"require-dev": {
3838
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
3939
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
40-
"symfony/var-dumper": "^5.4|^6.0|^7.0"
40+
"symfony/var-dumper": "^5.4|^6.0|^7.0",
41+
"symfony/yaml": "^5.4|^6.0|^7.0"
4142
},
4243
"extra": {
4344
"thanks": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
symfony_ux.great: Symfony UX is awesome
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
symfony_ux.great: Symfony UX es genial
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
symfony_ux.great: Symfony UX est génial
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\Translator\Tests\Functional;
13+
14+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
15+
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
16+
use Symfony\UX\Translator\CacheWarmer\TranslationsCacheWarmer;
17+
use Symfony\UX\Translator\Tests\Kernel\FrameworkAppKernel;
18+
19+
class DumpEnabledLocalesTest extends KernelTestCase
20+
{
21+
protected static function getKernelClass(): string
22+
{
23+
return FrameworkAppKernel::class;
24+
}
25+
26+
public function testShouldDumpOnlyEnabledLocales(): void
27+
{
28+
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.en.yaml');
29+
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.fr.yaml');
30+
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.es.yaml');
31+
32+
$enabledLocales = self::getContainer()->getParameter('kernel.enabled_locales');
33+
self::assertNotContains('es', $enabledLocales, 'The "es" locale should not be enabled in this test');
34+
35+
$translationsDumpDir = self::getContainer()->getParameter('kernel.project_dir') . '/var/translations';
36+
self::assertDirectoryExists($translationsDumpDir);
37+
38+
self::assertStringEqualsFile(
39+
$translationsDumpDir. '/index.js',
40+
<<<JAVASCRIPT
41+
export const SYMFONY_UX_GREAT = {"id":"symfony_ux.great","translations":{"messages":{"en":"Symfony UX is awesome","fr":"Symfony UX est g\u00e9nial"}}};
42+
43+
JAVASCRIPT
44+
);
45+
self::assertStringEqualsFile(
46+
$translationsDumpDir. '/index.d.ts',
47+
<<<TYPESCRIPT
48+
import { Message, NoParametersType } from '@symfony/ux-translator';
49+
50+
export declare const SYMFONY_UX_GREAT: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'fr'>;
51+
52+
TYPESCRIPT
53+
);
54+
self::assertStringEqualsFile(
55+
$translationsDumpDir. '/configuration.js',
56+
<<<JAVASCRIPT
57+
export const localeFallbacks = {"en":null,"fr":"en"};
58+
59+
JAVASCRIPT
60+
);
61+
self::assertStringEqualsFile(
62+
$translationsDumpDir. '/configuration.d.ts',
63+
<<<TYPESCRIPT
64+
import { LocaleType } from '@symfony/ux-translator';
65+
66+
export declare const localeFallbacks: Record<LocaleType, LocaleType>;
67+
TYPESCRIPT
68+
);
69+
}
70+
}

src/Translator/tests/Kernel/FrameworkAppKernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
3939
'test' => true,
4040
'translator' => [
4141
'fallbacks' => ['en'],
42+
'default_path' => '%kernel.project_dir%/tests/Fixtures/translations',
4243
],
44+
'enabled_locales' => ['en', 'fr'],
4345
'http_method_override' => false,
4446
]);
4547
});

0 commit comments

Comments
 (0)