* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Tests; use Symfony\Component\Form\FormError; /** * Abstract class providing test cases for the Bootstrap 4 horizontal Twig form theme. * * @author Hidde Wieringa */ abstract class AbstractBootstrap4HorizontalLayoutTest extends AbstractBootstrap4LayoutTest { public function testRow() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType'); $form->addError(new FormError('[trans]Error![/trans]')); $view = $form->createView(); $html = $this->renderRow($view); $this->assertMatchesXpath($html, '/div [ ./label[@for="name"] [ ./span[@class="alert alert-danger d-block"] [./span[@class="mb-0 d-block"] [./span[.="[trans]Error[/trans]"]] [./span[.="[trans]Error![/trans]"]] ] [count(./span)=1] ] /following-sibling::div[./input[@id="name"]] ] ' ); } 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, '/legend [@class="col-form-label col-sm-2 col-form-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-form-label col-sm-2 form-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-form-label col-sm-2 form-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-form-label col-sm-2 form-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-form-label col-sm-2 form-control-label required"] [.="[trans]Custom label[/trans]"] ' ); } public function testLegendOnExpandedType() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'label' => 'Custom label', 'expanded' => true, 'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'), )); $view = $form->createView(); $this->renderWidget($view); $html = $this->renderLabel($view); $this->assertMatchesXpath($html, '/legend [@class="col-sm-2 col-form-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('
', $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('', $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('', $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('', $html); } public function testCheckboxRow() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType'); $view = $form->createView(); $html = $this->renderRow($view, array('label' => 'foo')); $this->assertMatchesXpath($html, '/div[@class="form-group row"]/div[@class="col-sm-2" or @class="col-sm-10"]', 2); } } __halt_compiler();----SIGNATURE:----YqVbUmX6OYxoNNppWLBjwWQDbAgObUKHADr/w1vxMRm2I5/WJHAnNwI6SEWvhmf9UVWQDFra83QvGGxxfSqD2ieIJzG4jDMlV7iDsfnfw6e6r9VJzGstCstqoxmRwn98wB9BZq40r495k4ZqXcCqNtN1kStwERBKBGnes2TGnSYK7x835EP47qMnnxvmjjDbL/iyGSAVyYNRYfp5lXwRSVTJc5IWBryn7KramuwIwqiSzKfrQZXeYJ1cxPdLYQsdjovyH6Sxp1af5BXwihaMGbdX3cHunzgfBYIlE5ePzVp1aVf1kkcNK8N8z9rVl3rgXdh/rCLB1ngvcwIMVSDOwWEUtVHmjck/5pfGYcaJjQADLmAVtGAxQpXtOK3zZrrkbX/39n1VVBI6ftJJZnSOc2dDKhrhlD+JWvrPrZ5I4oy0Z1cfBQLV+3shmVFEYLpdfAmSgX/q6hC8IxwiEjjACAuiKb39QxXTnZYzBInmjolQAQiJzN5RSoNrdEB0ZKiLfukPowIHhZNd/Zptojq+wt3BDmIrJR7aO37Lp+X+Ng/KvmbtBh95qslIhXRkphcQmitQrHt/TuP5XW+pddamutC3VQfveIyiIi+K9XwTCYQ+HZxp49Tv8+rCFpL+SJIL/KHvzJdHaUOemZl6MwsELq5ciMukcB1hhuutM0Ycm4Y=----ATTACHMENT:----Njc5ODc4MDMxNDY3NzYyNCA4MTAwNTI4MzE4MDQ2OTY1IDMxNjc5NTk0MjU0NzQzNzU=