|
| 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 | +} |
0 commit comments