]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / twig-bridge / Symfony / Bridge / Twig / Tests / NodeVisitor / TranslationDefaultDomainNodeVisitorTest.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\TranslationDefaultDomainNodeVisitor;
15 use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
16 use Symfony\Bridge\Twig\Tests\TestCase;
17
18 class TranslationDefaultDomainNodeVisitorTest extends TestCase
19 {
20 private static $message = 'message';
21 private static $domain = 'domain';
22
23 /** @dataProvider getDefaultDomainAssignmentTestData */
24 public function testDefaultDomainAssignment(\Twig_Node $node)
25 {
26 $env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
27 $visitor = new TranslationDefaultDomainNodeVisitor();
28
29 // visit trans_default_domain tag
30 $defaultDomain = TwigNodeProvider::getTransDefaultDomainTag(self::$domain);
31 $visitor->enterNode($defaultDomain, $env);
32 $visitor->leaveNode($defaultDomain, $env);
33
34 // visit tested node
35 $enteredNode = $visitor->enterNode($node, $env);
36 $leavedNode = $visitor->leaveNode($node, $env);
37 $this->assertSame($node, $enteredNode);
38 $this->assertSame($node, $leavedNode);
39
40 // extracting tested node messages
41 $visitor = new TranslationNodeVisitor();
42 $visitor->enable();
43 $visitor->enterNode($node, $env);
44 $visitor->leaveNode($node, $env);
45
46 $this->assertEquals(array(array(self::$message, self::$domain)), $visitor->getMessages());
47 }
48
49 /** @dataProvider getDefaultDomainAssignmentTestData */
50 public function testNewModuleWithoutDefaultDomainTag(\Twig_Node $node)
51 {
52 $env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
53 $visitor = new TranslationDefaultDomainNodeVisitor();
54
55 // visit trans_default_domain tag
56 $newModule = TwigNodeProvider::getModule('test');
57 $visitor->enterNode($newModule, $env);
58 $visitor->leaveNode($newModule, $env);
59
60 // visit tested node
61 $enteredNode = $visitor->enterNode($node, $env);
62 $leavedNode = $visitor->leaveNode($node, $env);
63 $this->assertSame($node, $enteredNode);
64 $this->assertSame($node, $leavedNode);
65
66 // extracting tested node messages
67 $visitor = new TranslationNodeVisitor();
68 $visitor->enable();
69 $visitor->enterNode($node, $env);
70 $visitor->leaveNode($node, $env);
71
72 $this->assertEquals(array(array(self::$message, null)), $visitor->getMessages());
73 }
74
75 public function getDefaultDomainAssignmentTestData()
76 {
77 return array(
78 array(TwigNodeProvider::getTransFilter(self::$message)),
79 array(TwigNodeProvider::getTransChoiceFilter(self::$message)),
80 array(TwigNodeProvider::getTransTag(self::$message)),
81 );
82 }
83 }