Skip to content

Commit

Permalink
Test, that compiled catalogue file defines expected variables
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Aug 3, 2014
1 parent 58b0924 commit e4842e1
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/KdybyTests/Translation/CatalogueCompiler.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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());

0 comments on commit e4842e1

Please sign in to comment.