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\Component\Form\Tests;
|
2011-04-14 02:38:19 +01:00
|
|
|
|
|
|
|
use Symfony\Component\Form\FormError;
|
2013-10-04 14:25:38 +01:00
|
|
|
use Symfony\Component\Security\Csrf\CsrfToken;
|
2011-04-14 02:38:19 +01:00
|
|
|
|
|
|
|
abstract class AbstractTableLayoutTest extends AbstractLayoutTest
|
|
|
|
{
|
|
|
|
public function testRow()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
2012-11-27 22:17:30 +00:00
|
|
|
$form->addError(new FormError('[trans]Error![/trans]'));
|
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:38:19 +01:00
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
|
|
|
'/tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[
|
|
|
|
./ul
|
|
|
|
[./li[.="[trans]Error![/trans]"]]
|
|
|
|
[count(./li)=1]
|
|
|
|
/following-sibling::input[@id="name"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-12-11 08:37:25 +00:00
|
|
|
public function testLabelIsNotRenderedWhenSetToFalse()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
|
2014-09-21 19:53:12 +01:00
|
|
|
'label' => false,
|
2012-12-11 08:37:25 +00:00
|
|
|
));
|
|
|
|
$html = $this->renderRow($form->createView());
|
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
|
|
|
'/tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[count(//label)=0]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name"]]
|
|
|
|
]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:38:19 +01:00
|
|
|
public function testRepeatedRow()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RepeatedType');
|
2011-04-15 12:52:11 +01:00
|
|
|
$html = $this->renderRow($form->createView());
|
2011-04-14 02:38:19 +01:00
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
2012-04-19 09:37:16 +01:00
|
|
|
'/tr
|
2011-04-14 02:38:19 +01:00
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_first"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_first"]]
|
|
|
|
]
|
|
|
|
/following-sibling::tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_second"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_second"]]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
]
|
2012-07-09 15:09:12 +01:00
|
|
|
[count(../tr)=3]
|
2011-04-14 02:38:19 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRepeatedRowWithErrors()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RepeatedType');
|
2012-11-27 22:17:30 +00:00
|
|
|
$form->addError(new FormError('[trans]Error![/trans]'));
|
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:38:19 +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:38:19 +01:00
|
|
|
$this->assertMatchesXpath($html,
|
|
|
|
'/tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_first"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_first"]]
|
|
|
|
]
|
|
|
|
/following-sibling::tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_second"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_second"]]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
]
|
2012-07-09 15:09:12 +01:00
|
|
|
[count(../tr)=3]
|
2011-04-14 02:38:19 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-12-31 14:29:36 +00:00
|
|
|
public function testButtonRow()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ButtonType');
|
2012-12-31 14:29:36 +00:00
|
|
|
$view = $form->createView();
|
|
|
|
$html = $this->renderRow($view);
|
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
|
|
|
'/tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[.=""]
|
|
|
|
/following-sibling::td
|
|
|
|
[./button[@type="button"][@name="name"]]
|
|
|
|
]
|
|
|
|
[count(//label)=0]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:38:19 +01:00
|
|
|
public function testRest()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
|
|
|
->add('field1', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
|
|
|
->add('field2', 'Symfony\Component\Form\Extension\Core\Type\RepeatedType')
|
|
|
|
->add('field3', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
|
|
|
->add('field4', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
2011-04-14 13:42:17 +01:00
|
|
|
->getForm()
|
2011-04-15 12:52:11 +01:00
|
|
|
->createView();
|
2011-04-14 02:38:19 +01:00
|
|
|
|
2012-07-28 23:02:29 +01:00
|
|
|
// Render field2 row -> does not implicitly call renderWidget because
|
2011-04-14 02:38:19 +01:00
|
|
|
// it is a repeated field!
|
2011-04-14 14:02:51 +01:00
|
|
|
$this->renderRow($view['field2']);
|
2011-04-14 02:38:19 +01:00
|
|
|
|
|
|
|
// Render field3 widget
|
2011-04-14 14:02:51 +01:00
|
|
|
$this->renderWidget($view['field3']);
|
2011-04-14 02:38:19 +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:38:19 +01:00
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
2012-04-19 09:37:16 +01:00
|
|
|
'/tr
|
2011-04-14 02:38:19 +01:00
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_field1"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_field1"]]
|
|
|
|
]
|
|
|
|
/following-sibling::tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_field4"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_field4"]]
|
|
|
|
]
|
|
|
|
[count(../tr)=3]
|
|
|
|
[count(..//label)=2]
|
|
|
|
[count(..//input)=3]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
]
|
2011-04-14 02:38:19 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollection()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('names', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', array('a', 'b'), array(
|
2015-10-13 21:03:48 +01:00
|
|
|
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
2011-04-14 02:38:19 +01:00
|
|
|
));
|
|
|
|
|
2011-04-15 12:52:11 +01:00
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
2011-04-14 02:38:19 +01:00
|
|
|
'/table
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./tr[./td/input[@type="text"][@value="a"]]
|
2011-04-14 02:38:19 +01:00
|
|
|
/following-sibling::tr[./td/input[@type="text"][@value="b"]]
|
2013-09-13 16:21:38 +01:00
|
|
|
/following-sibling::tr[@style="display: none"][./td[@colspan="2"]/input[@type="hidden"][@id="names__token"]]
|
2011-04-14 02:38:19 +01:00
|
|
|
]
|
2011-06-10 21:18:09 +01:00
|
|
|
[count(./tr[./td/input])=3]
|
2011-04-14 02:38:19 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-20 17:42:21 +01:00
|
|
|
public function testEmptyCollection()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('names', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
2015-10-13 21:03:48 +01:00
|
|
|
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
2012-04-20 17:42:21 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/table
|
2013-09-13 16:21:38 +01:00
|
|
|
[./tr[@style="display: none"][./td[@colspan="2"]/input[@type="hidden"][@id="names__token"]]]
|
2012-04-20 17:58:52 +01:00
|
|
|
[count(./tr[./td/input])=1]
|
2012-04-20 17:42:21 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:38:19 +01:00
|
|
|
public function testForm()
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
2012-12-30 15:38:36 +00:00
|
|
|
->setMethod('PUT')
|
|
|
|
->setAction('http://example.com')
|
2015-06-23 17:42:21 +01:00
|
|
|
->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
|
|
|
->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
2012-12-30 15:38:36 +00:00
|
|
|
->getForm()
|
|
|
|
->createView();
|
|
|
|
|
|
|
|
$html = $this->renderForm($view, array(
|
|
|
|
'id' => 'my&id',
|
|
|
|
'attr' => array('class' => 'my&class'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertMatchesXpath($html,
|
|
|
|
'/form
|
|
|
|
[
|
|
|
|
./input[@type="hidden"][@name="_method"][@value="PUT"]
|
|
|
|
/following-sibling::table
|
|
|
|
[
|
|
|
|
./tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_firstName"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_firstName"]]
|
|
|
|
]
|
|
|
|
/following-sibling::tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_lastName"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_lastName"]]
|
|
|
|
]
|
|
|
|
/following-sibling::tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
[count(.//input)=3]
|
|
|
|
[@id="my&id"]
|
|
|
|
[@class="my&class"]
|
|
|
|
]
|
|
|
|
[@method="post"]
|
|
|
|
[@action="http://example.com"]
|
|
|
|
[@class="my&class"]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFormWidget()
|
2011-04-14 02:38:19 +01:00
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
|
|
|
->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
|
|
|
->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
2011-04-14 13:42:17 +01:00
|
|
|
->getForm()
|
2011-04-15 12:52:11 +01:00
|
|
|
->createView();
|
2011-04-14 02:38:19 +01:00
|
|
|
|
2011-04-14 14:02:51 +01:00
|
|
|
$this->assertWidgetMatchesXpath($view, array(),
|
2011-04-14 02:38:19 +01:00
|
|
|
'/table
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./tr
|
2011-04-14 02:38:19 +01:00
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_firstName"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_firstName"]]
|
|
|
|
]
|
|
|
|
/following-sibling::tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_lastName"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_lastName"]]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
]
|
2011-04-14 02:38:19 +01:00
|
|
|
]
|
|
|
|
[count(.//input)=3]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-02-10 10:41:19 +00:00
|
|
|
// https://github.com/symfony/symfony/issues/2308
|
|
|
|
public function testNestedFormError()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
2012-04-13 15:06:32 +01:00
|
|
|
->add($this->factory
|
2015-06-23 17:42:21 +01:00
|
|
|
->createNamedBuilder('child', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array('error_bubbling' => false))
|
|
|
|
->add('grandChild', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
2012-04-13 15:06:32 +01:00
|
|
|
)
|
2012-02-10 10:41:19 +00:00
|
|
|
->getForm();
|
|
|
|
|
2012-11-27 22:17:30 +00:00
|
|
|
$form->get('child')->addError(new FormError('[trans]Error![/trans]'));
|
2012-02-10 10:41:19 +00:00
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/table
|
|
|
|
[
|
2012-07-09 15:09:12 +01:00
|
|
|
./tr/td/ul[./li[.="[trans]Error![/trans]"]]
|
|
|
|
/following-sibling::table[@id="name_child"]
|
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()
|
|
|
|
{
|
2013-10-04 14:25:38 +01:00
|
|
|
$this->csrfTokenManager->expects($this->any())
|
|
|
|
->method('getToken')
|
|
|
|
->will($this->returnValue(new CsrfToken('token_id', 'foo&bar')));
|
2012-04-13 13:11:09 +01:00
|
|
|
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
2012-04-13 13:11:09 +01:00
|
|
|
->add($this->factory
|
|
|
|
// No CSRF protection on nested forms
|
2015-06-23 17:42:21 +01:00
|
|
|
->createNamedBuilder('child', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
|
|
|
->add($this->factory->createNamedBuilder('grandchild', 'Symfony\Component\Form\Extension\Core\Type\TextType'))
|
2012-04-13 13:11:09 +01:00
|
|
|
)
|
|
|
|
->getForm();
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/table
|
|
|
|
[
|
|
|
|
./tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
[count(.//input[@type="hidden"])=1]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:38:19 +01:00
|
|
|
public function testRepeated()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RepeatedType', 'foobar', array(
|
|
|
|
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
2011-04-14 02:38:19 +01:00
|
|
|
));
|
|
|
|
|
2011-04-15 12:52:11 +01:00
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
2011-04-14 02:38:19 +01:00
|
|
|
'/table
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./tr
|
2011-04-14 02:38:19 +01:00
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_first"]]
|
|
|
|
/following-sibling::td
|
2011-06-27 12:07:16 +01:00
|
|
|
[./input[@type="text"][@id="name_first"]]
|
2011-04-14 02:38:19 +01:00
|
|
|
]
|
|
|
|
/following-sibling::tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_second"]]
|
|
|
|
/following-sibling::td
|
2011-06-27 12:07:16 +01:00
|
|
|
[./input[@type="text"][@id="name_second"]]
|
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/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
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRepeatedWithCustomOptions()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\RepeatedType', 'foobar', array(
|
|
|
|
'type' => 'Symfony\Component\Form\Extension\Core\Type\PasswordType',
|
2014-10-22 19:27:13 +01:00
|
|
|
'first_options' => array('label' => 'Test', 'required' => false),
|
2014-09-21 19:53:12 +01:00
|
|
|
'second_options' => array('label' => 'Test2'),
|
2011-06-27 12:07:16 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/table
|
|
|
|
[
|
2012-04-19 09:37:16 +01:00
|
|
|
./tr
|
2011-06-27 12:07:16 +01:00
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_first"][.="[trans]Test[/trans]"]]
|
|
|
|
/following-sibling::td
|
2011-09-24 09:44:47 +01:00
|
|
|
[./input[@type="password"][@id="name_first"][@required="required"]]
|
2011-06-27 12:07:16 +01:00
|
|
|
]
|
|
|
|
/following-sibling::tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_second"][.="[trans]Test2[/trans]"]]
|
|
|
|
/following-sibling::td
|
2011-09-24 09:44:47 +01:00
|
|
|
[./input[@type="password"][@id="name_second"][@required="required"]]
|
2011-04-14 02:38:19 +01:00
|
|
|
]
|
2012-04-19 09:37:16 +01:00
|
|
|
/following-sibling::tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
]
|
2011-04-14 02:38:19 +01:00
|
|
|
]
|
2012-04-13 13:11:09 +01:00
|
|
|
[count(.//input)=3]
|
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');
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamedBuilder('names', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', $collection)
|
2012-07-14 11:08:26 +01:00
|
|
|
->getForm();
|
|
|
|
|
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
|
|
|
'/table
|
|
|
|
[
|
|
|
|
./tr[./td/label[.="Custom label: [trans]0[/trans]"]]
|
|
|
|
/following-sibling::tr[./td/label[.="Custom label: [trans]1[/trans]"]]
|
|
|
|
/following-sibling::tr[./td/label[.="Custom label: [trans]2[/trans]"]]
|
|
|
|
]
|
2011-04-14 02:38:19 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
2012-12-30 15:38:36 +00:00
|
|
|
|
|
|
|
public function testFormEndWithRest()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
|
|
|
->add('field1', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
|
|
|
->add('field2', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
2012-12-30 15:38:36 +00:00
|
|
|
->getForm()
|
|
|
|
->createView();
|
|
|
|
|
|
|
|
$this->renderWidget($view['field1']);
|
|
|
|
|
|
|
|
// Rest should only contain field2
|
|
|
|
$html = $this->renderEnd($view);
|
|
|
|
|
|
|
|
// Insert the start tag, the end tag should be rendered by the helper
|
|
|
|
// Unfortunately this is not valid HTML, because the surrounding table
|
|
|
|
// tag is missing. If someone renders a form with table layout
|
|
|
|
// manually, she should call form_rest() explicitly within the <table>
|
|
|
|
// tag.
|
2014-09-21 19:53:12 +01:00
|
|
|
$this->assertMatchesXpath('<form>'.$html,
|
2012-12-30 15:38:36 +00:00
|
|
|
'/form
|
|
|
|
[
|
|
|
|
./tr
|
|
|
|
[
|
|
|
|
./td
|
|
|
|
[./label[@for="name_field2"]]
|
|
|
|
/following-sibling::td
|
|
|
|
[./input[@id="name_field2"]]
|
|
|
|
]
|
|
|
|
/following-sibling::tr[@style="display: none"]
|
|
|
|
[./td[@colspan="2"]/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFormEndWithoutRest()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$view = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
|
|
|
->add('field1', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
|
|
|
->add('field2', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
2012-12-30 15:38:36 +00:00
|
|
|
->getForm()
|
|
|
|
->createView();
|
|
|
|
|
|
|
|
$this->renderWidget($view['field1']);
|
|
|
|
|
|
|
|
// Rest should only contain field2, but isn't rendered
|
|
|
|
$html = $this->renderEnd($view, array('render_rest' => false));
|
|
|
|
|
|
|
|
$this->assertEquals('</form>', $html);
|
|
|
|
}
|
2013-09-30 13:07:24 +01:00
|
|
|
|
|
|
|
public function testWidgetContainerAttributes()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('form', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
2013-09-30 13:07:24 +01:00
|
|
|
'attr' => array('class' => 'foobar', 'data-foo' => 'bar'),
|
|
|
|
));
|
|
|
|
|
2015-06-23 17:42:21 +01:00
|
|
|
$form->add('text', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
2013-09-30 13:07:24 +01:00
|
|
|
|
|
|
|
$html = $this->renderWidget($form->createView());
|
|
|
|
|
|
|
|
// compare plain HTML to check the whitespace
|
|
|
|
$this->assertContains('<table id="form" class="foobar" data-foo="bar">', $html);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWidgetContainerAttributeNameRepeatedIfTrue()
|
|
|
|
{
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('form', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
2013-09-30 13:07:24 +01:00
|
|
|
'attr' => array('foo' => true),
|
|
|
|
));
|
|
|
|
|
|
|
|
$html = $this->renderWidget($form->createView());
|
|
|
|
|
|
|
|
// foo="foo"
|
|
|
|
$this->assertContains('<table id="form" foo="foo">', $html);
|
|
|
|
}
|
2011-04-14 02:38:19 +01:00
|
|
|
}
|