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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Tests\Bridge\Twig\Extension;
|
|
|
|
|
2011-04-14 02:38:19 +01:00
|
|
|
require_once __DIR__.'/Fixtures/StubTranslator.php';
|
2011-04-14 12:46:11 +01:00
|
|
|
require_once __DIR__.'/Fixtures/StubFilesystemLoader.php';
|
2011-04-14 02:38:19 +01:00
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
use Symfony\Component\Form\FormView;
|
2011-04-14 02:15:56 +01:00
|
|
|
use Symfony\Bridge\Twig\Extension\FormExtension;
|
|
|
|
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
|
|
|
use Symfony\Tests\Component\Form\AbstractDivLayoutTest;
|
2011-04-14 02:38:19 +01:00
|
|
|
use Symfony\Tests\Bridge\Twig\Extension\Fixtures\StubTranslator;
|
2011-04-14 12:46:11 +01:00
|
|
|
use Symfony\Tests\Bridge\Twig\Extension\Fixtures\StubFilesystemLoader;
|
2011-04-14 02:15:56 +01:00
|
|
|
|
|
|
|
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
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
|
|
|
));
|
|
|
|
|
2011-05-04 14:33:17 +01:00
|
|
|
$this->extension = new FormExtension(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-11 09:11:29 +01:00
|
|
|
public function testThemeBlockInheritance()
|
|
|
|
{
|
|
|
|
$view = $this->factory
|
|
|
|
->createNamed('email', 'name')
|
|
|
|
->createView()
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->extension->setTheme($view, array('theme.html.twig'));
|
|
|
|
|
|
|
|
$this->assertMatchesXpath(
|
|
|
|
$this->renderWidget($view),
|
|
|
|
'/input[@type="email"][@rel="theme"]'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testThemeBlockInheritanceUsingUse()
|
|
|
|
{
|
|
|
|
$view = $this->factory
|
|
|
|
->createNamed('email', 'name')
|
|
|
|
->createView()
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->extension->setTheme($view, array('theme_use.html.twig'));
|
|
|
|
|
|
|
|
$this->assertMatchesXpath(
|
|
|
|
$this->renderWidget($view),
|
|
|
|
'/input[@type="email"][@rel="theme"]'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testThemeBlockInheritanceUsingExtend()
|
|
|
|
{
|
|
|
|
$view = $this->factory
|
|
|
|
->createNamed('email', 'name')
|
|
|
|
->createView()
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->extension->setTheme($view, array('theme_extends.html.twig'));
|
|
|
|
|
|
|
|
$this->assertMatchesXpath(
|
|
|
|
$this->renderWidget($view),
|
|
|
|
'/input[@type="email"][@rel="theme"]'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-08 13:20:37 +01:00
|
|
|
public function testThemeInheritance()
|
|
|
|
{
|
|
|
|
$child = $this->factory->createNamedBuilder('form', 'child')
|
|
|
|
->add('field', 'text')
|
|
|
|
->getForm();
|
|
|
|
|
|
|
|
$view = $this->factory->createNamedBuilder('form', 'parent')
|
|
|
|
->add('field', 'text')
|
|
|
|
->getForm()
|
|
|
|
->add($child)
|
|
|
|
->createView()
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->extension->setTheme($view, array('parent_label.html.twig'));
|
|
|
|
$this->extension->setTheme($view['child'], array('child_label.html.twig'));
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($view, array(),
|
|
|
|
'/div
|
|
|
|
[
|
|
|
|
./input[@type="hidden"]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./label[.="parent"]
|
|
|
|
/following-sibling::input[@type="text"]
|
|
|
|
]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./label
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./div
|
|
|
|
[
|
|
|
|
./label[.="child"]
|
|
|
|
/following-sibling::input[@type="text"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|