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\Component\Form;
|
|
|
|
|
|
|
|
use Symfony\Component\Form\FormError;
|
|
|
|
|
|
|
|
abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
|
|
|
{
|
|
|
|
public function testRow()
|
|
|
|
{
|
|
|
|
$form = $this->factory->create('text', 'name');
|
|
|
|
$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"]
|
|
|
|
]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRepeatedRow()
|
|
|
|
{
|
|
|
|
$form = $this->factory->create('repeated', 'name');
|
|
|
|
$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,
|
|
|
|
'/ul
|
|
|
|
[./li[.="[trans]Error![/trans]"]]
|
|
|
|
[count(./li)=1]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./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()
|
|
|
|
{
|
2011-04-14 14:02:51 +01:00
|
|
|
$view = $this->factory->createBuilder('form', 'name')
|
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
|
|
|
|
|
|
|
// Render field2 row -> does not implicitely call renderWidget because
|
|
|
|
// 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,
|
|
|
|
'/input
|
|
|
|
[@type="hidden"]
|
|
|
|
[@id="name__token"]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./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]
|
2011-04-14 02:15:56 +01:00
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollection()
|
|
|
|
{
|
|
|
|
$form = $this->factory->create('collection', 'name', array(
|
|
|
|
'type' => 'text',
|
|
|
|
'data' => array('a', 'b'),
|
|
|
|
));
|
|
|
|
|
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]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testForm()
|
|
|
|
{
|
|
|
|
$form = $this->factory->createBuilder('form', 'name')
|
|
|
|
->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
|
|
|
|
[
|
|
|
|
./input[@type="hidden"][@id="name__token"]
|
|
|
|
/following-sibling::div
|
|
|
|
[
|
|
|
|
./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"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
[count(.//input)=3]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRepeated()
|
|
|
|
{
|
|
|
|
$form = $this->factory->create('repeated', 'name', array(
|
|
|
|
'type' => 'text',
|
|
|
|
'data' => 'foobar',
|
|
|
|
));
|
|
|
|
|
2011-04-15 12:52:11 +01:00
|
|
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
2011-04-14 02:15:56 +01:00
|
|
|
'/div
|
|
|
|
[
|
|
|
|
./div
|
|
|
|
[
|
|
|
|
./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"]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
[count(.//input)=2]
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|