From 534fd91a288dd27f7698027bcc5d1c80684e98a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Sun, 3 Aug 2014 23:10:19 +0200 Subject: [PATCH] Test, that compiled catalogue file defines expected variables --- .../Translation/CatalogueCompiler.phpt | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/KdybyTests/Translation/CatalogueCompiler.phpt b/tests/KdybyTests/Translation/CatalogueCompiler.phpt index 1aed2b00..0002e78a 100644 --- a/tests/KdybyTests/Translation/CatalogueCompiler.phpt +++ b/tests/KdybyTests/Translation/CatalogueCompiler.phpt @@ -39,9 +39,48 @@ class CatalogueCompilerTest extends TestCase $translator->setFallbackLocales(array('en_US', 'en')); Assert::same("Hello world", $translator->translate('homepage.hello', NULL, array(), 'front', 'fr')); - } + + + public function testLocaleEscaping() + { + $container = $this->createContainer(); + + /** @var Kdyby\Translation\Translator $translator */ + $translator = $container->getByType('Nette\Localization\ITranslator'); + $translator->setFallbackLocales(array('fr_FR', 'fr.UTF8', 'cs_CZ', 'cs')); + + /** @var \Kdyby\Translation\CatalogueCompiler $compiler */ + $compiler = $container->getByType('Kdyby\Translation\CatalogueCompiler'); + + $catalogues = []; + $compiler->compile($translator, $catalogues, 'fr-FR.UTF8'); + + $tempFiles = array_filter(get_included_files(), function ($path) { + return stripos(realpath($path), realpath(TEMP_DIR)) !== FALSE && stripos($path, 'fr-FR.UTF8'); + }); + + Assert::count(1, $tempFiles); + + $compiledCatalogue = call_user_func(function ($__file) use (&$__definedVariables) { + $__definedVariables = get_defined_vars() + array('__compiled' => NULL); + $__compiled = include $__file; + $__definedVariables = array_diff_key(get_defined_vars(), $__definedVariables); + + return $__compiled; + }, reset($tempFiles)); + + Assert::type('Symfony\Component\Translation\MessageCatalogue', $compiledCatalogue); + Assert::same(array( + 'catalogue', + 'catalogueFr_FR', + 'catalogueFr_UTF8', + 'catalogueCs_CZ', + 'catalogueCs' + ), array_keys($__definedVariables)); + } + } \run(new CatalogueCompilerTest());