AbstractBootstrap3HorizontalLayoutTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form\Tests;
  11. abstract class AbstractBootstrap3HorizontalLayoutTest extends AbstractBootstrap3LayoutTest
  12. {
  13. public function testLabelOnForm()
  14. {
  15. $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType');
  16. $view = $form->createView();
  17. $this->renderWidget($view, array('label' => 'foo'));
  18. $html = $this->renderLabel($view);
  19. $this->assertMatchesXpath($html,
  20. '/label
  21. [@class="col-sm-2 control-label required"]
  22. [.="[trans]Name[/trans]"]
  23. '
  24. );
  25. }
  26. public function testLabelDoesNotRenderFieldAttributes()
  27. {
  28. $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
  29. $html = $this->renderLabel($form->createView(), null, array(
  30. 'attr' => array(
  31. 'class' => 'my&class',
  32. ),
  33. ));
  34. $this->assertMatchesXpath($html,
  35. '/label
  36. [@for="name"]
  37. [@class="col-sm-2 control-label required"]
  38. '
  39. );
  40. }
  41. public function testLabelWithCustomAttributesPassedDirectly()
  42. {
  43. $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
  44. $html = $this->renderLabel($form->createView(), null, array(
  45. 'label_attr' => array(
  46. 'class' => 'my&class',
  47. ),
  48. ));
  49. $this->assertMatchesXpath($html,
  50. '/label
  51. [@for="name"]
  52. [@class="my&class col-sm-2 control-label required"]
  53. '
  54. );
  55. }
  56. public function testLabelWithCustomTextAndCustomAttributesPassedDirectly()
  57. {
  58. $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
  59. $html = $this->renderLabel($form->createView(), 'Custom label', array(
  60. 'label_attr' => array(
  61. 'class' => 'my&class',
  62. ),
  63. ));
  64. $this->assertMatchesXpath($html,
  65. '/label
  66. [@for="name"]
  67. [@class="my&class col-sm-2 control-label required"]
  68. [.="[trans]Custom label[/trans]"]
  69. '
  70. );
  71. }
  72. public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly()
  73. {
  74. $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
  75. 'label' => 'Custom label',
  76. ));
  77. $html = $this->renderLabel($form->createView(), null, array(
  78. 'label_attr' => array(
  79. 'class' => 'my&class',
  80. ),
  81. ));
  82. $this->assertMatchesXpath($html,
  83. '/label
  84. [@for="name"]
  85. [@class="my&class col-sm-2 control-label required"]
  86. [.="[trans]Custom label[/trans]"]
  87. '
  88. );
  89. }
  90. public function testStartTag()
  91. {
  92. $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
  93. 'method' => 'get',
  94. 'action' => 'http://example.com/directory',
  95. ));
  96. $html = $this->renderStart($form->createView());
  97. $this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal">', $html);
  98. }
  99. public function testStartTagWithOverriddenVars()
  100. {
  101. $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
  102. 'method' => 'put',
  103. 'action' => 'http://example.com/directory',
  104. ));
  105. $html = $this->renderStart($form->createView(), array(
  106. 'method' => 'post',
  107. 'action' => 'http://foo.com/directory',
  108. ));
  109. $this->assertSame('<form name="form" method="post" action="http://foo.com/directory" class="form-horizontal">', $html);
  110. }
  111. public function testStartTagForMultipartForm()
  112. {
  113. $form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
  114. 'method' => 'get',
  115. 'action' => 'http://example.com/directory',
  116. ))
  117. ->add('file', 'Symfony\Component\Form\Extension\Core\Type\FileType')
  118. ->getForm();
  119. $html = $this->renderStart($form->createView());
  120. $this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal" enctype="multipart/form-data">', $html);
  121. }
  122. public function testStartTagWithExtraAttributes()
  123. {
  124. $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
  125. 'method' => 'get',
  126. 'action' => 'http://example.com/directory',
  127. ));
  128. $html = $this->renderStart($form->createView(), array(
  129. 'attr' => array('class' => 'foobar'),
  130. ));
  131. $this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar form-horizontal">', $html);
  132. }
  133. }