FormButtonTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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-2015 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_View_Helper_FormButtonTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormButtonTest::main");
  25. }
  26. require_once 'Zend/View.php';
  27. require_once 'Zend/View/Helper/FormButton.php';
  28. /**
  29. * Test class for Zend_View_Helper_FormButton.
  30. *
  31. * @category Zend
  32. * @package Zend_View
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_View
  37. * @group Zend_View_Helper
  38. */
  39. class Zend_View_Helper_FormButtonTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * Runs the test methods of this class.
  43. *
  44. * @access public
  45. * @static
  46. */
  47. public static function main()
  48. {
  49. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormButtonTest");
  50. $result = PHPUnit_TextUI_TestRunner::run($suite);
  51. }
  52. /**
  53. * Sets up the fixture, for example, open a network connection.
  54. * This method is called before a test is executed.
  55. *
  56. * @access protected
  57. */
  58. protected function setUp()
  59. {
  60. $this->view = new Zend_View();
  61. $this->helper = new Zend_View_Helper_FormButton();
  62. $this->helper->setView($this->view);
  63. }
  64. /**
  65. * Tears down the fixture, for example, close a network connection.
  66. * This method is called after a test is executed.
  67. *
  68. * @access protected
  69. */
  70. protected function tearDown()
  71. {
  72. }
  73. public function testFormButtonRendersButtonXhtml()
  74. {
  75. $button = $this->helper->formButton('foo', 'bar');
  76. $this->assertRegexp('/<button[^>]*?value="bar"/', $button);
  77. $this->assertRegexp('/<button[^>]*?name="foo"/', $button);
  78. $this->assertRegexp('/<button[^>]*?id="foo"/', $button);
  79. $this->assertContains('</button>', $button);
  80. }
  81. public function testCanPassContentViaContentAttribKey()
  82. {
  83. $button = $this->helper->formButton('foo', 'bar', array('content' => 'Display this'));
  84. $this->assertContains('>Display this<', $button);
  85. $this->assertContains('<button', $button);
  86. $this->assertContains('</button>', $button);
  87. }
  88. public function testCanDisableContentEscaping()
  89. {
  90. $button = $this->helper->formButton('foo', 'bar', array('content' => '<b>Display this</b>', 'escape' => false));
  91. $this->assertContains('><b>Display this</b><', $button);
  92. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('content' => '<b>Display this</b>', 'escape' => false)));
  93. $this->assertContains('><b>Display this</b><', $button);
  94. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'escape' => false, 'attribs' => array('content' => '<b>Display this</b>')));
  95. $this->assertContains('><b>Display this</b><', $button);
  96. $this->assertContains('<button', $button);
  97. $this->assertContains('</button>', $button);
  98. }
  99. public function testValueUsedForContentWhenNoContentProvided()
  100. {
  101. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar'));
  102. $this->assertRegexp('#<button[^>]*?value="bar"[^>]*>bar</button>#', $button);
  103. }
  104. public function testButtonTypeIsButtonByDefault()
  105. {
  106. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar'));
  107. $this->assertContains('type="button"', $button);
  108. }
  109. public function testButtonTypeMayOnlyBeValidXhtmlButtonType()
  110. {
  111. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('type' => 'submit')));
  112. $this->assertContains('type="submit"', $button);
  113. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('type' => 'reset')));
  114. $this->assertContains('type="reset"', $button);
  115. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('type' => 'button')));
  116. $this->assertContains('type="button"', $button);
  117. $button = $this->helper->formButton(array('name' => 'foo', 'value' => 'bar', 'attribs' => array('type' => 'bogus')));
  118. $this->assertContains('type="button"', $button);
  119. }
  120. }
  121. // Call Zend_View_Helper_FormButtonTest::main() if this source file is executed directly.
  122. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormButtonTest::main") {
  123. Zend_View_Helper_FormButtonTest::main();
  124. }