|
| 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\UX\Translator\Tests\Kernel\FrameworkAppKernel; |
| 16 | + |
| 17 | +class DumpEnabledLocalesTest extends KernelTestCase |
| 18 | +{ |
| 19 | + protected static function getKernelClass(): string |
| 20 | + { |
| 21 | + return FrameworkAppKernel::class; |
| 22 | + } |
| 23 | + |
| 24 | + public function testShouldDumpOnlyEnabledLocales(): void |
| 25 | + { |
| 26 | + self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.en.yaml'); |
| 27 | + self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.fr.yaml'); |
| 28 | + self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.es.yaml'); |
| 29 | + |
| 30 | + // Manually warmup cache warmers when < https://github.com/symfony/symfony/pull/57553 |
| 31 | + if (FrameworkAppKernel::VERSION_ID < 60409) { |
| 32 | + $cacheWarmer = self::getContainer()->get('cache_warmer'); |
| 33 | + $cacheWarmer->warmUp(self::getContainer()->getParameter('kernel.cache_dir')); |
| 34 | + } |
| 35 | + |
| 36 | + $enabledLocales = self::getContainer()->getParameter('kernel.enabled_locales'); |
| 37 | + self::assertNotContains('es', $enabledLocales, 'The "es" locale should not be enabled in this test'); |
| 38 | + |
| 39 | + $translationsDumpDir = self::getContainer()->getParameter('kernel.project_dir').'/var/translations'; |
| 40 | + self::assertDirectoryExists($translationsDumpDir); |
| 41 | + |
| 42 | + self::assertStringEqualsFile( |
| 43 | + $translationsDumpDir.'/index.js', |
| 44 | + <<<JAVASCRIPT |
| 45 | + export const SYMFONY_UX_GREAT = {"id":"symfony_ux.great","translations":{"messages":{"en":"Symfony UX is awesome","fr":"Symfony UX est g\u00e9nial"}}}; |
| 46 | +
|
| 47 | + JAVASCRIPT |
| 48 | + ); |
| 49 | + self::assertStringEqualsFile( |
| 50 | + $translationsDumpDir.'/index.d.ts', |
| 51 | + <<<TYPESCRIPT |
| 52 | + import { Message, NoParametersType } from '@symfony/ux-translator'; |
| 53 | +
|
| 54 | + export declare const SYMFONY_UX_GREAT: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'fr'>; |
| 55 | +
|
| 56 | + TYPESCRIPT |
| 57 | + ); |
| 58 | + self::assertStringEqualsFile( |
| 59 | + $translationsDumpDir.'/configuration.js', |
| 60 | + <<<JAVASCRIPT |
| 61 | + export const localeFallbacks = {"en":null,"fr":"en"}; |
| 62 | +
|
| 63 | + JAVASCRIPT |
| 64 | + ); |
| 65 | + self::assertStringEqualsFile( |
| 66 | + $translationsDumpDir.'/configuration.d.ts', |
| 67 | + <<<TYPESCRIPT |
| 68 | + import { LocaleType } from '@symfony/ux-translator'; |
| 69 | +
|
| 70 | + export declare const localeFallbacks: Record<LocaleType, LocaleType>; |
| 71 | + TYPESCRIPT |
| 72 | + ); |
| 73 | + } |
| 74 | +} |
0 commit comments