FormButtonTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // Call Zend_View_Helper_FormButtonTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormButtonTest::main");
  5. }
  6. require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  7. require_once 'Zend/View.php';
  8. require_once 'Zend/View/Helper/FormButton.php';
  9. /**
  10. * Test class for Zend_View_Helper_FormButton.
  11. */
  12. class Zend_View_Helper_FormButtonTest extends PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * Runs the test methods of this class.
  16. *
  17. * @access public
  18. * @static
  19. */
  20. public static function main()
  21. {
  22. require_once "PHPUnit/TextUI/TestRunner.php";
  23. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormButtonTest");
  24. $result = PHPUnit_TextUI_TestRunner::run($suite);
  25. }
  26. /**
  27. * Sets up the fixture, for example, open a network connection.
  28. * This method is called before a test is executed.
  29. *
  30. * @access protected
  31. */
  32. protected function setUp()
  33. {
  34. $this->view = new Zend_View();
  35. $this->helper = new Zend_View_Helper_FormButton();
  36. $this->helper->setView($this->view);
  37. }
  38. /**
  39. * Tears down the fixture, for example, close a network connection.
  40. * This method is called after a test is executed.
  41. *
  42. * @access protected
  43. */
  44. protected function tearDown()
  45. {
  46. }
  47. public function testFormButtonRendersButtonXhtml()
  48. {
  49. $button = $this->helper->formButton('foo', 'bar');
  50. $this->assertRegexp('/<button[^>]*?value="bar"/', $button);
  51. $this->assertRegexp('/<button[^>]*?name="foo"/', $button);
  52. $this->assertRegexp('/<button[^>]*?id="foo"/', $button);
  53. $this->assertContains('</button>', $button);
  54. }
  55. public function testCanPassContentViaContentAttribKey()
  56. {
  57. $button = $this->helper->formButton('foo', 'bar', array('content' => 'Display this'));
  58. $this->assertContains('>Display this<', $button);
  59. $this->assertContains('<button', $button);
  60. $this->assertContains('</button>', $button);
  61. }
  62. public function testCanDisableContentEscaping()
  63. {
  64. $button = $this->helper->formButton('foo', 'bar', array('content' => '<b>Display this</b>', 'escape' => false));
  65. $this->assertContains('><b>Display this</b><', $button);
  66. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('content' => '<b>Display this</b>', 'escape' => false)));
  67. $this->assertContains('><b>Display this</b><', $button);
  68. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'escape' => false, 'attribs' => array('content' => '<b>Display this</b>')));
  69. $this->assertContains('><b>Display this</b><', $button);
  70. $this->assertContains('<button', $button);
  71. $this->assertContains('</button>', $button);
  72. }
  73. public function testValueUsedForContentWhenNoContentProvided()
  74. {
  75. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar'));
  76. $this->assertRegexp('#<button[^>]*?value="bar"[^>]*>bar</button>#', $button);
  77. }
  78. public function testButtonTypeIsButtonByDefault()
  79. {
  80. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar'));
  81. $this->assertContains('type="button"', $button);
  82. }
  83. public function testButtonTypeMayOnlyBeValidXhtmlButtonType()
  84. {
  85. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('type' => 'submit')));
  86. $this->assertContains('type="submit"', $button);
  87. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('type' => 'reset')));
  88. $this->assertContains('type="reset"', $button);
  89. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('type' => 'button')));
  90. $this->assertContains('type="button"', $button);
  91. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('type' => 'bogus')));
  92. $this->assertContains('type="button"', $button);
  93. }
  94. }
  95. // Call Zend_View_Helper_FormButtonTest::main() if this source file is executed directly.
  96. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormButtonTest::main") {
  97. Zend_View_Helper_FormButtonTest::main();
  98. }