]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
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\Extension; | |
13 | ||
14 | use Symfony\Component\Form\FormView; | |
15 | use Symfony\Bridge\Twig\Form\TwigRenderer; | |
16 | use Symfony\Bridge\Twig\Form\TwigRendererEngine; | |
17 | use Symfony\Bridge\Twig\Extension\FormExtension; | |
18 | use Symfony\Bridge\Twig\Extension\TranslationExtension; | |
19 | use Symfony\Component\Form\Tests\AbstractTableLayoutTest; | |
20 | use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator; | |
21 | use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader; | |
22 | ||
23 | class 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 | } |