|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Form\Tests; |
| 13 | + |
| 14 | +/** |
| 15 | + * Abstract class providing test cases for the Bootstrap 4 horizontal Twig form theme. |
| 16 | + * |
| 17 | + * @author Hidde Wieringa <[email protected]> |
| 18 | + */ |
| 19 | +abstract class AbstractBootstrap4HorizontalLayoutTest extends AbstractBootstrap4LayoutTest |
| 20 | +{ |
| 21 | + public function testLabelOnForm() |
| 22 | + { |
| 23 | + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType'); |
| 24 | + $view = $form->createView(); |
| 25 | + $this->renderWidget($view, array('label' => 'foo')); |
| 26 | + $html = $this->renderLabel($view); |
| 27 | + |
| 28 | + $this->assertMatchesXpath($html, |
| 29 | +'/label |
| 30 | + [@class="col-form-label col-sm-2 form-control-label required"] |
| 31 | + [.="[trans]Name[/trans]"] |
| 32 | +' |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + public function testLabelDoesNotRenderFieldAttributes() |
| 37 | + { |
| 38 | + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType'); |
| 39 | + $html = $this->renderLabel($form->createView(), null, array( |
| 40 | + 'attr' => array( |
| 41 | + 'class' => 'my&class', |
| 42 | + ), |
| 43 | + )); |
| 44 | + |
| 45 | + $this->assertMatchesXpath($html, |
| 46 | +'/label |
| 47 | + [@for="name"] |
| 48 | + [@class="col-form-label col-sm-2 form-control-label required"] |
| 49 | +' |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + public function testLabelWithCustomAttributesPassedDirectly() |
| 54 | + { |
| 55 | + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType'); |
| 56 | + $html = $this->renderLabel($form->createView(), null, array( |
| 57 | + 'label_attr' => array( |
| 58 | + 'class' => 'my&class', |
| 59 | + ), |
| 60 | + )); |
| 61 | + |
| 62 | + $this->assertMatchesXpath($html, |
| 63 | +'/label |
| 64 | + [@for="name"] |
| 65 | + [@class="my&class col-form-label col-sm-2 form-control-label required"] |
| 66 | +' |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + public function testLabelWithCustomTextAndCustomAttributesPassedDirectly() |
| 71 | + { |
| 72 | + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType'); |
| 73 | + $html = $this->renderLabel($form->createView(), 'Custom label', array( |
| 74 | + 'label_attr' => array( |
| 75 | + 'class' => 'my&class', |
| 76 | + ), |
| 77 | + )); |
| 78 | + |
| 79 | + $this->assertMatchesXpath($html, |
| 80 | +'/label |
| 81 | + [@for="name"] |
| 82 | + [@class="my&class col-form-label col-sm-2 form-control-label required"] |
| 83 | + [.="[trans]Custom label[/trans]"] |
| 84 | +' |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly() |
| 89 | + { |
| 90 | + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array( |
| 91 | + 'label' => 'Custom label', |
| 92 | + )); |
| 93 | + $html = $this->renderLabel($form->createView(), null, array( |
| 94 | + 'label_attr' => array( |
| 95 | + 'class' => 'my&class', |
| 96 | + ), |
| 97 | + )); |
| 98 | + |
| 99 | + $this->assertMatchesXpath($html, |
| 100 | +'/label |
| 101 | + [@for="name"] |
| 102 | + [@class="my&class col-form-label col-sm-2 form-control-label required"] |
| 103 | + [.="[trans]Custom label[/trans]"] |
| 104 | +' |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + public function testLegendOnExpandedType() |
| 109 | + { |
| 110 | + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( |
| 111 | + 'label' => 'Custom label', |
| 112 | + 'expanded' => true, |
| 113 | + 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'), |
| 114 | + )); |
| 115 | + $view = $form->createView(); |
| 116 | + $this->renderWidget($view); |
| 117 | + $html = $this->renderLabel($view); |
| 118 | + |
| 119 | + $this->assertMatchesXpath($html, |
| 120 | +'/legend |
| 121 | + [@class="col-sm-2 col-form-legend form-control-label required"] |
| 122 | + [.="[trans]Custom label[/trans]"] |
| 123 | +' |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + public function testStartTag() |
| 128 | + { |
| 129 | + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( |
| 130 | + 'method' => 'get', |
| 131 | + 'action' => 'http://example.com/directory', |
| 132 | + )); |
| 133 | + |
| 134 | + $html = $this->renderStart($form->createView()); |
| 135 | + |
| 136 | + $this->assertSame('<form name="form" method="get" action="http://example.com/directory">', $html); |
| 137 | + } |
| 138 | + |
| 139 | + public function testStartTagWithOverriddenVars() |
| 140 | + { |
| 141 | + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( |
| 142 | + 'method' => 'put', |
| 143 | + 'action' => 'http://example.com/directory', |
| 144 | + )); |
| 145 | + |
| 146 | + $html = $this->renderStart($form->createView(), array( |
| 147 | + 'method' => 'post', |
| 148 | + 'action' => 'http://foo.com/directory', |
| 149 | + )); |
| 150 | + |
| 151 | + $this->assertSame('<form name="form" method="post" action="http://foo.com/directory">', $html); |
| 152 | + } |
| 153 | + |
| 154 | + public function testStartTagForMultipartForm() |
| 155 | + { |
| 156 | + $form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( |
| 157 | + 'method' => 'get', |
| 158 | + 'action' => 'http://example.com/directory', |
| 159 | + )) |
| 160 | + ->add('file', 'Symfony\Component\Form\Extension\Core\Type\FileType') |
| 161 | + ->getForm(); |
| 162 | + |
| 163 | + $html = $this->renderStart($form->createView()); |
| 164 | + |
| 165 | + $this->assertSame('<form name="form" method="get" action="http://example.com/directory" enctype="multipart/form-data">', $html); |
| 166 | + } |
| 167 | + |
| 168 | + public function testStartTagWithExtraAttributes() |
| 169 | + { |
| 170 | + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( |
| 171 | + 'method' => 'get', |
| 172 | + 'action' => 'http://example.com/directory', |
| 173 | + )); |
| 174 | + |
| 175 | + $html = $this->renderStart($form->createView(), array( |
| 176 | + 'attr' => array('class' => 'foobar'), |
| 177 | + )); |
| 178 | + |
| 179 | + $this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar">', $html); |
| 180 | + } |
| 181 | +} |
0 commit comments