HtmlObjectTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_HtmlObjectTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_HtmlObjectTest::main");
  25. }
  26. require_once 'Zend/View.php';
  27. require_once 'Zend/View/Helper/HtmlObject.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_View
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_View
  35. * @group Zend_View_Helper
  36. */
  37. class Zend_View_Helper_HtmlObjectTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * @var Zend_View_Helper_HtmlObject
  41. */
  42. public $helper;
  43. /**
  44. * Runs the test methods of this class.
  45. *
  46. * @access public
  47. * @static
  48. */
  49. public static function main()
  50. {
  51. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_HtmlObjectTest");
  52. PHPUnit_TextUI_TestRunner::run($suite);
  53. }
  54. /**
  55. * Sets up the fixture, for example, open a network connection.
  56. * This method is called before a test is executed.
  57. *
  58. * @access protected
  59. */
  60. protected function setUp()
  61. {
  62. $this->view = new Zend_View();
  63. $this->helper = new Zend_View_Helper_HtmlObject();
  64. $this->helper->setView($this->view);
  65. }
  66. public function tearDown()
  67. {
  68. unset($this->helper);
  69. }
  70. public function testViewObjectIsSet()
  71. {
  72. $this->assertTrue($this->helper->view instanceof Zend_View_Interface);
  73. }
  74. public function testMakeHtmlObjectWithoutAttribsWithoutParams()
  75. {
  76. $htmlObject = $this->helper->htmlObject('datastring', 'typestring');
  77. $this->assertContains('<object data="datastring" type="typestring">', $htmlObject);
  78. $this->assertContains('</object>', $htmlObject);
  79. }
  80. public function testMakeHtmlObjectWithAttribsWithoutParams()
  81. {
  82. $attribs = array('attribkey1' => 'attribvalue1',
  83. 'attribkey2' => 'attribvalue2');
  84. $htmlObject = $this->helper->htmlObject('datastring', 'typestring', $attribs);
  85. $this->assertContains('<object data="datastring" type="typestring" attribkey1="attribvalue1" attribkey2="attribvalue2">', $htmlObject);
  86. $this->assertContains('</object>', $htmlObject);
  87. }
  88. public function testMakeHtmlObjectWithoutAttribsWithParamsHtml()
  89. {
  90. $this->view->doctype(Zend_View_Helper_Doctype::HTML4_STRICT);
  91. $params = array('paramname1' => 'paramvalue1',
  92. 'paramname2' => 'paramvalue2');
  93. $htmlObject = $this->helper->htmlObject('datastring', 'typestring', array(), $params);
  94. $this->assertContains('<object data="datastring" type="typestring">', $htmlObject);
  95. $this->assertContains('</object>', $htmlObject);
  96. foreach ($params as $key => $value) {
  97. $param = '<param name="' . $key . '" value="' . $value . '">';
  98. $this->assertContains($param, $htmlObject);
  99. }
  100. }
  101. public function testMakeHtmlObjectWithoutAttribsWithParamsXhtml()
  102. {
  103. $this->view->doctype(Zend_View_Helper_Doctype::XHTML1_STRICT);
  104. $params = array('paramname1' => 'paramvalue1',
  105. 'paramname2' => 'paramvalue2');
  106. $htmlObject = $this->helper->htmlObject('datastring', 'typestring', array(), $params);
  107. $this->assertContains('<object data="datastring" type="typestring">', $htmlObject);
  108. $this->assertContains('</object>', $htmlObject);
  109. foreach ($params as $key => $value) {
  110. $param = '<param name="' . $key . '" value="' . $value . '" />';
  111. $this->assertContains($param, $htmlObject);
  112. }
  113. }
  114. public function testMakeHtmlObjectWithContent()
  115. {
  116. $htmlObject = $this->helper->htmlObject('datastring', 'typestring', array(), array(), 'testcontent');
  117. $this->assertContains('<object data="datastring" type="typestring">', $htmlObject);
  118. $this->assertContains('testcontent', $htmlObject);
  119. $this->assertContains('</object>', $htmlObject);
  120. }
  121. }
  122. // Call Zend_View_Helper_HtmlObjectTest::main() if this source file is executed directly.
  123. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_HtmlObjectTest::main") {
  124. Zend_View_Helper_HtmlObjectTest::main();
  125. }