FieldsetTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_FieldsetTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FieldsetTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  27. require_once "PHPUnit/Framework/TestCase.php";
  28. require_once "PHPUnit/Framework/TestSuite.php";
  29. require_once 'Zend/View/Helper/Fieldset.php';
  30. require_once 'Zend/View.php';
  31. /**
  32. * Test class for Zend_View_Helper_Fieldset
  33. *
  34. * @category Zend
  35. * @package Zend_View
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. * @group Zend_View
  40. * @group Zend_View_Helper
  41. */
  42. class Zend_View_Helper_FieldsetTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * Runs the test methods of this class.
  46. *
  47. * @return void
  48. */
  49. public static function main()
  50. {
  51. require_once "PHPUnit/TextUI/TestRunner.php";
  52. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FieldsetTest");
  53. $result = PHPUnit_TextUI_TestRunner::run($suite);
  54. }
  55. /**
  56. * Sets up the fixture, for example, open a network connection.
  57. * This method is called before a test is executed.
  58. *
  59. * @return void
  60. */
  61. public function setUp()
  62. {
  63. $this->view = new Zend_View();
  64. $this->helper = new Zend_View_Helper_Fieldset();
  65. $this->helper->setView($this->view);
  66. ob_start();
  67. }
  68. /**
  69. * Tears down the fixture, for example, close a network connection.
  70. * This method is called after a test is executed.
  71. *
  72. * @return void
  73. */
  74. public function tearDown()
  75. {
  76. ob_end_clean();
  77. }
  78. public function testFieldsetHelperCreatesFieldsetWithProvidedContent()
  79. {
  80. $html = $this->helper->fieldset('foo', 'foobar');
  81. $this->assertRegexp('#<fieldset[^>]+id="foo".*?>#', $html);
  82. $this->assertContains('</fieldset>', $html);
  83. $this->assertContains('foobar', $html);
  84. }
  85. public function testProvidingLegendOptionToFieldsetCreatesLegendTag()
  86. {
  87. $html = $this->helper->fieldset('foo', 'foobar', array('legend' => 'Great Scott!'));
  88. $this->assertRegexp('#<legend>Great Scott!</legend>#', $html);
  89. }
  90. /**
  91. * @see ZF-2913
  92. */
  93. public function testEmptyLegendShouldNotRenderLegendTag()
  94. {
  95. foreach (array(null, '', ' ', false) as $legend) {
  96. $html = $this->helper->fieldset('foo', 'foobar', array('legend' => $legend));
  97. $this->assertNotContains('<legend>', $html, 'Failed with value ' . var_export($legend, 1) . ': ' . $html);
  98. }
  99. }
  100. /**
  101. * @group ZF-3632
  102. */
  103. public function testHelperShouldAllowDisablingEscapingOfLegend()
  104. {
  105. $html = $this->helper->fieldset('foo', 'foobar', array('legend' => '<b>Great Scott!</b>', 'escape' => false));
  106. $this->assertRegexp('#<legend><b>Great Scott!</b></legend>#', $html, $html);
  107. }
  108. }
  109. // Call Zend_View_Helper_FieldsetTest::main() if this source file is executed directly.
  110. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FieldsetTest::main") {
  111. Zend_View_Helper_FieldsetTest::main();
  112. }