123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?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->createNamed('text', 'name');
- $form->addError(new FormError('Error!'));
- $view = $form->createView();
- $html = $this->renderRow($view);
- $this->assertMatchesXpath($html,
- '/div
- [
- ./label[@for="name"]
- /following-sibling::ul
- [./li[.="[trans]Error![/trans]"]]
- [count(./li)=1]
- /following-sibling::input[@id="name"]
- ]
- '
- );
- }
- public function testRowForwardsVariables()
- {
- $view = $this->factory->createNamed('text', 'name')->createView();
- $html = $this->renderRow($view, array('label' => 'foo&bar'));
- $this->assertMatchesXpath($html,
- '/div
- [
- ./label[@for="name"][.="[trans]foo&bar[/trans]"]
- /following-sibling::input[@id="name"]
- ]
- '
- );
- }
- public function testRepeatedRow()
- {
- $form = $this->factory->createNamed('repeated', 'name');
- $form->addError(new FormError('Error!'));
- $view = $form->createView();
- $html = $this->renderRow($view);
- $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()
- {
- $view = $this->factory->createNamedBuilder('form', 'name')
- ->add('field1', 'text')
- ->add('field2', 'repeated')
- ->add('field3', 'text')
- ->add('field4', 'text')
- ->getForm()
- ->createView();
- // Render field2 row -> does not implicitely call renderWidget because
- // it is a repeated field!
- $this->renderRow($view['field2']);
- // Render field3 widget
- $this->renderWidget($view['field3']);
- // Rest should only contain field1 and field4
- $html = $this->renderRest($view);
- $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"]
- ]
- [count(../div)=2]
- [count(..//label)=2]
- [count(..//input)=3]
- '
- );
- }
- public function testCollection()
- {
- $form = $this->factory->createNamed('collection', 'name', array('a', 'b'), array(
- 'type' => 'text',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/div
- [
- ./div[./input[@type="text"][@value="a"]]
- /following-sibling::div[./input[@type="text"][@value="b"]]
- ]
- [count(./div[./input])=2]
- '
- );
- }
- public function testForm()
- {
- $form = $this->factory->createNamedBuilder('form', 'name')
- ->add('firstName', 'text')
- ->add('lastName', 'text')
- ->getForm();
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/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->createNamed('repeated', 'name', 'foobar', array(
- 'type' => 'text',
- ));
- $this->assertWidgetMatchesXpath($form->createView(), array(),
- '/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]
- '
- );
- }
- }
|