PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/ZendFramework/tests/Zend/View/Helper/HtmlListTest.php

https://bitbucket.org/Dal-Papa/is-340-publish-base
PHP | 262 lines | 153 code | 47 blank | 62 comment | 3 complexity | e994cd9e93f70d693fa53d63b29b112f MD5 | raw file
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: HtmlListTest.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. // Call Zend_View_Helper_HtmlListTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_HtmlListTest::main");
  25. }
  26. require_once 'Zend/View.php';
  27. require_once 'Zend/View/Helper/HtmlList.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_View
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2012 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_HtmlListTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * @var Zend_View_Helper_HtmlList
  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_HtmlListTest");
  52. $result = 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_HtmlList();
  64. $this->helper->setView($this->view);
  65. }
  66. public function tearDown()
  67. {
  68. unset($this->helper);
  69. }
  70. public function testMakeUnorderedList()
  71. {
  72. $items = array('one', 'two', 'three');
  73. $list = $this->helper->htmlList($items);
  74. $this->assertContains('<ul>', $list);
  75. $this->assertContains('</ul>', $list);
  76. foreach ($items as $item) {
  77. $this->assertContains('<li>' . $item . '</li>', $list);
  78. }
  79. }
  80. public function testMakeOrderedList()
  81. {
  82. $items = array('one', 'two', 'three');
  83. $list = $this->helper->htmlList($items, true);
  84. $this->assertContains('<ol>', $list);
  85. $this->assertContains('</ol>', $list);
  86. foreach ($items as $item) {
  87. $this->assertContains('<li>' . $item . '</li>', $list);
  88. }
  89. }
  90. public function testMakeUnorderedListWithAttribs()
  91. {
  92. $items = array('one', 'two', 'three');
  93. $attribs = array('class' => 'selected', 'name' => 'list');
  94. $list = $this->helper->htmlList($items, false, $attribs);
  95. $this->assertContains('<ul', $list);
  96. $this->assertContains('class="selected"', $list);
  97. $this->assertContains('name="list"', $list);
  98. $this->assertContains('</ul>', $list);
  99. foreach ($items as $item) {
  100. $this->assertContains('<li>' . $item . '</li>', $list);
  101. }
  102. }
  103. public function testMakeOrderedListWithAttribs()
  104. {
  105. $items = array('one', 'two', 'three');
  106. $attribs = array('class' => 'selected', 'name' => 'list');
  107. $list = $this->helper->htmlList($items, true, $attribs);
  108. $this->assertContains('<ol', $list);
  109. $this->assertContains('class="selected"', $list);
  110. $this->assertContains('name="list"', $list);
  111. $this->assertContains('</ol>', $list);
  112. foreach ($items as $item) {
  113. $this->assertContains('<li>' . $item . '</li>', $list);
  114. }
  115. }
  116. /*
  117. * @group ZF-5018
  118. */
  119. public function testMakeNestedUnorderedList()
  120. {
  121. $items = array('one', array('four', 'five', 'six'), 'two', 'three');
  122. $list = $this->helper->htmlList($items);
  123. $this->assertContains('<ul>' . Zend_View_Helper_HtmlList::EOL, $list);
  124. $this->assertContains('</ul>' . Zend_View_Helper_HtmlList::EOL, $list);
  125. $this->assertContains('one<ul>' . Zend_View_Helper_HtmlList::EOL.'<li>four', $list);
  126. $this->assertContains('<li>six</li>' . Zend_View_Helper_HtmlList::EOL . '</ul>' .
  127. Zend_View_Helper_HtmlList::EOL . '</li>' . Zend_View_Helper_HtmlList::EOL . '<li>two', $list);
  128. }
  129. /*
  130. * @group ZF-5018
  131. */
  132. public function testMakeNestedDeepUnorderedList()
  133. {
  134. $items = array('one', array('four', array('six', 'seven', 'eight'), 'five'), 'two', 'three');
  135. $list = $this->helper->htmlList($items);
  136. $this->assertContains('<ul>' . Zend_View_Helper_HtmlList::EOL, $list);
  137. $this->assertContains('</ul>' . Zend_View_Helper_HtmlList::EOL, $list);
  138. $this->assertContains('one<ul>' . Zend_View_Helper_HtmlList::EOL . '<li>four', $list);
  139. $this->assertContains('<li>four<ul>' . Zend_View_Helper_HtmlList::EOL . '<li>six', $list);
  140. $this->assertContains('<li>five</li>' . Zend_View_Helper_HtmlList::EOL . '</ul>' .
  141. Zend_View_Helper_HtmlList::EOL . '</li>' . Zend_View_Helper_HtmlList::EOL . '<li>two', $list);
  142. }
  143. public function testListWithValuesToEscapeForZF2283()
  144. {
  145. $items = array('one <small> test', 'second & third', 'And \'some\' "final" test');
  146. $list = $this->helper->htmlList($items);
  147. $this->assertContains('<ul>', $list);
  148. $this->assertContains('</ul>', $list);
  149. $this->assertContains('<li>one &lt;small&gt; test</li>', $list);
  150. $this->assertContains('<li>second &amp; third</li>', $list);
  151. $this->assertContains('<li>And \'some\' &quot;final&quot; test</li>', $list);
  152. }
  153. public function testListEscapeSwitchedOffForZF2283()
  154. {
  155. $items = array('one <b>small</b> test');
  156. $list = $this->helper->htmlList($items, false, false, false);
  157. $this->assertContains('<ul>', $list);
  158. $this->assertContains('</ul>', $list);
  159. $this->assertContains('<li>one <b>small</b> test</li>', $list);
  160. }
  161. /**
  162. * @group ZF-2527
  163. */
  164. public function testEscapeFlagHonoredForMultidimensionalLists()
  165. {
  166. $items = array('<b>one</b>', array('<b>four</b>', '<b>five</b>', '<b>six</b>'), '<b>two</b>', '<b>three</b>');
  167. $list = $this->helper->htmlList($items, false, false, false);
  168. foreach ($items[1] as $item) {
  169. $this->assertContains($item, $list);
  170. }
  171. }
  172. /**
  173. * @group ZF-2527
  174. * Added the s modifier to match newlines after @see ZF-5018
  175. */
  176. public function testAttribsPassedIntoMultidimensionalLists()
  177. {
  178. $items = array('one', array('four', 'five', 'six'), 'two', 'three');
  179. $list = $this->helper->htmlList($items, false, array('class' => 'foo'));
  180. foreach ($items[1] as $item) {
  181. $this->assertRegexp('#<ul[^>]*?class="foo"[^>]*>.*?(<li>' . $item . ')#s', $list);
  182. }
  183. }
  184. /**
  185. * @group ZF-2870
  186. */
  187. public function testEscapeFlagShouldBePassedRecursively()
  188. {
  189. $items = array(
  190. '<b>one</b>',
  191. array(
  192. '<b>four</b>',
  193. '<b>five</b>',
  194. '<b>six</b>',
  195. array(
  196. '<b>two</b>',
  197. '<b>three</b>',
  198. ),
  199. ),
  200. );
  201. $list = $this->helper->htmlList($items, false, false, false);
  202. $this->assertContains('<ul>', $list);
  203. $this->assertContains('</ul>', $list);
  204. $this->markTestSkipped('Wrong array_walk_recursive behavior.');
  205. array_walk_recursive($items, array($this, 'validateItems'), $list);
  206. }
  207. public function validateItems($value, $key, $userdata)
  208. {
  209. $this->assertContains('<li>' . $value, $userdata);
  210. }
  211. }
  212. // Call Zend_View_Helper_HtmlListTest::main() if this source file is executed directly.
  213. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_HtmlListTest::main") {
  214. Zend_View_Helper_HtmlListTest::main();
  215. }