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\Component\Form\Tests;
|
2011-04-14 02:15:56 +01:00
|
|
|
|
|
|
|
use Symfony\Component\Form\FormError;
|
|
|
|
|
|
|
|
abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
|
|
|
{
|
|
|
|
public function testRow()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'text');
|
2011-04-14 02:15:56 +01:00
|
|
|
$form->addError(new FormError('Error!'));
|
2011-04-15 12:52:11 +01:00
|
|
|
$view = $form->createView();
|
2011-04-14 14:02:51 +01:00
|
|
|
$html = $this->renderRow($view);
|
2011-04-14 02:15:56 +01:00
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
|
|
|
'/div
|
|
|
|
[
|
|
|
|
./label[@for="name"]
|
|
|
|
/following-sibling::ul
|
|
|
|
[./li[.="[trans]Error![/trans]"]]
|
|
|
|
[count(./li)=1]
|
|
|
|
/following-sibling::input[@id="name"]
|
|
|
|
]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-20 08:35:17 +01:00
|
|
|
public function testRowOverrideVariables()
|
2011-05-04 14:40:15 +01:00
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$view = $this->factory->createNamed('name', 'text')->createView();
|
2012-07-25 12:20:23 +01:00
|
|
|
$html = $this->renderRow($view, array(
|
|
|
|
'attr' => array('class' => 'my&class'),
|
|
|
|
'label' => 'foo&bar',
|
|
|
|
'label_attr' => array('class' => 'my&label&class'),
|
|
|
|
));
|
2011-05-04 14:40:15 +01:00
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
2011-06-22 07:36:45 +01:00
|
|
|
'/div
|
2011-05-04 14:40:15 +01:00
|
|
|
[
|
2012-07-25 12:20:23 +01:00
|
|
|
./label[@for="name"][@class="my&label&class required"][.="[trans]foo&bar[/trans]"]
|
|
|
|
/following-sibling::input[@id="name"][@class="my&class"]
|
2011-05-04 14:40:15 +01:00
|
|
|
]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:15:56 +01:00
|
|
|
public function testRepeatedRow()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'repeated');
|
2011-04-14 02:15:56 +01:00
|
|
|
$form->addError(new FormError('Error!'));
|
2011-04-15 12:52:11 +01:00
|
|
|
$view = $form->createView();
|
2011-04-14 14:02:51 +01:00
|
|
|
$html = $this->renderRow($view);
|
2011-04-14 02:15:56 +01:00
|
|
|
|
2012-07-09 15:09:12 +01:00
|
|
|
// The errors of the form are not rendered by intention!
|
|
|
|
// In practice, repeated fields cannot have errors as all errors
|
|
|
|
// on them are mapped to the first child.
|
|
|
|
// (see RepeatedTypeValidatorExtension)
|
|
|
|
|
2011-04-14 02:15:56 +01:00
|
|
|
$this->assertMatchesXpath($html,
|
2012-07-09 15:09:12 +01:00
|
|
|
'/div
|
2011-04-14 02:15:56 +01:00
|
|
|
[
|
|
|
|
./label[@for="name_first"]
|
|
|
|
/following-sibling::input[@id="name_first"]
|
|
|
|
]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./label[@for="name_second"]
|
|
|
|
/following-sibling::input[@id="name_second"]
|
|
|
|
]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRest()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'form')
|
2011-04-14 02:15:56 +01:00
|
|
|
->add('field1', 'text')
|
|
|
|
->add('field2', 'repeated')
|
|
|
|
->add('field3', 'text')
|
|
|
|
->add('field4', 'text')
|
2011-04-14 13:42:17 +01:00
|
|
|
->getForm()
|
2011-04-15 12:52:11 +01:00
|
|
|
->createView();
|
2011-04-14 02:15:56 +01:00
|
|
|
|
2011-06-12 21:52:53 +01:00
|
|
|
// Render field2 row -> does not implicitly call renderWidget because
|
2011-04-14 02:15:56 +01:00
|
|
|
// it is a repeated field!
|
2011-04-14 14:02:51 +01:00
|
|
|
$this->renderRow($view['field2']);
|
2011-04-14 02:15:56 +01:00
|
|
|
|
|
|
|
// Render field3 widget
|
2011-04-14 14:02:51 +01:00
|
|
|
$this->renderWidget($view['field3']);
|
2011-04-14 02:15:56 +01:00
|
|
|
|
|
|
|
// Rest should only contain field1 and field4
|
2011-04-14 14:02:51 +01:00
|
|
|
$html = $this->renderRest($view);
|
2011-04-14 02:15:56 +01:00
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
2012-04-19 09:37:16 +01:00
|
|
|
'/div
|
2011-04-14 02:15:56 +01:00
|
|
|
[
|
|
|
|
./label[@for="name_field1"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_field1"]
|
|
|
|
]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./label[@for="name_field4"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_field4"]
|
|
|
|
]
|
2011-04-14 02:38:19 +01:00
|
|
|
[count(../div)=2]
|
|
|
|
[count(..//label)=2]
|
|
|
|
[count(..//input)=3]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
2011-04-14 02:15:56 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-06 11:30:28 +01:00
|
|
|
public function testRestWithChildrenForms()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$child1 = $this->factory->createNamedBuilder('child1', 'form')
|
2011-06-06 11:30:28 +01:00
|
|
|
->add('field1', 'text')
|
|
|
|
->add('field2', 'text')
|
|
|
|
->getForm();
|
|
|
|
|
2012-05-23 20:50:13 +01:00
|
|
|
$child2 = $this->factory->createNamedBuilder('child2', 'form')
|
2011-06-06 11:30:28 +01:00
|
|
|
->add('field1', 'text')
|
|
|
|
->add('field2', 'text')
|
|
|
|
->getForm();
|
|
|
|
|
2012-05-23 20:50:13 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('parent', 'form')
|
2011-06-06 11:30:28 +01:00
|
|
|
->getForm()
|
|
|
|
->add($child1)
|
|
|
|
->add($child2)
|
|
|
|
->createView();
|
|
|
|
|
|
|
|
// Render child1.field1 row
|
|
|
|
$this->renderRow($view['child1']['field1']);
|
|
|
|
|
|
|
|
// Render child2.field2 widget (remember that widget don't render label)
|
|
|
|
$this->renderWidget($view['child2']['field2']);
|
|
|
|
|
|
|
|
// Rest should only contain child1.field2 and child2.field1
|
|
|
|
$html = $this->renderRest($view);
|
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
2012-04-19 09:37:16 +01:00
|
|
|
'/div
|
2011-06-06 11:30:28 +01:00
|
|
|
[
|
2011-06-06 16:18:43 +01:00
|
|
|
./label[not(@for)]
|
2011-06-06 16:15:11 +01:00
|
|
|
/following-sibling::div[@id="parent_child1"]
|
2011-06-06 11:30:28 +01:00
|
|
|
[
|
|
|
|
./div
|
|
|
|
[
|
|
|
|
./label[@for="parent_child1_field2"]
|
|
|
|
/following-sibling::input[@id="parent_child1_field2"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2011-06-06 16:15:11 +01:00
|
|
|
|
2011-06-06 11:30:28 +01:00
|
|
|
/following-sibling::div
|
|
|
|
[
|
2011-06-06 16:18:43 +01:00
|
|
|
./label[not(@for)]
|
2011-06-06 16:15:11 +01:00
|
|
|
/following-sibling::div[@id="parent_child2"]
|
2011-06-06 11:30:28 +01:00
|
|
|
[
|
|
|
|
./div
|
|
|
|
[
|
|
|
|
./label[@for="parent_child2_field1"]
|
|
|
|
/following-sibling::input[@id="parent_child2_field1"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2011-06-06 16:15:11 +01:00
|
|
|
[count(//label)=4]
|
|
|
|
[count(//input[@type="text"])=2]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input[@type="hidden"][@id="parent__token"]
|
2011-06-06 11:30:28 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRestAndRepeatedWithRow()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'form')
|
2011-06-06 11:30:28 +01:00
|
|
|
->add('first', 'text')
|
|
|
|
->add('password', 'repeated')
|
|
|
|
->getForm()
|
|
|
|
->createView();
|
|
|
|
|
|
|
|
$this->renderRow($view['password']);
|
|
|
|
|
|
|
|
$html = $this->renderRest($view);
|
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
2012-04-19 09:37:16 +01:00
|
|
|
'/div
|
2011-06-06 11:30:28 +01:00
|
|
|
[
|
|
|
|
./label[@for="name_first"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_first"]
|
|
|
|
]
|
|
|
|
[count(.//input)=1]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
2011-06-06 11:30:28 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-13 15:06:32 +01:00
|
|
|
public function testRestAndRepeatedWithRowPerChild()
|
2011-06-06 11:30:28 +01:00
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'form')
|
2011-06-06 11:30:28 +01:00
|
|
|
->add('first', 'text')
|
|
|
|
->add('password', 'repeated')
|
|
|
|
->getForm()
|
|
|
|
->createView();
|
|
|
|
|
|
|
|
$this->renderRow($view['password']['first']);
|
|
|
|
$this->renderRow($view['password']['second']);
|
|
|
|
|
|
|
|
$html = $this->renderRest($view);
|
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
2012-04-19 09:37:16 +01:00
|
|
|
'/div
|
2011-06-06 11:30:28 +01:00
|
|
|
[
|
|
|
|
./label[@for="name_first"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_first"]
|
|
|
|
]
|
|
|
|
[count(.//input)=1]
|
|
|
|
[count(.//label)=1]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
2011-06-06 11:30:28 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-13 15:06:32 +01:00
|
|
|
public function testRestAndRepeatedWithWidgetPerChild()
|
2011-06-06 11:30:28 +01:00
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'form')
|
2011-06-06 11:30:28 +01:00
|
|
|
->add('first', 'text')
|
|
|
|
->add('password', 'repeated')
|
|
|
|
->getForm()
|
|
|
|
->createView();
|
|
|
|
|
2011-09-24 14:28:16 +01:00
|
|
|
// The password form is considered as rendered as all its children
|
2011-06-06 11:30:28 +01:00
|
|
|
// are rendered
|
|
|
|
$this->renderWidget($view['password']['first']);
|
|
|
|
$this->renderWidget($view['password']['second']);
|
|
|
|
|
|
|
|
$html = $this->renderRest($view);
|
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
2012-04-19 09:37:16 +01:00
|
|
|
'/div
|
2011-06-06 11:30:28 +01:00
|
|
|
[
|
|
|
|
./label[@for="name_first"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_first"]
|
|
|
|
]
|
|
|
|
[count(//input)=2]
|
|
|
|
[count(//label)=1]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
2011-06-06 11:30:28 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:15:56 +01:00
|
|
|
public function testCollection()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'collection', array('a', 'b'), array(
|
2011-04-14 02:15:56 +01:00
|
|
|
'type' => 'text',
|
|
|
|
));
|
|
|
|
|
2011-04-15 12:52:11 +01:00
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
2011-04-14 02:15:56 +01:00
|
|
|
'/div
|
2011-04-14 02:38:19 +01:00
|
|
|
[
|
|
|
|
./div[./input[@type="text"][@value="a"]]
|
2011-04-14 02:15:56 +01:00
|
|
|
/following-sibling::div[./input[@type="text"][@value="b"]]
|
|
|
|
]
|
|
|
|
[count(./div[./input])=2]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-20 17:42:21 +01:00
|
|
|
public function testEmptyCollection()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'collection', array(), array(
|
2012-04-20 17:42:21 +01:00
|
|
|
'type' => 'text',
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/div
|
2012-04-20 17:58:52 +01:00
|
|
|
[./input[@type="hidden"][@id="name__token"]]
|
2012-04-20 17:42:21 +01:00
|
|
|
[count(./div)=0]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-06 13:21:49 +01:00
|
|
|
public function testCollectionRow()
|
|
|
|
{
|
|
|
|
$collection = $this->factory->createNamedBuilder(
|
|
|
|
'collection',
|
|
|
|
'collection',
|
|
|
|
array('a', 'b'),
|
|
|
|
array('type' => 'text')
|
|
|
|
);
|
|
|
|
|
|
|
|
$form = $this->factory->createNamedBuilder('form', 'form')
|
|
|
|
->add($collection)
|
|
|
|
->getForm();
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/div
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./div
|
2011-06-06 13:21:49 +01:00
|
|
|
[
|
|
|
|
./label[not(@for)]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./div
|
|
|
|
[
|
|
|
|
./label[@for="form_collection_0"]
|
|
|
|
/following-sibling::input[@type="text"][@value="a"]
|
|
|
|
]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./label[@for="form_collection_1"]
|
|
|
|
/following-sibling::input[@type="text"][@value="b"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input[@type="hidden"][@id="form__token"]
|
2011-06-06 13:21:49 +01:00
|
|
|
]
|
|
|
|
[count(.//input)=3]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:15:56 +01:00
|
|
|
public function testForm()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamedBuilder('name', 'form')
|
2011-04-14 02:15:56 +01:00
|
|
|
->add('firstName', 'text')
|
|
|
|
->add('lastName', 'text')
|
|
|
|
->getForm();
|
|
|
|
|
2011-04-15 12:52:11 +01:00
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
2011-04-14 02:15:56 +01:00
|
|
|
'/div
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./div
|
2011-04-14 02:15:56 +01:00
|
|
|
[
|
|
|
|
./label[@for="name_firstName"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_firstName"]
|
|
|
|
]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./label[@for="name_lastName"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_lastName"]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input[@type="hidden"][@id="name__token"]
|
2011-04-14 02:15:56 +01:00
|
|
|
]
|
|
|
|
[count(.//input)=3]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-02-10 10:41:19 +00:00
|
|
|
// https://github.com/symfony/symfony/issues/2308
|
|
|
|
public function testNestedFormError()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamedBuilder('name', 'form')
|
2012-04-13 15:06:32 +01:00
|
|
|
->add($this->factory
|
2012-05-23 20:50:13 +01:00
|
|
|
->createNamedBuilder('child', 'form', null, array('error_bubbling' => false))
|
2012-04-13 15:06:32 +01:00
|
|
|
->add('grandChild', 'form')
|
|
|
|
)
|
2012-02-10 10:41:19 +00:00
|
|
|
->getForm();
|
|
|
|
|
|
|
|
$form->get('child')->addError(new FormError('Error!'));
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/div
|
|
|
|
[
|
2012-07-09 15:09:12 +01:00
|
|
|
./div/label
|
|
|
|
/following-sibling::ul[./li[.="[trans]Error![/trans]"]]
|
2012-02-10 10:41:19 +00:00
|
|
|
]
|
|
|
|
[count(.//li[.="[trans]Error![/trans]"])=1]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-13 13:11:09 +01:00
|
|
|
public function testCsrf()
|
|
|
|
{
|
|
|
|
$this->csrfProvider->expects($this->any())
|
|
|
|
->method('generateCsrfToken')
|
|
|
|
->will($this->returnValue('foo&bar'));
|
|
|
|
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamedBuilder('name', 'form')
|
2012-04-13 13:11:09 +01:00
|
|
|
->add($this->factory
|
|
|
|
// No CSRF protection on nested forms
|
2012-05-23 20:50:13 +01:00
|
|
|
->createNamedBuilder('child', 'form')
|
|
|
|
->add($this->factory->createNamedBuilder('grandchild', 'text'))
|
2012-04-13 13:11:09 +01:00
|
|
|
)
|
|
|
|
->getForm();
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/div
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./div
|
|
|
|
/following-sibling::input[@type="hidden"][@id="name__token"][@value="foo&bar"]
|
2012-04-13 13:11:09 +01:00
|
|
|
]
|
|
|
|
[count(.//input[@type="hidden"])=1]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:15:56 +01:00
|
|
|
public function testRepeated()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'repeated', 'foobar', array(
|
2011-04-14 02:15:56 +01:00
|
|
|
'type' => 'text',
|
|
|
|
));
|
|
|
|
|
2011-04-15 12:52:11 +01:00
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
2011-04-14 02:15:56 +01:00
|
|
|
'/div
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./div
|
2011-04-14 02:15:56 +01:00
|
|
|
[
|
|
|
|
./label[@for="name_first"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_first"]
|
|
|
|
]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./label[@for="name_second"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_second"]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input[@type="hidden"][@id="name__token"]
|
2011-04-14 02:15:56 +01:00
|
|
|
]
|
2012-04-13 13:11:09 +01:00
|
|
|
[count(.//input)=3]
|
2011-06-06 17:17:22 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-27 12:07:16 +01:00
|
|
|
public function testRepeatedWithCustomOptions()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'repeated', null, array(
|
2011-09-24 15:42:12 +01:00
|
|
|
// the global required value cannot be overriden
|
|
|
|
'first_options' => array('label' => 'Test', 'required' => false),
|
2011-06-27 12:07:16 +01:00
|
|
|
'second_options' => array('label' => 'Test2')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/div
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./div
|
2011-06-27 12:07:16 +01:00
|
|
|
[
|
|
|
|
./label[@for="name_first"][.="[trans]Test[/trans]"]
|
2011-09-24 09:44:47 +01:00
|
|
|
/following-sibling::input[@type="text"][@id="name_first"][@required="required"]
|
2011-06-27 12:07:16 +01:00
|
|
|
]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./label[@for="name_second"][.="[trans]Test2[/trans]"]
|
|
|
|
/following-sibling::input[@type="text"][@id="name_second"][@required="required"]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input[@type="hidden"][@id="name__token"]
|
2011-06-27 12:07:16 +01:00
|
|
|
]
|
2012-04-13 13:11:09 +01:00
|
|
|
[count(.//input)=3]
|
2011-06-27 12:07:16 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-06 17:17:22 +01:00
|
|
|
public function testSearchInputName()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamedBuilder('full', 'form')
|
2011-06-06 17:17:22 +01:00
|
|
|
->add('name', 'search')
|
|
|
|
->getForm();
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/div
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./div
|
2011-06-06 17:17:22 +01:00
|
|
|
[
|
|
|
|
./label[@for="full_name"]
|
|
|
|
/following-sibling::input[@type="search"][@id="full_name"][@name="full[name]"]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input[@type="hidden"][@id="full__token"]
|
2011-06-06 17:17:22 +01:00
|
|
|
]
|
|
|
|
[count(//input)=2]
|
2011-06-06 19:12:03 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLabelHasNoId()
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'text');
|
2011-06-06 19:12:03 +01:00
|
|
|
$html = $this->renderRow($form->createView());
|
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
|
|
|
'/div
|
|
|
|
[
|
|
|
|
./label[@for="name"][not(@id)]
|
|
|
|
/following-sibling::input[@id="name"]
|
|
|
|
]
|
2011-06-21 16:46:13 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider themeBlockInheritanceProvider
|
|
|
|
*/
|
|
|
|
public function testThemeBlockInheritance($theme)
|
|
|
|
{
|
|
|
|
$view = $this->factory
|
2012-05-23 20:50:13 +01:00
|
|
|
->createNamed('name', 'email')
|
2011-06-21 16:46:13 +01:00
|
|
|
->createView()
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->setTheme($view, $theme);
|
|
|
|
|
|
|
|
$this->assertMatchesXpath(
|
|
|
|
$this->renderWidget($view),
|
|
|
|
'/input[@type="email"][@rel="theme"]'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider themeInheritanceProvider
|
|
|
|
*/
|
|
|
|
public function testThemeInheritance($parentTheme, $childTheme)
|
|
|
|
{
|
2012-05-23 20:50:13 +01:00
|
|
|
$child = $this->factory->createNamedBuilder('child', 'form')
|
2011-06-21 16:46:13 +01:00
|
|
|
->add('field', 'text')
|
|
|
|
->getForm();
|
|
|
|
|
2012-05-23 20:50:13 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('parent', 'form')
|
2011-06-21 16:46:13 +01:00
|
|
|
->add('field', 'text')
|
|
|
|
->getForm()
|
|
|
|
->add($child)
|
|
|
|
->createView()
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->setTheme($view, $parentTheme);
|
|
|
|
$this->setTheme($view['child'], $childTheme);
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($view, array(),
|
|
|
|
'/div
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./div
|
2011-06-21 16:46:13 +01:00
|
|
|
[
|
|
|
|
./label[.="parent"]
|
|
|
|
/following-sibling::input[@type="text"]
|
|
|
|
]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
2012-07-15 17:58:13 +01:00
|
|
|
./label[.="child"]
|
2011-06-21 16:46:13 +01:00
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./div
|
|
|
|
[
|
|
|
|
./label[.="child"]
|
|
|
|
/following-sibling::input[@type="text"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::input[@type="hidden"]
|
2011-06-21 16:46:13 +01:00
|
|
|
]
|
2012-07-14 11:08:26 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The block "_name_child_label" should be overridden in the theme of the
|
|
|
|
* implemented driver.
|
|
|
|
*/
|
|
|
|
public function testCollectionRowWithCustomBlock()
|
|
|
|
{
|
|
|
|
$collection = array('one', 'two', 'three');
|
|
|
|
$form = $this->factory->createNamedBuilder('name', 'collection', $collection)
|
|
|
|
->getForm();
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/div
|
|
|
|
[
|
|
|
|
./div[./label[.="Custom label: [trans]0[/trans]"]]
|
|
|
|
/following-sibling::div[./label[.="Custom label: [trans]1[/trans]"]]
|
|
|
|
/following-sibling::div[./label[.="Custom label: [trans]2[/trans]"]]
|
|
|
|
]
|
2011-04-14 02:15:56 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|