2011-04-14 02:38:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2012-03-28 14:43:52 +01:00
|
|
|
namespace Symfony\Bridge\Twig\Tests\Extension;
|
2011-04-14 02:38:19 +01:00
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
use Symfony\Component\Form\FormView;
|
2012-07-15 17:58:13 +01:00
|
|
|
use Symfony\Bridge\Twig\Form\TwigRenderer;
|
|
|
|
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
|
2011-04-14 02:38:19 +01:00
|
|
|
use Symfony\Bridge\Twig\Extension\FormExtension;
|
|
|
|
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
2012-03-28 14:43:52 +01:00
|
|
|
use Symfony\Component\Form\Tests\AbstractTableLayoutTest;
|
|
|
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
|
|
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
2011-04-14 02:38:19 +01:00
|
|
|
|
|
|
|
class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
|
|
|
|
{
|
2012-07-15 17:58:13 +01:00
|
|
|
/**
|
|
|
|
* @var FormExtension
|
|
|
|
*/
|
2011-06-21 16:46:13 +01:00
|
|
|
protected $extension;
|
|
|
|
|
2011-04-14 02:38:19 +01:00
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2012-07-15 17:58:13 +01:00
|
|
|
$rendererEngine = new TwigRendererEngine(array(
|
2011-06-16 14:18:25 +01:00
|
|
|
'form_table_layout.html.twig',
|
2011-05-04 14:33:17 +01:00
|
|
|
'custom_widgets.html.twig',
|
|
|
|
));
|
2015-01-04 14:37:21 +00:00
|
|
|
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
|
2012-07-15 17:58:13 +01:00
|
|
|
|
|
|
|
$this->extension = new FormExtension($renderer);
|
|
|
|
|
|
|
|
$loader = new StubFilesystemLoader(array(
|
|
|
|
__DIR__.'/../../Resources/views/Form',
|
2015-01-03 18:21:43 +00:00
|
|
|
__DIR__.'/Fixtures/templates/form',
|
2012-07-15 17:58:13 +01:00
|
|
|
));
|
2011-04-14 02:38:19 +01:00
|
|
|
|
2012-07-10 10:41:19 +01:00
|
|
|
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
2011-04-14 02:38:19 +01:00
|
|
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
2012-07-10 10:41:19 +01:00
|
|
|
$environment->addGlobal('global', '');
|
2012-07-15 17:58:13 +01:00
|
|
|
$environment->addExtension($this->extension);
|
2011-04-14 02:38:19 +01:00
|
|
|
|
|
|
|
$this->extension->initRuntime($environment);
|
|
|
|
}
|
|
|
|
|
2011-06-14 09:44:38 +01:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
$this->extension = null;
|
|
|
|
}
|
|
|
|
|
2012-12-30 15:38:36 +00:00
|
|
|
protected function renderForm(FormView $view, array $vars = array())
|
|
|
|
{
|
|
|
|
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
|
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderEnctype(FormView $view)
|
2011-04-14 02:38:19 +01:00
|
|
|
{
|
2012-07-21 18:44:09 +01:00
|
|
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|
|
|
|
|
2011-06-01 09:08:18 +01:00
|
|
|
protected function renderLabel(FormView $view, $label = null, array $vars = array())
|
2011-04-14 02:38:19 +01:00
|
|
|
{
|
2012-07-21 18:44:09 +01:00
|
|
|
if ($label !== null) {
|
|
|
|
$vars += array('label' => $label);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderErrors(FormView $view)
|
2011-04-14 02:38:19 +01:00
|
|
|
{
|
2012-07-21 18:44:09 +01:00
|
|
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderWidget(FormView $view, array $vars = array())
|
2011-04-14 02:38:19 +01:00
|
|
|
{
|
2012-07-21 18:44:09 +01:00
|
|
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderRow(FormView $view, array $vars = array())
|
2011-04-14 02:38:19 +01:00
|
|
|
{
|
2012-07-21 18:44:09 +01:00
|
|
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderRest(FormView $view, array $vars = array())
|
2011-04-14 02:38:19 +01:00
|
|
|
{
|
2012-07-21 18:44:09 +01:00
|
|
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|
2011-06-21 16:46:13 +01:00
|
|
|
|
2012-12-30 15:38:36 +00:00
|
|
|
protected function renderStart(FormView $view, array $vars = array())
|
|
|
|
{
|
|
|
|
return (string) $this->extension->renderer->renderBlock($view, 'form_start', $vars);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderEnd(FormView $view, array $vars = array())
|
|
|
|
{
|
|
|
|
return (string) $this->extension->renderer->renderBlock($view, 'form_end', $vars);
|
|
|
|
}
|
|
|
|
|
2011-06-21 16:46:13 +01:00
|
|
|
protected function setTheme(FormView $view, array $themes)
|
|
|
|
{
|
2012-07-15 17:58:13 +01:00
|
|
|
$this->extension->renderer->setTheme($view, $themes);
|
2011-06-21 16:46:13 +01:00
|
|
|
}
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|