HtmlObjectTest.php 5.1 KB

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