FormImageTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. // Call Zend_View_Helper_FormImageTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormImageTest::main");
  5. }
  6. require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  7. require_once 'Zend/View.php';
  8. require_once 'Zend/View/Helper/FormImage.php';
  9. /**
  10. * Test class for Zend_View_Helper_FormImage.
  11. */
  12. class Zend_View_Helper_FormImageTest 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. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormImageTest");
  23. $result = PHPUnit_TextUI_TestRunner::run($suite);
  24. }
  25. /**
  26. * Sets up the fixture, for example, open a network connection.
  27. * This method is called before a test is executed.
  28. *
  29. * @access protected
  30. */
  31. protected function setUp()
  32. {
  33. $this->view = new Zend_View();
  34. $this->helper = new Zend_View_Helper_FormImage();
  35. $this->helper->setView($this->view);
  36. }
  37. /**
  38. * Tears down the fixture, for example, close a network connection.
  39. * This method is called after a test is executed.
  40. *
  41. * @access protected
  42. */
  43. protected function tearDown()
  44. {
  45. }
  46. public function testFormImageRendersFormImageXhtml()
  47. {
  48. $button = $this->helper->formImage('foo', 'bar');
  49. $this->assertRegexp('/<input[^>]*?src="bar"/', $button);
  50. $this->assertRegexp('/<input[^>]*?name="foo"/', $button);
  51. $this->assertRegexp('/<input[^>]*?type="image"/', $button);
  52. }
  53. public function testDisablingFormImageRendersImageInputWithDisableAttribute()
  54. {
  55. $button = $this->helper->formImage('foo', 'bar', array('disable' => true));
  56. $this->assertRegexp('/<input[^>]*?disabled="disabled"/', $button);
  57. $this->assertRegexp('/<input[^>]*?src="bar"/', $button);
  58. $this->assertRegexp('/<input[^>]*?name="foo"/', $button);
  59. $this->assertRegexp('/<input[^>]*?type="image"/', $button);
  60. }
  61. }
  62. // Call Zend_View_Helper_FormImageTest::main() if this source file is executed directly.
  63. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormImageTest::main") {
  64. Zend_View_Helper_FormImageTest::main();
  65. }