From 8069e235fd2971675ee5fc05026ffa9bce5cbbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Aug 2013 22:43:56 +0200 Subject: move Twig in 3rdparty --- inc/3rdparty/Twig/Gettext/Test/ExtractorTest.php | 123 +++++++++++++++++++++ .../Twig/Gettext/Test/Fixtures/twig/empty.twig | 1 + .../Twig/Gettext/Test/Fixtures/twig/plural.twig | 5 + .../Twig/Gettext/Test/Fixtures/twig/singular.twig | 9 ++ 4 files changed, 138 insertions(+) create mode 100644 inc/3rdparty/Twig/Gettext/Test/ExtractorTest.php create mode 100644 inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/empty.twig create mode 100644 inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/plural.twig create mode 100644 inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/singular.twig (limited to 'inc/3rdparty/Twig/Gettext/Test') diff --git a/inc/3rdparty/Twig/Gettext/Test/ExtractorTest.php b/inc/3rdparty/Twig/Gettext/Test/ExtractorTest.php new file mode 100644 index 00000000..d467835f --- /dev/null +++ b/inc/3rdparty/Twig/Gettext/Test/ExtractorTest.php @@ -0,0 +1,123 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Twig\Gettext\Test; + +use Twig\Gettext\Extractor; +use Twig\Gettext\Loader\Filesystem; +use Symfony\Component\Translation\Loader\PoFileLoader; + +/** + * @author Саша Стаменковић + */ +class ExtractorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Twig_Environment + */ + protected $twig; + + /** + * @var PoFileLoader + */ + protected $loader; + + protected function setUp() + { + $this->twig = new \Twig_Environment(new Filesystem('/'), array( + 'cache' => '/tmp/cache/'.uniqid(), + 'auto_reload' => true + )); + $this->twig->addExtension(new \Twig_Extensions_Extension_I18n()); + + $this->loader = new PoFileLoader(); + } + + /** + * @dataProvider testExtractDataProvider + */ + public function testExtract(array $templates, array $parameters, array $messages) + { + $extractor = new Extractor($this->twig); + + foreach ($templates as $template) { + $extractor->addTemplate($template); + } + foreach ($parameters as $parameter) { + $extractor->addGettextParameter($parameter); + } + + $extractor->extract(); + + $catalog = $this->loader->load($this->getPotFile(), null); + + foreach ($messages as $message) { + $this->assertTrue( + $catalog->has($message), + sprintf('Message "%s" not found in catalog.', $message) + ); + } + } + + public function testExtractDataProvider() + { + return array( + array( + array( + __DIR__.'/Fixtures/twig/singular.twig', + __DIR__.'/Fixtures/twig/plural.twig', + ), + $this->getGettextParameters(), + array( + 'Hello %name%!', + 'Hello World!', + 'Hey %name%, I have one apple.', + 'Hey %name%, I have %count% apples.', + ), + ), + ); + } + + public function testExtractNoTranslations() + { + $extractor = new Extractor($this->twig); + + $extractor->addTemplate(__DIR__.'/Fixtures/twig/empty.twig'); + $extractor->setGettextParameters($this->getGettextParameters()); + + $extractor->extract(); + + $catalog = $this->loader->load($this->getPotFile(), null); + + $this->assertEmpty($catalog->all('messages')); + } + + private function getPotFile() + { + return __DIR__.'/Fixtures/messages.pot'; + } + + private function getGettextParameters() + { + return array( + '--force-po', + '-o', + $this->getPotFile(), + ); + } + + protected function tearDown() + { + if (file_exists($this->getPotFile())) { + unlink($this->getPotFile()); + } + } +} diff --git a/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/empty.twig b/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/empty.twig new file mode 100644 index 00000000..05f0d26a --- /dev/null +++ b/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/empty.twig @@ -0,0 +1 @@ +Nothing to translate here. diff --git a/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/plural.twig b/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/plural.twig new file mode 100644 index 00000000..f9754ff4 --- /dev/null +++ b/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/plural.twig @@ -0,0 +1,5 @@ +{% trans %} + Hey {{ name }}, I have one apple. +{% plural apple_count %} + Hey {{ name }}, I have {{ count }} apples. +{% endtrans %} diff --git a/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/singular.twig b/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/singular.twig new file mode 100644 index 00000000..d757cf90 --- /dev/null +++ b/inc/3rdparty/Twig/Gettext/Test/Fixtures/twig/singular.twig @@ -0,0 +1,9 @@ +{% trans "Hello World!" %} + +{% trans %} + Hello World! +{% endtrans %} + +{% trans %} + Hello {{ name }}! +{% endtrans %} -- cgit v1.2.3