2
0

FieldsetTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // Call Zend_FieldsetTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FieldsetTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once "PHPUnit/Framework/TestCase.php";
  8. require_once "PHPUnit/Framework/TestSuite.php";
  9. require_once 'Zend/View/Helper/Fieldset.php';
  10. require_once 'Zend/View.php';
  11. /**
  12. * Test class for Zend_View_Helper_Fieldset
  13. */
  14. class Zend_View_Helper_FieldsetTest extends PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * Runs the test methods of this class.
  18. *
  19. * @return void
  20. */
  21. public static function main()
  22. {
  23. require_once "PHPUnit/TextUI/TestRunner.php";
  24. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FieldsetTest");
  25. $result = PHPUnit_TextUI_TestRunner::run($suite);
  26. }
  27. /**
  28. * Sets up the fixture, for example, open a network connection.
  29. * This method is called before a test is executed.
  30. *
  31. * @return void
  32. */
  33. public function setUp()
  34. {
  35. $this->view = new Zend_View();
  36. $this->helper = new Zend_View_Helper_Fieldset();
  37. $this->helper->setView($this->view);
  38. ob_start();
  39. }
  40. /**
  41. * Tears down the fixture, for example, close a network connection.
  42. * This method is called after a test is executed.
  43. *
  44. * @return void
  45. */
  46. public function tearDown()
  47. {
  48. ob_end_clean();
  49. }
  50. public function testFieldsetHelperCreatesFieldsetWithProvidedContent()
  51. {
  52. $html = $this->helper->fieldset('foo', 'foobar');
  53. $this->assertRegexp('#<fieldset[^>]+id="foo".*?>#', $html);
  54. $this->assertContains('</fieldset>', $html);
  55. $this->assertContains('foobar', $html);
  56. }
  57. public function testProvidingLegendOptionToFieldsetCreatesLegendTag()
  58. {
  59. $html = $this->helper->fieldset('foo', 'foobar', array('legend' => 'Great Scott!'));
  60. $this->assertRegexp('#<legend>Great Scott!</legend>#', $html);
  61. }
  62. /**
  63. * @see ZF-2913
  64. */
  65. public function testEmptyLegendShouldNotRenderLegendTag()
  66. {
  67. foreach (array(null, '', ' ', false) as $legend) {
  68. $html = $this->helper->fieldset('foo', 'foobar', array('legend' => $legend));
  69. $this->assertNotContains('<legend>', $html, 'Failed with value ' . var_export($legend, 1) . ': ' . $html);
  70. }
  71. }
  72. /**
  73. * @group ZF-3632
  74. */
  75. public function testHelperShouldAllowDisablingEscapingOfLegend()
  76. {
  77. $html = $this->helper->fieldset('foo', 'foobar', array('legend' => '<b>Great Scott!</b>', 'escape' => false));
  78. $this->assertRegexp('#<legend><b>Great Scott!</b></legend>#', $html, $html);
  79. }
  80. }
  81. // Call Zend_View_Helper_FieldsetTest::main() if this source file is executed directly.
  82. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FieldsetTest::main") {
  83. Zend_View_Helper_FieldsetTest::main();
  84. }