]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php
4e3ee6fdfa37fd153cfbbb735a6d5fb11c473d7c
[github/wallabag/wallabag.git] / vendor / symfony / twig-bridge / Symfony / Bridge / Twig / Tests / NodeVisitor / TranslationNodeVisitorTest.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
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\Bridge\Twig\Tests\NodeVisitor;
13
14 use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
15 use Symfony\Bridge\Twig\Tests\TestCase;
16
17 class TranslationNodeVisitorTest extends TestCase
18 {
19 /** @dataProvider getMessagesExtractionTestData */
20 public function testMessagesExtraction(\Twig_Node $node, array $expectedMessages)
21 {
22 $env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
23 $visitor = new TranslationNodeVisitor();
24 $visitor->enable();
25 $visitor->enterNode($node, $env);
26 $visitor->leaveNode($node, $env);
27 $this->assertEquals($expectedMessages, $visitor->getMessages());
28 }
29
30 public function testMessageExtractionWithInvalidDomainNode()
31 {
32 $message = 'new key';
33
34 $node = new \Twig_Node_Expression_Filter(
35 new \Twig_Node_Expression_Constant($message, 0),
36 new \Twig_Node_Expression_Constant('trans', 0),
37 new \Twig_Node(array(
38 new \Twig_Node_Expression_Array(array(), 0),
39 new \Twig_Node_Expression_Name('variable', 0),
40 )),
41 0
42 );
43
44 $this->testMessagesExtraction($node, array(array($message, TranslationNodeVisitor::UNDEFINED_DOMAIN)));
45 }
46
47 public function getMessagesExtractionTestData()
48 {
49 $message = 'new key';
50 $domain = 'domain';
51
52 return array(
53 array(TwigNodeProvider::getTransFilter($message), array(array($message, null))),
54 array(TwigNodeProvider::getTransChoiceFilter($message), array(array($message, null))),
55 array(TwigNodeProvider::getTransTag($message), array(array($message, null))),
56 array(TwigNodeProvider::getTransFilter($message, $domain), array(array($message, $domain))),
57 array(TwigNodeProvider::getTransChoiceFilter($message, $domain), array(array($message, $domain))),
58 array(TwigNodeProvider::getTransTag($message, $domain), array(array($message, $domain))),
59 );
60 }
61 }