mirror of
https://github.com/symfony/ux-translator.git
synced 2026-03-24 00:12:19 +01:00
[Translator] Add functional test to ensure only enabled_locales are dumped
This commit is contained in:
@@ -37,7 +37,8 @@
|
||||
"require-dev": {
|
||||
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
|
||||
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
|
||||
"symfony/var-dumper": "^5.4|^6.0|^7.0"
|
||||
"symfony/var-dumper": "^5.4|^6.0|^7.0",
|
||||
"symfony/yaml": "^5.4|^6.0|^7.0"
|
||||
},
|
||||
"extra": {
|
||||
"thanks": {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
|
||||
1
tests/Fixtures/translations/messages.en.yaml
Normal file
1
tests/Fixtures/translations/messages.en.yaml
Normal file
@@ -0,0 +1 @@
|
||||
symfony_ux.great: Symfony UX is awesome
|
||||
1
tests/Fixtures/translations/messages.es.yaml
Normal file
1
tests/Fixtures/translations/messages.es.yaml
Normal file
@@ -0,0 +1 @@
|
||||
symfony_ux.great: Symfony UX es genial
|
||||
1
tests/Fixtures/translations/messages.fr.yaml
Normal file
1
tests/Fixtures/translations/messages.fr.yaml
Normal file
@@ -0,0 +1 @@
|
||||
symfony_ux.great: Symfony UX est génial
|
||||
68
tests/Functional/DumpEnabledLocalesTest.php
Normal file
68
tests/Functional/DumpEnabledLocalesTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\UX\Translator\Tests\Functional;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\UX\Translator\Tests\Kernel\FrameworkAppKernel;
|
||||
|
||||
class DumpEnabledLocalesTest extends KernelTestCase
|
||||
{
|
||||
protected static function getKernelClass(): string
|
||||
{
|
||||
return FrameworkAppKernel::class;
|
||||
}
|
||||
|
||||
public function testShouldDumpOnlyEnabledLocales(): void
|
||||
{
|
||||
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.en.yaml');
|
||||
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.fr.yaml');
|
||||
self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.es.yaml');
|
||||
|
||||
$enabledLocales = self::getContainer()->getParameter('kernel.enabled_locales');
|
||||
self::assertNotContains('es', $enabledLocales, 'The "es" locale should not be enabled in this test');
|
||||
|
||||
$translationsDumpDir = self::getContainer()->getParameter('kernel.project_dir').'/var/translations';
|
||||
self::assertDirectoryExists($translationsDumpDir);
|
||||
|
||||
self::assertStringEqualsFile(
|
||||
$translationsDumpDir.'/index.js',
|
||||
<<<JAVASCRIPT
|
||||
export const SYMFONY_UX_GREAT = {"id":"symfony_ux.great","translations":{"messages":{"en":"Symfony UX is awesome","fr":"Symfony UX est g\u00e9nial"}}};
|
||||
|
||||
JAVASCRIPT
|
||||
);
|
||||
self::assertStringEqualsFile(
|
||||
$translationsDumpDir.'/index.d.ts',
|
||||
<<<TYPESCRIPT
|
||||
import { Message, NoParametersType } from '@symfony/ux-translator';
|
||||
|
||||
export declare const SYMFONY_UX_GREAT: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'fr'>;
|
||||
|
||||
TYPESCRIPT
|
||||
);
|
||||
self::assertStringEqualsFile(
|
||||
$translationsDumpDir.'/configuration.js',
|
||||
<<<JAVASCRIPT
|
||||
export const localeFallbacks = {"en":null,"fr":"en"};
|
||||
|
||||
JAVASCRIPT
|
||||
);
|
||||
self::assertStringEqualsFile(
|
||||
$translationsDumpDir.'/configuration.d.ts',
|
||||
<<<TYPESCRIPT
|
||||
import { LocaleType } from '@symfony/ux-translator';
|
||||
|
||||
export declare const localeFallbacks: Record<LocaleType, LocaleType>;
|
||||
TYPESCRIPT
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,9 @@ class FrameworkAppKernel extends Kernel
|
||||
'test' => true,
|
||||
'translator' => [
|
||||
'fallbacks' => ['en'],
|
||||
'default_path' => '%kernel.project_dir%/tests/Fixtures/translations',
|
||||
],
|
||||
'enabled_locales' => ['en', 'fr'],
|
||||
'http_method_override' => false,
|
||||
]);
|
||||
});
|
||||
|
||||
25
tests/bootstrap.php
Normal file
25
tests/bootstrap.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\UX\Translator\Tests\Kernel\FrameworkAppKernel;
|
||||
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
(new Filesystem())->remove(__DIR__.'/../var');
|
||||
|
||||
$kernel = new FrameworkAppKernel('test', true);
|
||||
$application = new Application($kernel);
|
||||
|
||||
// Trigger Symfony Translator and UX Translator cache warmers
|
||||
$application->run(new StringInput('cache:clear'));
|
||||
Reference in New Issue
Block a user