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\TranslationDefaultDomainNodeVisitor
;
15 use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor
;
16 use Symfony\Bridge\Twig\Tests\TestCase
;
18 class TranslationDefaultDomainNodeVisitorTest
extends TestCase
20 private static $message = 'message';
21 private static $domain = 'domain';
23 /** @dataProvider getDefaultDomainAssignmentTestData */
24 public function testDefaultDomainAssignment(\Twig_Node
$node)
26 $env = new \
Twig_Environment(new \
Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
27 $visitor = new TranslationDefaultDomainNodeVisitor();
29 // visit trans_default_domain tag
30 $defaultDomain = TwigNodeProvider
::getTransDefaultDomainTag(self
::$domain);
31 $visitor->enterNode($defaultDomain, $env);
32 $visitor->leaveNode($defaultDomain, $env);
35 $enteredNode = $visitor->enterNode($node, $env);
36 $leavedNode = $visitor->leaveNode($node, $env);
37 $this->assertSame($node, $enteredNode);
38 $this->assertSame($node, $leavedNode);
40 // extracting tested node messages
41 $visitor = new TranslationNodeVisitor();
43 $visitor->enterNode($node, $env);
44 $visitor->leaveNode($node, $env);
46 $this->assertEquals(array(array(self
::$message, self
::$domain)), $visitor->getMessages());
49 /** @dataProvider getDefaultDomainAssignmentTestData */
50 public function testNewModuleWithoutDefaultDomainTag(\Twig_Node
$node)
52 $env = new \
Twig_Environment(new \
Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
53 $visitor = new TranslationDefaultDomainNodeVisitor();
55 // visit trans_default_domain tag
56 $newModule = TwigNodeProvider
::getModule('test');
57 $visitor->enterNode($newModule, $env);
58 $visitor->leaveNode($newModule, $env);
61 $enteredNode = $visitor->enterNode($node, $env);
62 $leavedNode = $visitor->leaveNode($node, $env);
63 $this->assertSame($node, $enteredNode);
64 $this->assertSame($node, $leavedNode);
66 // extracting tested node messages
67 $visitor = new TranslationNodeVisitor();
69 $visitor->enterNode($node, $env);
70 $visitor->leaveNode($node, $env);
72 $this->assertEquals(array(array(self
::$message, null)), $visitor->getMessages());
75 public function getDefaultDomainAssignmentTestData()
78 array(TwigNodeProvider
::getTransFilter(self
::$message)),
79 array(TwigNodeProvider
::getTransChoiceFilter(self
::$message)),
80 array(TwigNodeProvider
::getTransTag(self
::$message)),