2011-04-14 02:15:56 +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 02:15:56 +01:00
|
|
|
use Symfony\Bridge\Twig\Extension\FormExtension;
|
|
|
|
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
2012-03-28 14:43:52 +01:00
|
|
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
|
|
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
2012-05-12 17:52:27 +01:00
|
|
|
use Symfony\Component\Form\FormView;
|
|
|
|
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
|
2011-04-14 02:15:56 +01:00
|
|
|
|
|
|
|
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
|
|
|
{
|
2011-06-21 16:46:13 +01:00
|
|
|
protected $extension;
|
|
|
|
|
2011-04-14 02:15:56 +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:15:56 +01:00
|
|
|
parent::setUp();
|
|
|
|
|
2011-04-14 12:46:11 +01:00
|
|
|
$loader = new StubFilesystemLoader(array(
|
2011-06-07 15:32:42 +01:00
|
|
|
__DIR__.'/../../../../../../src/Symfony/Bridge/Twig/Resources/views/Form',
|
2011-05-04 14:33:17 +01:00
|
|
|
__DIR__,
|
2011-04-14 02:15:56 +01:00
|
|
|
));
|
|
|
|
|
2012-01-10 12:55:48 +00:00
|
|
|
$this->extension = new FormExtension($this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'), array(
|
2011-06-16 14:18:25 +01:00
|
|
|
'form_div_layout.html.twig',
|
2011-05-04 14:33:17 +01:00
|
|
|
'custom_widgets.html.twig',
|
|
|
|
));
|
2011-04-14 02:15:56 +01:00
|
|
|
|
|
|
|
$environment = new \Twig_Environment($loader);
|
|
|
|
$environment->addExtension($this->extension);
|
|
|
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
|
|
|
|
|
|
|
$this->extension->initRuntime($environment);
|
|
|
|
}
|
|
|
|
|
2011-06-14 09:44:38 +01:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
$this->extension = null;
|
|
|
|
}
|
|
|
|
|
2011-06-11 09:11:29 +01:00
|
|
|
public function testThemeBlockInheritanceUsingUse()
|
|
|
|
{
|
|
|
|
$view = $this->factory
|
|
|
|
->createNamed('email', 'name')
|
|
|
|
->createView()
|
|
|
|
;
|
|
|
|
|
2011-06-21 16:46:13 +01:00
|
|
|
$this->setTheme($view, array('theme_use.html.twig'));
|
2011-06-11 09:11:29 +01:00
|
|
|
|
|
|
|
$this->assertMatchesXpath(
|
|
|
|
$this->renderWidget($view),
|
|
|
|
'/input[@type="email"][@rel="theme"]'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testThemeBlockInheritanceUsingExtend()
|
|
|
|
{
|
|
|
|
$view = $this->factory
|
|
|
|
->createNamed('email', 'name')
|
|
|
|
->createView()
|
|
|
|
;
|
|
|
|
|
2011-06-21 16:46:13 +01:00
|
|
|
$this->setTheme($view, array('theme_extends.html.twig'));
|
2011-06-11 09:11:29 +01:00
|
|
|
|
|
|
|
$this->assertMatchesXpath(
|
|
|
|
$this->renderWidget($view),
|
|
|
|
'/input[@type="email"][@rel="theme"]'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderEnctype(FormView $view)
|
2011-04-14 02:15:56 +01:00
|
|
|
{
|
2011-04-14 14:02:51 +01:00
|
|
|
return (string)$this->extension->renderEnctype($view);
|
2011-04-14 02:15:56 +01:00
|
|
|
}
|
|
|
|
|
2011-06-01 09:08:18 +01:00
|
|
|
protected function renderLabel(FormView $view, $label = null, array $vars = array())
|
2011-04-14 02:15:56 +01:00
|
|
|
{
|
2011-06-01 09:08:18 +01:00
|
|
|
return (string)$this->extension->renderLabel($view, $label, $vars);
|
2011-04-14 02:15:56 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderErrors(FormView $view)
|
2011-04-14 02:15:56 +01:00
|
|
|
{
|
2011-04-14 14:02:51 +01:00
|
|
|
return (string)$this->extension->renderErrors($view);
|
2011-04-14 02:15:56 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderWidget(FormView $view, array $vars = array())
|
2011-04-14 02:15:56 +01:00
|
|
|
{
|
2011-04-14 14:02:51 +01:00
|
|
|
return (string)$this->extension->renderWidget($view, $vars);
|
2011-04-14 02:15:56 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderRow(FormView $view, array $vars = array())
|
2011-04-14 02:15:56 +01:00
|
|
|
{
|
2011-04-14 14:02:51 +01:00
|
|
|
return (string)$this->extension->renderRow($view, $vars);
|
2011-04-14 02:15:56 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
protected function renderRest(FormView $view, array $vars = array())
|
2011-04-14 02:15:56 +01:00
|
|
|
{
|
2011-04-14 14:02:51 +01:00
|
|
|
return (string)$this->extension->renderRest($view, $vars);
|
2011-04-14 02:15:56 +01:00
|
|
|
}
|
2011-06-21 16:46:13 +01:00
|
|
|
|
|
|
|
protected function setTheme(FormView $view, array $themes)
|
|
|
|
{
|
|
|
|
$this->extension->setTheme($view, $themes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function themeBlockInheritanceProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(array('theme.html.twig'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function themeInheritanceProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(array('parent_label.html.twig'), array('child_label.html.twig'))
|
|
|
|
);
|
|
|
|
}
|
2011-04-14 02:15:56 +01:00
|
|
|
}
|