4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Bridge\Twig\Tests\NodeVisitor
;
14 use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor
;
15 use Symfony\Bridge\Twig\Tests\TestCase
;
17 class TranslationNodeVisitorTest
extends TestCase
19 /** @dataProvider getMessagesExtractionTestData */
20 public function testMessagesExtraction(\Twig_Node
$node, array $expectedMessages)
22 $env = new \
Twig_Environment(new \
Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
23 $visitor = new TranslationNodeVisitor();
25 $visitor->enterNode($node, $env);
26 $visitor->leaveNode($node, $env);
27 $this->assertEquals($expectedMessages, $visitor->getMessages());
30 public function testMessageExtractionWithInvalidDomainNode()
34 $node = new \
Twig_Node_Expression_Filter(
35 new \
Twig_Node_Expression_Constant($message, 0),
36 new \
Twig_Node_Expression_Constant('trans', 0),
38 new \
Twig_Node_Expression_Array(array(), 0),
39 new \
Twig_Node_Expression_Name('variable', 0),
44 $this->testMessagesExtraction($node, array(array($message, TranslationNodeVisitor
::UNDEFINED_DOMAIN
)));
47 public function getMessagesExtractionTestData()
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))),