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()
|
|
|
|
{
|
2012-03-28 14:43:52 +01:00
|
|
|
if (!class_exists('Symfony\Component\Locale\Locale')) {
|
|
|
|
$this->markTestSkipped('The "Locale" component is not available');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
|
|
|
|
$this->markTestSkipped('The "EventDispatcher" component is not available');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('Symfony\Component\Form\Form')) {
|
|
|
|
$this->markTestSkipped('The "Form" component is not available');
|
|
|
|
}
|
|
|
|
|
2011-05-14 11:23:40 +01:00
|
|
|
if (!class_exists('Twig_Environment')) {
|
|
|
|
$this->markTestSkipped('Twig is not available.');
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:38:19 +01:00
|
|
|
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',
|
|
|
|
));
|
2012-07-15 17:58:13 +01:00
|
|
|
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'));
|
|
|
|
|
|
|
|
$this->extension = new FormExtension($renderer);
|
|
|
|
|
|
|
|
$loader = new StubFilesystemLoader(array(
|
|
|
|
__DIR__.'/../../Resources/views/Form',
|
|
|
|
__DIR__,
|
|
|
|
));
|
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;
|
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderEnctype(FormView $view)
|
2011-04-14 02:38:19 +01:00
|
|
|
{
|
2012-07-15 17:58:13 +01:00
|
|
|
return (string) $this->extension->renderer->renderEnctype($view);
|
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-15 17:58:13 +01:00
|
|
|
return (string) $this->extension->renderer->renderLabel($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-15 17:58:13 +01:00
|
|
|
return (string) $this->extension->renderer->renderErrors($view);
|
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-15 17:58:13 +01:00
|
|
|
return (string) $this->extension->renderer->renderWidget($view, $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-15 17:58:13 +01:00
|
|
|
return (string) $this->extension->renderer->renderRow($view, $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-15 17:58:13 +01:00
|
|
|
return (string) $this->extension->renderer->renderRest($view, $vars);
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|
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
|
|
|
}
|