aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests')
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php69
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php30
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php35
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php209
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php131
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php68
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php60
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php151
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/child_label.html.twig3
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/custom_widgets.html.twig16
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/parent_label.html.twig3
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme.html.twig6
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_extends.html.twig8
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_use.html.twig8
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php85
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php282
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/ScopeTest.php25
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php83
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php61
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php77
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/TestCase.php22
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php108
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php81
23 files changed, 0 insertions, 1621 deletions
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php
deleted file mode 100644
index d9356514..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php
+++ /dev/null
@@ -1,69 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Extension;
13
14use Symfony\Bridge\Twig\Extension\CodeExtension;
15
16class CodeExtensionTest extends \PHPUnit_Framework_TestCase
17{
18 protected $helper;
19
20 public function testFormatFile()
21 {
22 $expected = sprintf('<a href="txmt://open?url=file://%s&amp;line=25" title="Click to open this file" class="file_link">%s at line 25</a>', __FILE__, __FILE__);
23 $this->assertEquals($expected, $this->getExtension()->formatFile(__FILE__, 25));
24 }
25
26 /**
27 * @dataProvider getClassNameProvider
28 */
29 public function testGettingClassAbbreviation($class, $abbr)
30 {
31 $this->assertEquals($this->getExtension()->abbrClass($class), $abbr);
32 }
33
34 /**
35 * @dataProvider getMethodNameProvider
36 */
37 public function testGettingMethodAbbreviation($method, $abbr)
38 {
39 $this->assertEquals($this->getExtension()->abbrMethod($method), $abbr);
40 }
41
42 public function getClassNameProvider()
43 {
44 return array(
45 array('F\Q\N\Foo', '<abbr title="F\Q\N\Foo">Foo</abbr>'),
46 array('Bare', '<abbr title="Bare">Bare</abbr>'),
47 );
48 }
49
50 public function getMethodNameProvider()
51 {
52 return array(
53 array('F\Q\N\Foo::Method', '<abbr title="F\Q\N\Foo">Foo</abbr>::Method()'),
54 array('Bare::Method', '<abbr title="Bare">Bare</abbr>::Method()'),
55 array('Closure', '<abbr title="Closure">Closure</abbr>'),
56 array('Method', '<abbr title="Method">Method</abbr>()')
57 );
58 }
59
60 public function testGetName()
61 {
62 $this->assertEquals('code', $this->getExtension()->getName());
63 }
64
65 protected function getExtension()
66 {
67 return new CodeExtension('txmt://open?url=file://%f&line=%l', '/root', 'UTF-8');
68 }
69}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php
deleted file mode 100644
index 36c61cd6..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php
+++ /dev/null
@@ -1,30 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Extension\Fixtures;
13
14// Preventing autoloader throwing E_FATAL when Twig is now available
15if (!class_exists('Twig_Environment')) {
16 class StubFilesystemLoader
17 {
18 }
19} else {
20 class StubFilesystemLoader extends \Twig_Loader_Filesystem
21 {
22 protected function findTemplate($name)
23 {
24 // strip away bundle name
25 $parts = explode(':', $name);
26
27 return parent::findTemplate(end($parts));
28 }
29 }
30}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php
deleted file mode 100644
index b7d011b5..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php
+++ /dev/null
@@ -1,35 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Extension\Fixtures;
13
14use Symfony\Component\Translation\TranslatorInterface;
15
16class StubTranslator implements TranslatorInterface
17{
18 public function trans($id, array $parameters = array(), $domain = null, $locale = null)
19 {
20 return '[trans]'.$id.'[/trans]';
21 }
22
23 public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
24 {
25 return '[trans]'.$id.'[/trans]';
26 }
27
28 public function setLocale($locale)
29 {
30 }
31
32 public function getLocale()
33 {
34 }
35}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php
deleted file mode 100644
index c5c134bc..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php
+++ /dev/null
@@ -1,209 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Extension;
13
14use Symfony\Bridge\Twig\Extension\FormExtension;
15use Symfony\Bridge\Twig\Form\TwigRenderer;
16use Symfony\Bridge\Twig\Form\TwigRendererEngine;
17use Symfony\Bridge\Twig\Extension\TranslationExtension;
18use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
19use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
20use Symfony\Component\Form\FormView;
21use Symfony\Component\Form\Extension\Core\View\ChoiceView;
22use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
23
24class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
25{
26 /**
27 * @var FormExtension
28 */
29 protected $extension;
30
31 protected function setUp()
32 {
33 if (!class_exists('Symfony\Component\Locale\Locale')) {
34 $this->markTestSkipped('The "Locale" component is not available');
35 }
36
37 if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
38 $this->markTestSkipped('The "EventDispatcher" component is not available');
39 }
40
41 if (!class_exists('Symfony\Component\Form\Form')) {
42 $this->markTestSkipped('The "Form" component is not available');
43 }
44
45 if (!class_exists('Twig_Environment')) {
46 $this->markTestSkipped('Twig is not available.');
47 }
48
49 parent::setUp();
50
51 $rendererEngine = new TwigRendererEngine(array(
52 'form_div_layout.html.twig',
53 'custom_widgets.html.twig',
54 ));
55 $renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'));
56
57 $this->extension = new FormExtension($renderer);
58
59 $loader = new StubFilesystemLoader(array(
60 __DIR__.'/../../Resources/views/Form',
61 __DIR__,
62 ));
63
64 $environment = new \Twig_Environment($loader, array('strict_variables' => true));
65 $environment->addExtension(new TranslationExtension(new StubTranslator()));
66 $environment->addGlobal('global', '');
67 $environment->addExtension($this->extension);
68
69 $this->extension->initRuntime($environment);
70 }
71
72 protected function tearDown()
73 {
74 parent::tearDown();
75
76 $this->extension = null;
77 }
78
79 public function testThemeBlockInheritanceUsingUse()
80 {
81 $view = $this->factory
82 ->createNamed('name', 'email')
83 ->createView()
84 ;
85
86 $this->setTheme($view, array('theme_use.html.twig'));
87
88 $this->assertMatchesXpath(
89 $this->renderWidget($view),
90 '/input[@type="email"][@rel="theme"]'
91 );
92 }
93
94 public function testThemeBlockInheritanceUsingExtend()
95 {
96 $view = $this->factory
97 ->createNamed('name', 'email')
98 ->createView()
99 ;
100
101 $this->setTheme($view, array('theme_extends.html.twig'));
102
103 $this->assertMatchesXpath(
104 $this->renderWidget($view),
105 '/input[@type="email"][@rel="theme"]'
106 );
107 }
108
109 public function isSelectedChoiceProvider()
110 {
111 // The commented cases should not be necessary anymore, because the
112 // choice lists should assure that both values passed here are always
113 // strings
114 return array(
115// array(true, 0, 0),
116 array(true, '0', '0'),
117 array(true, '1', '1'),
118// array(true, false, 0),
119// array(true, true, 1),
120 array(true, '', ''),
121// array(true, null, ''),
122 array(true, '1.23', '1.23'),
123 array(true, 'foo', 'foo'),
124 array(true, 'foo10', 'foo10'),
125 array(true, 'foo', array(1, 'foo', 'foo10')),
126
127 array(false, 10, array(1, 'foo', 'foo10')),
128 array(false, 0, array(1, 'foo', 'foo10')),
129 );
130 }
131
132 /**
133 * @dataProvider isSelectedChoiceProvider
134 */
135 public function testIsChoiceSelected($expected, $choice, $value)
136 {
137 $choice = new ChoiceView($choice, $choice, $choice.' label');
138
139 $this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
140 }
141
142 protected function renderForm(FormView $view, array $vars = array())
143 {
144 return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
145 }
146
147 protected function renderEnctype(FormView $view)
148 {
149 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
150 }
151
152 protected function renderLabel(FormView $view, $label = null, array $vars = array())
153 {
154 if ($label !== null) {
155 $vars += array('label' => $label);
156 }
157
158 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
159 }
160
161 protected function renderErrors(FormView $view)
162 {
163 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
164 }
165
166 protected function renderWidget(FormView $view, array $vars = array())
167 {
168 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
169 }
170
171 protected function renderRow(FormView $view, array $vars = array())
172 {
173 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
174 }
175
176 protected function renderRest(FormView $view, array $vars = array())
177 {
178 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
179 }
180
181 protected function renderStart(FormView $view, array $vars = array())
182 {
183 return (string) $this->extension->renderer->renderBlock($view, 'form_start', $vars);
184 }
185
186 protected function renderEnd(FormView $view, array $vars = array())
187 {
188 return (string) $this->extension->renderer->renderBlock($view, 'form_end', $vars);
189 }
190
191 protected function setTheme(FormView $view, array $themes)
192 {
193 $this->extension->renderer->setTheme($view, $themes);
194 }
195
196 public static function themeBlockInheritanceProvider()
197 {
198 return array(
199 array(array('theme.html.twig'))
200 );
201 }
202
203 public static function themeInheritanceProvider()
204 {
205 return array(
206 array(array('parent_label.html.twig'), array('child_label.html.twig'))
207 );
208 }
209}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php
deleted file mode 100644
index 99a78217..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php
+++ /dev/null
@@ -1,131 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Extension;
13
14use Symfony\Component\Form\FormView;
15use Symfony\Bridge\Twig\Form\TwigRenderer;
16use Symfony\Bridge\Twig\Form\TwigRendererEngine;
17use Symfony\Bridge\Twig\Extension\FormExtension;
18use Symfony\Bridge\Twig\Extension\TranslationExtension;
19use Symfony\Component\Form\Tests\AbstractTableLayoutTest;
20use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
21use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
22
23class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
24{
25 /**
26 * @var FormExtension
27 */
28 protected $extension;
29
30 protected function setUp()
31 {
32 if (!class_exists('Symfony\Component\Locale\Locale')) {
33 $this->markTestSkipped('The "Locale" component is not available');
34 }
35
36 if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
37 $this->markTestSkipped('The "EventDispatcher" component is not available');
38 }
39
40 if (!class_exists('Symfony\Component\Form\Form')) {
41 $this->markTestSkipped('The "Form" component is not available');
42 }
43
44 if (!class_exists('Twig_Environment')) {
45 $this->markTestSkipped('Twig is not available.');
46 }
47
48 parent::setUp();
49
50 $rendererEngine = new TwigRendererEngine(array(
51 'form_table_layout.html.twig',
52 'custom_widgets.html.twig',
53 ));
54 $renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'));
55
56 $this->extension = new FormExtension($renderer);
57
58 $loader = new StubFilesystemLoader(array(
59 __DIR__.'/../../Resources/views/Form',
60 __DIR__,
61 ));
62
63 $environment = new \Twig_Environment($loader, array('strict_variables' => true));
64 $environment->addExtension(new TranslationExtension(new StubTranslator()));
65 $environment->addGlobal('global', '');
66 $environment->addExtension($this->extension);
67
68 $this->extension->initRuntime($environment);
69 }
70
71 protected function tearDown()
72 {
73 parent::tearDown();
74
75 $this->extension = null;
76 }
77
78 protected function renderForm(FormView $view, array $vars = array())
79 {
80 return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
81 }
82
83 protected function renderEnctype(FormView $view)
84 {
85 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
86 }
87
88 protected function renderLabel(FormView $view, $label = null, array $vars = array())
89 {
90 if ($label !== null) {
91 $vars += array('label' => $label);
92 }
93
94 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
95 }
96
97 protected function renderErrors(FormView $view)
98 {
99 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
100 }
101
102 protected function renderWidget(FormView $view, array $vars = array())
103 {
104 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
105 }
106
107 protected function renderRow(FormView $view, array $vars = array())
108 {
109 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
110 }
111
112 protected function renderRest(FormView $view, array $vars = array())
113 {
114 return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
115 }
116
117 protected function renderStart(FormView $view, array $vars = array())
118 {
119 return (string) $this->extension->renderer->renderBlock($view, 'form_start', $vars);
120 }
121
122 protected function renderEnd(FormView $view, array $vars = array())
123 {
124 return (string) $this->extension->renderer->renderBlock($view, 'form_end', $vars);
125 }
126
127 protected function setTheme(FormView $view, array $themes)
128 {
129 $this->extension->renderer->setTheme($view, $themes);
130 }
131}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
deleted file mode 100644
index 077927cd..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
+++ /dev/null
@@ -1,68 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Extension;
13
14use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
15use Symfony\Bridge\Twig\Tests\TestCase;
16use Symfony\Component\HttpFoundation\Request;
17use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
18
19class HttpKernelExtensionTest extends TestCase
20{
21 protected function setUp()
22 {
23 parent::setUp();
24
25 if (!class_exists('Symfony\Component\HttpKernel\HttpKernel')) {
26 $this->markTestSkipped('The "HttpKernel" component is not available');
27 }
28
29 if (!class_exists('Twig_Environment')) {
30 $this->markTestSkipped('Twig is not available.');
31 }
32 }
33
34 /**
35 * @expectedException \Twig_Error_Runtime
36 */
37 public function testFragmentWithError()
38 {
39 $kernel = $this->getFragmentHandler($this->throwException(new \Exception('foo')));
40
41 $loader = new \Twig_Loader_Array(array('index' => '{{ fragment("foo") }}'));
42 $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
43 $twig->addExtension(new HttpKernelExtension($kernel));
44
45 $this->renderTemplate($kernel);
46 }
47
48 protected function getFragmentHandler($return)
49 {
50 $strategy = $this->getMock('Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface');
51 $strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
52 $strategy->expects($this->once())->method('render')->will($return);
53
54 $renderer = new FragmentHandler(array($strategy));
55 $renderer->setRequest(Request::create('/'));
56
57 return $renderer;
58 }
59
60 protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
61 {
62 $loader = new \Twig_Loader_Array(array('index' => $template));
63 $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
64 $twig->addExtension(new HttpKernelExtension($renderer));
65
66 return $twig->render('index');
67 }
68}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
deleted file mode 100644
index 3c5d762c..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Extension;
13
14use Symfony\Bridge\Twig\Extension\RoutingExtension;
15use Symfony\Bridge\Twig\Tests\TestCase;
16
17class RoutingExtensionTest extends TestCase
18{
19 protected function setUp()
20 {
21 parent::setUp();
22
23 if (!class_exists('Symfony\Component\Routing\Route')) {
24 $this->markTestSkipped('The "Routing" component is not available');
25 }
26 }
27
28 /**
29 * @dataProvider getEscapingTemplates
30 */
31 public function testEscaping($template, $mustBeEscaped)
32 {
33 $twig = new \Twig_Environment(null, array('debug' => true, 'cache' => false, 'autoescape' => true, 'optimizations' => 0));
34 $twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
35
36 $nodes = $twig->parse($twig->tokenize($template));
37
38 $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
39 }
40
41 public function getEscapingTemplates()
42 {
43 return array(
44 array('{{ path("foo") }}', false),
45 array('{{ path("foo", {}) }}', false),
46 array('{{ path("foo", { foo: "foo" }) }}', false),
47 array('{{ path("foo", foo) }}', true),
48 array('{{ path("foo", { foo: foo }) }}', true),
49 array('{{ path("foo", { foo: ["foo", "bar"] }) }}', true),
50 array('{{ path("foo", { foo: "foo", bar: "bar" }) }}', true),
51
52 array('{{ path(name = "foo", parameters = {}) }}', false),
53 array('{{ path(name = "foo", parameters = { foo: "foo" }) }}', false),
54 array('{{ path(name = "foo", parameters = foo) }}', true),
55 array('{{ path(name = "foo", parameters = { foo: ["foo", "bar"] }) }}', true),
56 array('{{ path(name = "foo", parameters = { foo: foo }) }}', true),
57 array('{{ path(name = "foo", parameters = { foo: "foo", bar: "bar" }) }}', true),
58 );
59 }
60}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
deleted file mode 100644
index 2b9c5533..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
+++ /dev/null
@@ -1,151 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Extension;
13
14use Symfony\Bridge\Twig\Extension\TranslationExtension;
15use Symfony\Component\Translation\Translator;
16use Symfony\Component\Translation\MessageSelector;
17use Symfony\Component\Translation\Loader\ArrayLoader;
18use Symfony\Bridge\Twig\Tests\TestCase;
19
20class TranslationExtensionTest extends TestCase
21{
22 protected function setUp()
23 {
24 parent::setUp();
25
26 if (!class_exists('Symfony\Component\Translation\Translator')) {
27 $this->markTestSkipped('The "Translation" component is not available');
28 }
29
30 if (!class_exists('Twig_Environment')) {
31 $this->markTestSkipped('Twig is not available.');
32 }
33 }
34
35 public function testEscaping()
36 {
37 $output = $this->getTemplate('{% trans %}Percent: %value%%% (%msg%){% endtrans %}')->render(array('value' => 12, 'msg' => 'approx.'));
38
39 $this->assertEquals('Percent: 12% (approx.)', $output);
40 }
41
42 /**
43 * @dataProvider getTransTests
44 */
45 public function testTrans($template, $expected, array $variables = array())
46 {
47 if ($expected != $this->getTemplate($template)->render($variables)) {
48 print $template."\n";
49 $loader = new \Twig_Loader_Array(array('index' => $template));
50 $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
51 $twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
52
53 echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSource('index'), 'index')))."\n\n";
54 $this->assertEquals($expected, $this->getTemplate($template)->render($variables));
55 }
56
57 $this->assertEquals($expected, $this->getTemplate($template)->render($variables));
58 }
59
60 public function getTransTests()
61 {
62 return array(
63 // trans tag
64 array('{% trans %}Hello{% endtrans %}', 'Hello'),
65 array('{% trans %}%name%{% endtrans %}', 'Symfony2', array('name' => 'Symfony2')),
66
67 array('{% trans from elsewhere %}Hello{% endtrans %}', 'Hello'),
68
69 array('{% trans %}Hello %name%{% endtrans %}', 'Hello Symfony2', array('name' => 'Symfony2')),
70 array('{% trans with { \'%name%\': \'Symfony2\' } %}Hello %name%{% endtrans %}', 'Hello Symfony2'),
71 array('{% set vars = { \'%name%\': \'Symfony2\' } %}{% trans with vars %}Hello %name%{% endtrans %}', 'Hello Symfony2'),
72
73 array('{% trans into "fr"%}Hello{% endtrans %}', 'Hello'),
74
75 // transchoice
76 array('{% transchoice count from "messages" %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
77 'There is no apples', array('count' => 0)),
78 array('{% transchoice count %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
79 'There is 5 apples', array('count' => 5)),
80 array('{% transchoice count %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%){% endtranschoice %}',
81 'There is 5 apples (Symfony2)', array('count' => 5, 'name' => 'Symfony2')),
82 array('{% transchoice count with { \'%name%\': \'Symfony2\' } %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%){% endtranschoice %}',
83 'There is 5 apples (Symfony2)', array('count' => 5)),
84 array('{% transchoice count into "fr"%}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
85 'There is no apples', array('count' => 0)),
86
87 // trans filter
88 array('{{ "Hello"|trans }}', 'Hello'),
89 array('{{ name|trans }}', 'Symfony2', array('name' => 'Symfony2')),
90 array('{{ hello|trans({ \'%name%\': \'Symfony2\' }) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')),
91 array('{% set vars = { \'%name%\': \'Symfony2\' } %}{{ hello|trans(vars) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')),
92 array('{{ "Hello"|trans({}, "messages", "fr") }}', 'Hello'),
93
94 // transchoice filter
95 array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count) }}', 'There is 5 apples', array('count' => 5)),
96 array('{{ text|transchoice(5, {\'%name%\': \'Symfony2\'}) }}', 'There is 5 apples (Symfony2)', array('text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)')),
97 array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count, {}, "messages", "fr") }}', 'There is 5 apples', array('count' => 5)),
98 );
99 }
100
101 public function testDefaultTranslationDomain()
102 {
103 $templates = array(
104 'index' => '
105 {%- extends "base" %}
106
107 {%- trans_default_domain "foo" %}
108
109 {%- block content %}
110 {%- trans %}foo{% endtrans %}
111 {%- trans from "custom" %}foo{% endtrans %}
112 {{- "foo"|trans }}
113 {{- "foo"|trans({}, "custom") }}
114 {{- "foo"|transchoice(1) }}
115 {{- "foo"|transchoice(1, {}, "custom") }}
116 {% endblock %}
117 ',
118
119 'base' => '
120 {%- block content "" %}
121 ',
122 );
123
124 $translator = new Translator('en', new MessageSelector());
125 $translator->addLoader('array', new ArrayLoader());
126 $translator->addResource('array', array('foo' => 'foo (messages)'), 'en');
127 $translator->addResource('array', array('foo' => 'foo (custom)'), 'en', 'custom');
128 $translator->addResource('array', array('foo' => 'foo (foo)'), 'en', 'foo');
129
130 $template = $this->getTemplate($templates, $translator);
131
132 $this->assertEquals('foo (foo)foo (custom)foo (foo)foo (custom)foo (foo)foo (custom)', trim($template->render(array())));
133 }
134
135 protected function getTemplate($template, $translator = null)
136 {
137 if (null === $translator) {
138 $translator = new Translator('en', new MessageSelector());
139 }
140
141 if (is_array($template)) {
142 $loader = new \Twig_Loader_Array($template);
143 } else {
144 $loader = new \Twig_Loader_Array(array('index' => $template));
145 }
146 $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
147 $twig->addExtension(new TranslationExtension($translator));
148
149 return $twig->loadTemplate('index');
150 }
151}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/child_label.html.twig b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/child_label.html.twig
deleted file mode 100644
index 8c7c2489..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/child_label.html.twig
+++ /dev/null
@@ -1,3 +0,0 @@
1{% block form_label %}
2 <label>{{ global }}child</label>
3{% endblock form_label %}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/custom_widgets.html.twig b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/custom_widgets.html.twig
deleted file mode 100644
index 12fd7c66..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/custom_widgets.html.twig
+++ /dev/null
@@ -1,16 +0,0 @@
1{% block _text_id_widget %}
2{% spaceless %}
3 <div id="container">
4 {{ form_widget(form) }}
5 </div>
6{% endspaceless %}
7{% endblock _text_id_widget %}
8
9{% block _name_entry_label %}
10{% spaceless %}
11 {% if label is empty %}
12 {% set label = name|humanize %}
13 {% endif %}
14 <label>Custom label: {{ label|trans({}, translation_domain) }}</label>
15{% endspaceless %}
16{% endblock _name_entry_label %}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/parent_label.html.twig b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/parent_label.html.twig
deleted file mode 100644
index e96278b8..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/parent_label.html.twig
+++ /dev/null
@@ -1,3 +0,0 @@
1{% block form_label %}
2 <label>parent</label>
3{% endblock form_label %}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme.html.twig b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme.html.twig
deleted file mode 100644
index da1c1b64..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme.html.twig
+++ /dev/null
@@ -1,6 +0,0 @@
1{% block form_widget_simple %}
2{% spaceless %}
3 {% set type = type|default('text') %}
4 <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
5{% endspaceless %}
6{% endblock form_widget_simple %}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_extends.html.twig b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_extends.html.twig
deleted file mode 100644
index 8c719867..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_extends.html.twig
+++ /dev/null
@@ -1,8 +0,0 @@
1{% extends 'form_div_layout.html.twig' %}
2
3{% block form_widget_simple %}
4{% spaceless %}
5 {% set type = type|default('text') %}
6 <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
7{% endspaceless %}
8{% endblock form_widget_simple %}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_use.html.twig b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_use.html.twig
deleted file mode 100644
index d485b8d0..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_use.html.twig
+++ /dev/null
@@ -1,8 +0,0 @@
1{% use 'form_div_layout.html.twig' %}
2
3{% block form_widget_simple %}
4{% spaceless %}
5 {% set type = type|default('text') %}
6 <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
7{% endspaceless %}
8{% endblock form_widget_simple %}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
deleted file mode 100644
index 90afef12..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
+++ /dev/null
@@ -1,85 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Node;
13
14use Symfony\Bridge\Twig\Tests\TestCase;
15use Symfony\Bridge\Twig\Node\FormThemeNode;
16
17class FormThemeTest extends TestCase
18{
19 protected function setUp()
20 {
21 parent::setUp();
22
23 if (version_compare(\Twig_Environment::VERSION, '1.5.0', '<')) {
24 $this->markTestSkipped('Requires Twig version to be at least 1.5.0.');
25 }
26 }
27
28 public function testConstructor()
29 {
30 $form = new \Twig_Node_Expression_Name('form', 0);
31 $resources = new \Twig_Node(array(
32 new \Twig_Node_Expression_Constant('tpl1', 0),
33 new \Twig_Node_Expression_Constant('tpl2', 0)
34 ));
35
36 $node = new FormThemeNode($form, $resources, 0);
37
38 $this->assertEquals($form, $node->getNode('form'));
39 $this->assertEquals($resources, $node->getNode('resources'));
40 }
41
42 public function testCompile()
43 {
44 $form = new \Twig_Node_Expression_Name('form', 0);
45 $resources = new \Twig_Node_Expression_Array(array(
46 new \Twig_Node_Expression_Constant(0, 0),
47 new \Twig_Node_Expression_Constant('tpl1', 0),
48 new \Twig_Node_Expression_Constant(1, 0),
49 new \Twig_Node_Expression_Constant('tpl2', 0)
50 ), 0);
51
52 $node = new FormThemeNode($form, $resources, 0);
53
54 $compiler = new \Twig_Compiler(new \Twig_Environment());
55
56 $this->assertEquals(
57 sprintf(
58 '$this->env->getExtension(\'form\')->renderer->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"));',
59 $this->getVariableGetter('form')
60 ),
61 trim($compiler->compile($node)->getSource())
62 );
63
64 $resources = new \Twig_Node_Expression_Constant('tpl1', 0);
65
66 $node = new FormThemeNode($form, $resources, 0);
67
68 $this->assertEquals(
69 sprintf(
70 '$this->env->getExtension(\'form\')->renderer->setTheme(%s, "tpl1");',
71 $this->getVariableGetter('form')
72 ),
73 trim($compiler->compile($node)->getSource())
74 );
75 }
76
77 protected function getVariableGetter($name)
78 {
79 if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
80 return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
81 }
82
83 return sprintf('$this->getContext($context, "%s")', $name);
84 }
85}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php
deleted file mode 100644
index c1f247ca..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php
+++ /dev/null
@@ -1,282 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Node;
13
14use Symfony\Bridge\Twig\Tests\TestCase;
15use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode;
16
17class SearchAndRenderBlockNodeTest extends TestCase
18{
19 protected function setUp()
20 {
21 parent::setUp();
22
23 if (version_compare(\Twig_Environment::VERSION, '1.5.0', '<')) {
24 $this->markTestSkipped('Requires Twig version to be at least 1.5.0.');
25 }
26 }
27
28 public function testCompileWidget()
29 {
30 $arguments = new \Twig_Node(array(
31 new \Twig_Node_Expression_Name('form', 0),
32 ));
33
34 $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);
35
36 $compiler = new \Twig_Compiler(new \Twig_Environment());
37
38 $this->assertEquals(
39 sprintf(
40 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'widget\')',
41 $this->getVariableGetter('form')
42 ),
43 trim($compiler->compile($node)->getSource())
44 );
45 }
46
47 public function testCompileWidgetWithVariables()
48 {
49 $arguments = new \Twig_Node(array(
50 new \Twig_Node_Expression_Name('form', 0),
51 new \Twig_Node_Expression_Array(array(
52 new \Twig_Node_Expression_Constant('foo', 0),
53 new \Twig_Node_Expression_Constant('bar', 0),
54 ), 0),
55 ));
56
57 $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);
58
59 $compiler = new \Twig_Compiler(new \Twig_Environment());
60
61 $this->assertEquals(
62 sprintf(
63 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'widget\', array("foo" => "bar"))',
64 $this->getVariableGetter('form')
65 ),
66 trim($compiler->compile($node)->getSource())
67 );
68 }
69
70 public function testCompileLabelWithLabel()
71 {
72 $arguments = new \Twig_Node(array(
73 new \Twig_Node_Expression_Name('form', 0),
74 new \Twig_Node_Expression_Constant('my label', 0),
75 ));
76
77 $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
78
79 $compiler = new \Twig_Compiler(new \Twig_Environment());
80
81 $this->assertEquals(
82 sprintf(
83 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("label" => "my label"))',
84 $this->getVariableGetter('form')
85 ),
86 trim($compiler->compile($node)->getSource())
87 );
88 }
89
90 public function testCompileLabelWithNullLabel()
91 {
92 $arguments = new \Twig_Node(array(
93 new \Twig_Node_Expression_Name('form', 0),
94 new \Twig_Node_Expression_Constant(null, 0),
95 ));
96
97 $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
98
99 $compiler = new \Twig_Compiler(new \Twig_Environment());
100
101 // "label" => null must not be included in the output!
102 // Otherwise the default label is overwritten with null.
103 $this->assertEquals(
104 sprintf(
105 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')',
106 $this->getVariableGetter('form')
107 ),
108 trim($compiler->compile($node)->getSource())
109 );
110 }
111
112 public function testCompileLabelWithEmptyStringLabel()
113 {
114 $arguments = new \Twig_Node(array(
115 new \Twig_Node_Expression_Name('form', 0),
116 new \Twig_Node_Expression_Constant('', 0),
117 ));
118
119 $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
120
121 $compiler = new \Twig_Compiler(new \Twig_Environment());
122
123 // "label" => null must not be included in the output!
124 // Otherwise the default label is overwritten with null.
125 $this->assertEquals(
126 sprintf(
127 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')',
128 $this->getVariableGetter('form')
129 ),
130 trim($compiler->compile($node)->getSource())
131 );
132 }
133
134 public function testCompileLabelWithDefaultLabel()
135 {
136 $arguments = new \Twig_Node(array(
137 new \Twig_Node_Expression_Name('form', 0),
138 ));
139
140 $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
141
142 $compiler = new \Twig_Compiler(new \Twig_Environment());
143
144 $this->assertEquals(
145 sprintf(
146 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')',
147 $this->getVariableGetter('form')
148 ),
149 trim($compiler->compile($node)->getSource())
150 );
151 }
152
153 public function testCompileLabelWithAttributes()
154 {
155 $arguments = new \Twig_Node(array(
156 new \Twig_Node_Expression_Name('form', 0),
157 new \Twig_Node_Expression_Constant(null, 0),
158 new \Twig_Node_Expression_Array(array(
159 new \Twig_Node_Expression_Constant('foo', 0),
160 new \Twig_Node_Expression_Constant('bar', 0),
161 ), 0),
162 ));
163
164 $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
165
166 $compiler = new \Twig_Compiler(new \Twig_Environment());
167
168 // "label" => null must not be included in the output!
169 // Otherwise the default label is overwritten with null.
170 // https://github.com/symfony/symfony/issues/5029
171 $this->assertEquals(
172 sprintf(
173 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar"))',
174 $this->getVariableGetter('form')
175 ),
176 trim($compiler->compile($node)->getSource())
177 );
178 }
179
180 public function testCompileLabelWithLabelAndAttributes()
181 {
182 $arguments = new \Twig_Node(array(
183 new \Twig_Node_Expression_Name('form', 0),
184 new \Twig_Node_Expression_Constant('value in argument', 0),
185 new \Twig_Node_Expression_Array(array(
186 new \Twig_Node_Expression_Constant('foo', 0),
187 new \Twig_Node_Expression_Constant('bar', 0),
188 new \Twig_Node_Expression_Constant('label', 0),
189 new \Twig_Node_Expression_Constant('value in attributes', 0),
190 ), 0),
191 ));
192
193 $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
194
195 $compiler = new \Twig_Compiler(new \Twig_Environment());
196
197 $this->assertEquals(
198 sprintf(
199 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in argument"))',
200 $this->getVariableGetter('form')
201 ),
202 trim($compiler->compile($node)->getSource())
203 );
204 }
205
206 public function testCompileLabelWithLabelThatEvaluatesToNull()
207 {
208 $arguments = new \Twig_Node(array(
209 new \Twig_Node_Expression_Name('form', 0),
210 new \Twig_Node_Expression_Conditional(
211 // if
212 new \Twig_Node_Expression_Constant(true, 0),
213 // then
214 new \Twig_Node_Expression_Constant(null, 0),
215 // else
216 new \Twig_Node_Expression_Constant(null, 0),
217 0
218 ),
219 ));
220
221 $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
222
223 $compiler = new \Twig_Compiler(new \Twig_Environment());
224
225 // "label" => null must not be included in the output!
226 // Otherwise the default label is overwritten with null.
227 // https://github.com/symfony/symfony/issues/5029
228 $this->assertEquals(
229 sprintf(
230 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))',
231 $this->getVariableGetter('form')
232 ),
233 trim($compiler->compile($node)->getSource())
234 );
235 }
236
237 public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
238 {
239 $arguments = new \Twig_Node(array(
240 new \Twig_Node_Expression_Name('form', 0),
241 new \Twig_Node_Expression_Conditional(
242 // if
243 new \Twig_Node_Expression_Constant(true, 0),
244 // then
245 new \Twig_Node_Expression_Constant(null, 0),
246 // else
247 new \Twig_Node_Expression_Constant(null, 0),
248 0
249 ),
250 new \Twig_Node_Expression_Array(array(
251 new \Twig_Node_Expression_Constant('foo', 0),
252 new \Twig_Node_Expression_Constant('bar', 0),
253 new \Twig_Node_Expression_Constant('label', 0),
254 new \Twig_Node_Expression_Constant('value in attributes', 0),
255 ), 0),
256 ));
257
258 $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
259
260 $compiler = new \Twig_Compiler(new \Twig_Environment());
261
262 // "label" => null must not be included in the output!
263 // Otherwise the default label is overwritten with null.
264 // https://github.com/symfony/symfony/issues/5029
265 $this->assertEquals(
266 sprintf(
267 '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in attributes") + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))',
268 $this->getVariableGetter('form')
269 ),
270 trim($compiler->compile($node)->getSource())
271 );
272 }
273
274 protected function getVariableGetter($name)
275 {
276 if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
277 return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
278 }
279
280 return sprintf('$this->getContext($context, "%s")', $name);
281 }
282}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/ScopeTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/ScopeTest.php
deleted file mode 100644
index bcae5919..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/ScopeTest.php
+++ /dev/null
@@ -1,25 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\NodeVisitor;
13
14use Symfony\Bridge\Twig\NodeVisitor\Scope;
15use Symfony\Bridge\Twig\Tests\TestCase;
16
17class ScopeTest extends TestCase
18{
19 public function testScopeInitiation()
20 {
21 $scope = new Scope();
22 $scope->enter();
23 $this->assertNull($scope->get('test'));
24 }
25}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php
deleted file mode 100644
index 24a6215e..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php
+++ /dev/null
@@ -1,83 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\NodeVisitor;
13
14use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
15use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
16use Symfony\Bridge\Twig\Tests\TestCase;
17
18class 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}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php
deleted file mode 100644
index 4e3ee6fd..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php
+++ /dev/null
@@ -1,61 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\NodeVisitor;
13
14use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
15use Symfony\Bridge\Twig\Tests\TestCase;
16
17class 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}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php
deleted file mode 100644
index 277e7774..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php
+++ /dev/null
@@ -1,77 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\NodeVisitor;
13
14use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
15use Symfony\Bridge\Twig\Node\TransNode;
16
17class TwigNodeProvider
18{
19 public static function getModule($content)
20 {
21 return new \Twig_Node_Module(
22 new \Twig_Node_Expression_Constant($content, 0),
23 null,
24 new \Twig_Node_Expression_Array(array(), 0),
25 new \Twig_Node_Expression_Array(array(), 0),
26 new \Twig_Node_Expression_Array(array(), 0),
27 null,
28 null
29 );
30 }
31
32 public static function getTransFilter($message, $domain = null)
33 {
34 $arguments = $domain ? array(
35 new \Twig_Node_Expression_Array(array(), 0),
36 new \Twig_Node_Expression_Constant($domain, 0),
37 ) : array();
38
39 return new \Twig_Node_Expression_Filter(
40 new \Twig_Node_Expression_Constant($message, 0),
41 new \Twig_Node_Expression_Constant('trans', 0),
42 new \Twig_Node($arguments),
43 0
44 );
45 }
46
47 public static function getTransChoiceFilter($message, $domain = null)
48 {
49 $arguments = $domain ? array(
50 new \Twig_Node_Expression_Constant(0, 0),
51 new \Twig_Node_Expression_Array(array(), 0),
52 new \Twig_Node_Expression_Constant($domain, 0),
53 ) : array();
54
55 return new \Twig_Node_Expression_Filter(
56 new \Twig_Node_Expression_Constant($message, 0),
57 new \Twig_Node_Expression_Constant('transchoice', 0),
58 new \Twig_Node($arguments),
59 0
60 );
61 }
62
63 public static function getTransTag($message, $domain = null)
64 {
65 return new TransNode(
66 new \Twig_Node_Body(array(), array('data' => $message)),
67 $domain ? new \Twig_Node_Expression_Constant($domain, 0) : null
68 );
69 }
70
71 public static function getTransDefaultDomainTag($domain)
72 {
73 return new TransDefaultDomainNode(
74 new \Twig_Node_Expression_Constant($domain, 0)
75 );
76 }
77}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/TestCase.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/TestCase.php
deleted file mode 100644
index ecfb7daf..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/TestCase.php
+++ /dev/null
@@ -1,22 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests;
13
14abstract class TestCase extends \PHPUnit_Framework_TestCase
15{
16 protected function setUp()
17 {
18 if (!class_exists('Twig_Environment')) {
19 $this->markTestSkipped('Twig is not available.');
20 }
21 }
22}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php
deleted file mode 100644
index 077cd76a..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php
+++ /dev/null
@@ -1,108 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Node;
13
14use Symfony\Bridge\Twig\Tests\TestCase;
15use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
16use Symfony\Bridge\Twig\Node\FormThemeNode;
17
18class FormThemeTokenParserTest extends TestCase
19{
20 protected function setUp()
21 {
22 parent::setUp();
23
24 if (version_compare(\Twig_Environment::VERSION, '1.5.0', '<')) {
25 $this->markTestSkipped('Requires Twig version to be at least 1.5.0.');
26 }
27 }
28
29 /**
30 * @dataProvider getTestsForFormTheme
31 */
32 public function testCompile($source, $expected)
33 {
34 $env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
35 $env->addTokenParser(new FormThemeTokenParser());
36 $stream = $env->tokenize($source);
37 $parser = new \Twig_Parser($env);
38
39 $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
40 }
41
42 public function getTestsForFormTheme()
43 {
44 return array(
45 array(
46 '{% form_theme form "tpl1" %}',
47 new FormThemeNode(
48 new \Twig_Node_Expression_Name('form', 1),
49 new \Twig_Node_Expression_Array(array(
50 new \Twig_Node_Expression_Constant(0, 1),
51 new \Twig_Node_Expression_Constant('tpl1', 1),
52 ), 1),
53 1,
54 'form_theme'
55 )
56 ),
57 array(
58 '{% form_theme form "tpl1" "tpl2" %}',
59 new FormThemeNode(
60 new \Twig_Node_Expression_Name('form', 1),
61 new \Twig_Node_Expression_Array(array(
62 new \Twig_Node_Expression_Constant(0, 1),
63 new \Twig_Node_Expression_Constant('tpl1', 1),
64 new \Twig_Node_Expression_Constant(1, 1),
65 new \Twig_Node_Expression_Constant('tpl2', 1)
66 ), 1),
67 1,
68 'form_theme'
69 )
70 ),
71 array(
72 '{% form_theme form with "tpl1" %}',
73 new FormThemeNode(
74 new \Twig_Node_Expression_Name('form', 1),
75 new \Twig_Node_Expression_Constant('tpl1', 1),
76 1,
77 'form_theme'
78 )
79 ),
80 array(
81 '{% form_theme form with ["tpl1"] %}',
82 new FormThemeNode(
83 new \Twig_Node_Expression_Name('form', 1),
84 new \Twig_Node_Expression_Array(array(
85 new \Twig_Node_Expression_Constant(0, 1),
86 new \Twig_Node_Expression_Constant('tpl1', 1),
87 ), 1),
88 1,
89 'form_theme'
90 )
91 ),
92 array(
93 '{% form_theme form with ["tpl1", "tpl2"] %}',
94 new FormThemeNode(
95 new \Twig_Node_Expression_Name('form', 1),
96 new \Twig_Node_Expression_Array(array(
97 new \Twig_Node_Expression_Constant(0, 1),
98 new \Twig_Node_Expression_Constant('tpl1', 1),
99 new \Twig_Node_Expression_Constant(1, 1),
100 new \Twig_Node_Expression_Constant('tpl2', 1)
101 ), 1),
102 1,
103 'form_theme'
104 )
105 ),
106 );
107 }
108}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php
deleted file mode 100644
index a2c5cd3d..00000000
--- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php
+++ /dev/null
@@ -1,81 +0,0 @@
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
12namespace Symfony\Bridge\Twig\Tests\Translation;
13
14use Symfony\Bridge\Twig\Extension\TranslationExtension;
15use Symfony\Bridge\Twig\Translation\TwigExtractor;
16use Symfony\Component\Translation\MessageCatalogue;
17use Symfony\Bridge\Twig\Tests\TestCase;
18
19class TwigExtractorTest extends TestCase
20{
21 protected function setUp()
22 {
23 if (!class_exists('Symfony\Component\Translation\Translator')) {
24 $this->markTestSkipped('The "Translation" component is not available');
25 }
26 }
27
28 /**
29 * @dataProvider getExtractData
30 */
31 public function testExtract($template, $messages)
32 {
33 $loader = new \Twig_Loader_Array(array());
34 $twig = new \Twig_Environment($loader, array(
35 'strict_variables' => true,
36 'debug' => true,
37 'cache' => false,
38 'autoescape' => false,
39 ));
40 $twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
41
42 $extractor = new TwigExtractor($twig);
43 $extractor->setPrefix('prefix');
44 $catalogue = new MessageCatalogue('en');
45
46 $m = new \ReflectionMethod($extractor, 'extractTemplate');
47 $m->setAccessible(true);
48 $m->invoke($extractor, $template, $catalogue);
49
50 foreach ($messages as $key => $domain) {
51 $this->assertTrue($catalogue->has($key, $domain));
52 $this->assertEquals('prefix'.$key, $catalogue->get($key, $domain));
53 }
54 }
55
56 public function getExtractData()
57 {
58 return array(
59 array('{{ "new key" | trans() }}', array('new key' => 'messages')),
60 array('{{ "new key" | trans() | upper }}', array('new key' => 'messages')),
61 array('{{ "new key" | trans({}, "domain") }}', array('new key' => 'domain')),
62 array('{{ "new key" | transchoice(1) }}', array('new key' => 'messages')),
63 array('{{ "new key" | transchoice(1) | upper }}', array('new key' => 'messages')),
64 array('{{ "new key" | transchoice(1, {}, "domain") }}', array('new key' => 'domain')),
65 array('{% trans %}new key{% endtrans %}', array('new key' => 'messages')),
66 array('{% trans %} new key {% endtrans %}', array('new key' => 'messages')),
67 array('{% trans from "domain" %}new key{% endtrans %}', array('new key' => 'domain')),
68 array('{% set foo = "new key" | trans %}', array('new key' => 'messages')),
69 array('{{ 1 ? "new key" | trans : "another key" | trans }}', array('new key' => 'messages', 'another key' => 'messages')),
70
71 // make sure 'trans_default_domain' tag is supported
72 array('{% trans_default_domain "domain" %}{{ "new key"|trans }}', array('new key' => 'domain')),
73 array('{% trans_default_domain "domain" %}{{ "new key"|transchoice }}', array('new key' => 'domain')),
74 array('{% trans_default_domain "domain" %}{% trans %}new key{% endtrans %}', array('new key' => 'domain')),
75
76 // make sure this works with twig's named arguments
77 array('{{ "new key" | trans(domain="domain") }}', array('new key' => 'domain')),
78 array('{{ "new key" | transchoice(domain="domain", count=1) }}', array('new key' => 'domain')),
79 );
80 }
81}