123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?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\Component\Form\Tests;
- abstract class AbstractBootstrap3HorizontalLayoutTest extends AbstractBootstrap3LayoutTest
- {
- public function testLabelOnForm()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType');
- $view = $form->createView();
- $this->renderWidget($view, array('label' => 'foo'));
- $html = $this->renderLabel($view);
- $this->assertMatchesXpath($html,
- '/label
- [@class="col-sm-2 control-label required"]
- [.="[trans]Name[/trans]"]
- '
- );
- }
- public function testLabelDoesNotRenderFieldAttributes()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
- $html = $this->renderLabel($form->createView(), null, array(
- 'attr' => array(
- 'class' => 'my&class',
- ),
- ));
- $this->assertMatchesXpath($html,
- '/label
- [@for="name"]
- [@class="col-sm-2 control-label required"]
- '
- );
- }
- public function testLabelWithCustomAttributesPassedDirectly()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
- $html = $this->renderLabel($form->createView(), null, array(
- 'label_attr' => array(
- 'class' => 'my&class',
- ),
- ));
- $this->assertMatchesXpath($html,
- '/label
- [@for="name"]
- [@class="my&class col-sm-2 control-label required"]
- '
- );
- }
- public function testLabelWithCustomTextAndCustomAttributesPassedDirectly()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
- $html = $this->renderLabel($form->createView(), 'Custom label', array(
- 'label_attr' => array(
- 'class' => 'my&class',
- ),
- ));
- $this->assertMatchesXpath($html,
- '/label
- [@for="name"]
- [@class="my&class col-sm-2 control-label required"]
- [.="[trans]Custom label[/trans]"]
- '
- );
- }
- public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly()
- {
- $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
- 'label' => 'Custom label',
- ));
- $html = $this->renderLabel($form->createView(), null, array(
- 'label_attr' => array(
- 'class' => 'my&class',
- ),
- ));
- $this->assertMatchesXpath($html,
- '/label
- [@for="name"]
- [@class="my&class col-sm-2 control-label required"]
- [.="[trans]Custom label[/trans]"]
- '
- );
- }
- public function testStartTag()
- {
- $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
- 'method' => 'get',
- 'action' => 'http://example.com/directory',
- ));
- $html = $this->renderStart($form->createView());
- $this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal">', $html);
- }
- public function testStartTagWithOverriddenVars()
- {
- $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
- 'method' => 'put',
- 'action' => 'http://example.com/directory',
- ));
- $html = $this->renderStart($form->createView(), array(
- 'method' => 'post',
- 'action' => 'http://foo.com/directory',
- ));
- $this->assertSame('<form name="form" method="post" action="http://foo.com/directory" class="form-horizontal">', $html);
- }
- public function testStartTagForMultipartForm()
- {
- $form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
- 'method' => 'get',
- 'action' => 'http://example.com/directory',
- ))
- ->add('file', 'Symfony\Component\Form\Extension\Core\Type\FileType')
- ->getForm();
- $html = $this->renderStart($form->createView());
- $this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal" enctype="multipart/form-data">', $html);
- }
- public function testStartTagWithExtraAttributes()
- {
- $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
- 'method' => 'get',
- 'action' => 'http://example.com/directory',
- ));
- $html = $this->renderStart($form->createView(), array(
- 'attr' => array('class' => 'foobar'),
- ));
- $this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar form-horizontal">', $html);
- }
- }
|