HtmlObjectTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // Call Zend_View_Helper_HtmlObjectTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_HtmlObjectTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once 'Zend/View.php';
  8. require_once 'Zend/View/Helper/HtmlObject.php';
  9. class Zend_View_Helper_HtmlObjectTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @var Zend_View_Helper_HtmlObject
  13. */
  14. public $helper;
  15. /**
  16. * Runs the test methods of this class.
  17. *
  18. * @access public
  19. * @static
  20. */
  21. public static function main()
  22. {
  23. require_once "PHPUnit/TextUI/TestRunner.php";
  24. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_HtmlObjectTest");
  25. 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. * @access protected
  32. */
  33. protected function setUp()
  34. {
  35. $this->view = new Zend_View();
  36. $this->helper = new Zend_View_Helper_HtmlObject();
  37. $this->helper->setView($this->view);
  38. }
  39. public function tearDown()
  40. {
  41. unset($this->helper);
  42. }
  43. public function testViewObjectIsSet()
  44. {
  45. $this->assertType('Zend_View_Interface', $this->helper->view);
  46. }
  47. public function testMakeHtmlObjectWithoutAttribsWithoutParams()
  48. {
  49. $htmlObject = $this->helper->htmlObject('datastring', 'typestring');
  50. $this->assertContains('<object data="datastring" type="typestring">', $htmlObject);
  51. $this->assertContains('</object>', $htmlObject);
  52. }
  53. public function testMakeHtmlObjectWithAttribsWithoutParams()
  54. {
  55. $attribs = array('attribkey1' => 'attribvalue1',
  56. 'attribkey2' => 'attribvalue2');
  57. $htmlObject = $this->helper->htmlObject('datastring', 'typestring', $attribs);
  58. $this->assertContains('<object data="datastring" type="typestring" attribkey1="attribvalue1" attribkey2="attribvalue2">', $htmlObject);
  59. $this->assertContains('</object>', $htmlObject);
  60. }
  61. public function testMakeHtmlObjectWithoutAttribsWithParamsHtml()
  62. {
  63. $this->view->doctype(Zend_View_Helper_Doctype::HTML4_STRICT);
  64. $params = array('paramname1' => 'paramvalue1',
  65. 'paramname2' => 'paramvalue2');
  66. $htmlObject = $this->helper->htmlObject('datastring', 'typestring', array(), $params);
  67. $this->assertContains('<object data="datastring" type="typestring">', $htmlObject);
  68. $this->assertContains('</object>', $htmlObject);
  69. foreach ($params as $key => $value) {
  70. $param = '<param name="' . $key . '" value="' . $value . '">';
  71. $this->assertContains($param, $htmlObject);
  72. }
  73. }
  74. public function testMakeHtmlObjectWithoutAttribsWithParamsXhtml()
  75. {
  76. $this->view->doctype(Zend_View_Helper_Doctype::XHTML1_STRICT);
  77. $params = array('paramname1' => 'paramvalue1',
  78. 'paramname2' => 'paramvalue2');
  79. $htmlObject = $this->helper->htmlObject('datastring', 'typestring', array(), $params);
  80. $this->assertContains('<object data="datastring" type="typestring">', $htmlObject);
  81. $this->assertContains('</object>', $htmlObject);
  82. foreach ($params as $key => $value) {
  83. $param = '<param name="' . $key . '" value="' . $value . '" />';
  84. $this->assertContains($param, $htmlObject);
  85. }
  86. }
  87. public function testMakeHtmlObjectWithContent()
  88. {
  89. $htmlObject = $this->helper->htmlObject('datastring', 'typestring', array(), array(), 'testcontent');
  90. $this->assertContains('<object data="datastring" type="typestring">', $htmlObject);
  91. $this->assertContains('testcontent', $htmlObject);
  92. $this->assertContains('</object>', $htmlObject);
  93. }
  94. }
  95. // Call Zend_View_Helper_HtmlObjectTest::main() if this source file is executed directly.
  96. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_HtmlObjectTest::main") {
  97. Zend_View_Helper_HtmlObjectTest::main();
  98. }