PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/cake/tests/cases/libs/view/helpers/html.test.php

https://github.com/mariuz/firetube
PHP | 1001 lines | 730 code | 91 blank | 180 comment | 0 complexity | e31309aa860d3bfa88a77d67d5ee015b MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * HtmlHelperTest file
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2011, Cake Software Foundation, Inc.
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
  17. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  18. * @package cake
  19. * @subpackage cake.tests.cases.libs.view.helpers
  20. * @since CakePHP(tm) v 1.2.0.4206
  21. * @version $Revision$
  22. * @modifiedby $LastChangedBy$
  23. * @lastmodified $Date$
  24. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  25. */
  26. App::import('Core', array('Helper', 'AppHelper', 'ClassRegistry', 'Controller', 'Model'));
  27. App::import('Helper', array('Html', 'Form'));
  28. /**
  29. * TheHtmlTestController class
  30. *
  31. * @package cake
  32. * @subpackage cake.tests.cases.libs.view.helpers
  33. */
  34. class TheHtmlTestController extends Controller {
  35. /**
  36. * name property
  37. *
  38. * @var string 'TheTest'
  39. * @access public
  40. */
  41. var $name = 'TheTest';
  42. /**
  43. * uses property
  44. *
  45. * @var mixed null
  46. * @access public
  47. */
  48. var $uses = null;
  49. }
  50. /**
  51. * HtmlHelperTest class
  52. *
  53. * @package cake
  54. * @subpackage cake.tests.cases.libs.view.helpers
  55. */
  56. class HtmlHelperTest extends CakeTestCase {
  57. /**
  58. * Html property
  59. *
  60. * @var object
  61. * @access public
  62. */
  63. var $Html = null;
  64. /**
  65. * Backup of app encoding configuration setting
  66. *
  67. * @var string
  68. * @access protected
  69. */
  70. var $_appEncoding;
  71. /**
  72. * Backup of asset configuration settings
  73. *
  74. * @var string
  75. * @access protected
  76. */
  77. var $_asset;
  78. /**
  79. * Backup of debug configuration setting
  80. *
  81. * @var integer
  82. * @access protected
  83. */
  84. var $_debug;
  85. /**
  86. * setUp method
  87. *
  88. * @access public
  89. * @return void
  90. */
  91. function setUp() {
  92. $this->Html =& new HtmlHelper();
  93. $view =& new View(new TheHtmlTestController());
  94. ClassRegistry::addObject('view', $view);
  95. $this->_appEncoding = Configure::read('App.encoding');
  96. $this->_asset = Configure::read('Asset');
  97. $this->_debug = Configure::read('debug');
  98. }
  99. /**
  100. * tearDown method
  101. *
  102. * @access public
  103. * @return void
  104. */
  105. function tearDown() {
  106. Configure::write('App.encoding', $this->_appEncoding);
  107. Configure::write('Asset', $this->_asset);
  108. Configure::write('debug', $this->_debug);
  109. ClassRegistry::flush();
  110. }
  111. /**
  112. * testDocType method
  113. *
  114. * @access public
  115. * @return void
  116. */
  117. function testDocType() {
  118. $result = $this->Html->docType();
  119. $expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  120. $this->assertEqual($result, $expected);
  121. $result = $this->Html->docType('html4-strict');
  122. $expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
  123. $this->assertEqual($result, $expected);
  124. $this->assertNull($this->Html->docType('non-existing-doctype'));
  125. }
  126. /**
  127. * testLink method
  128. *
  129. * @access public
  130. * @return void
  131. */
  132. function testLink() {
  133. $result = $this->Html->link('/home');
  134. $expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
  135. $this->assertTags($result, $expected);
  136. $result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
  137. $expected = array(
  138. 'a' => array('href' => '/home', 'onclick' => 'return confirm(&#039;Are you sure you want to do this?&#039;);'),
  139. 'Home',
  140. '/a'
  141. );
  142. $this->assertTags($result, $expected, true);
  143. $result = $this->Html->link('Home', '/home', array('default' => false));
  144. $expected = array(
  145. 'a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'),
  146. 'Home',
  147. '/a'
  148. );
  149. $this->assertTags($result, $expected);
  150. $result = $this->Html->link('Next >', '#');
  151. $expected = array(
  152. 'a' => array('href' => '#'),
  153. 'Next &gt;',
  154. '/a'
  155. );
  156. $this->assertTags($result, $expected);
  157. $result = $this->Html->link('Next >', '#', array('escape' => true));
  158. $expected = array(
  159. 'a' => array('href' => '#'),
  160. 'Next &gt;',
  161. '/a'
  162. );
  163. $this->assertTags($result, $expected);
  164. $result = $this->Html->link('Next >', '#', array('escape' => 'utf-8'));
  165. $expected = array(
  166. 'a' => array('href' => '#'),
  167. 'Next &gt;',
  168. '/a'
  169. );
  170. $this->assertTags($result, $expected);
  171. $result = $this->Html->link('Next >', '#', array('escape' => false));
  172. $expected = array(
  173. 'a' => array('href' => '#'),
  174. 'Next >',
  175. '/a'
  176. );
  177. $this->assertTags($result, $expected);
  178. $result = $this->Html->link('Next >', '#', array(
  179. 'title' => 'to escape &#8230; or not escape?',
  180. 'escape' => false
  181. ));
  182. $expected = array(
  183. 'a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'),
  184. 'Next >',
  185. '/a'
  186. );
  187. $this->assertTags($result, $expected);
  188. $result = $this->Html->link('Next >', '#', array(
  189. 'title' => 'to escape &#8230; or not escape?',
  190. 'escape' => true
  191. ), false, false);
  192. $expected = array(
  193. 'a' => array('href' => '#', 'title' => 'to escape &amp;#8230; or not escape?'),
  194. 'Next >',
  195. '/a'
  196. );
  197. $this->assertTags($result, $expected);
  198. $result = $this->Html->link('Original size', array(
  199. 'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
  200. ));
  201. $expected = array(
  202. 'a' => array('href' => '/images/view/3?height=100&amp;width=200'),
  203. 'Original size',
  204. '/a'
  205. );
  206. $this->assertTags($result, $expected);
  207. Configure::write('Asset.timestamp', false);
  208. $result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false);
  209. $expected = array(
  210. 'a' => array('href' => '#'),
  211. 'img' => array('src' => 'img/test.gif', 'alt' => ''),
  212. '/a'
  213. );
  214. $this->assertTags($result, $expected);
  215. $result = $this->Html->image('test.gif', array('url' => '#'));
  216. $expected = array(
  217. 'a' => array('href' => '#'),
  218. 'img' => array('src' => 'img/test.gif', 'alt' => ''),
  219. '/a'
  220. );
  221. $this->assertTags($result, $expected);
  222. Configure::write('Asset.timestamp', true);
  223. $result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false);
  224. $expected = array(
  225. 'a' => array('href' => '#'),
  226. 'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''),
  227. '/a'
  228. );
  229. $this->assertTags($result, $expected);
  230. $result = $this->Html->image('test.gif', array('url' => '#'));
  231. $expected = array(
  232. 'a' => array('href' => '#'),
  233. 'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''),
  234. '/a'
  235. );
  236. $this->assertTags($result, $expected);
  237. }
  238. /**
  239. * testImageTag method
  240. *
  241. * @access public
  242. * @return void
  243. */
  244. function testImageTag() {
  245. Configure::write('Asset.timestamp', false);
  246. $result = $this->Html->image('test.gif');
  247. $this->assertTags($result, array('img' => array('src' => 'img/test.gif', 'alt' => '')));
  248. $result = $this->Html->image('http://google.com/logo.gif');
  249. $this->assertTags($result, array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => '')));
  250. $result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, 'ext' => 'gif'));
  251. $this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
  252. $result = $this->Html->image('/test/view/1.gif');
  253. $this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
  254. Configure::write('Asset.timestamp', true);
  255. $result = $this->Html->image('cake.icon.gif');
  256. $this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.gif\?\d+/', 'alt' => '')));
  257. Configure::write('debug', 0);
  258. Configure::write('Asset.timestamp', 'force');
  259. $result = $this->Html->image('cake.icon.gif');
  260. $this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.gif\?\d+/', 'alt' => '')));
  261. $webroot = $this->Html->webroot;
  262. $this->Html->webroot = '/testing/longer/';
  263. $result = $this->Html->image('cake.icon.gif');
  264. $expected = array(
  265. 'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.gif\?[0-9]+/', 'alt' => '')
  266. );
  267. $this->assertTags($result, $expected);
  268. $this->Html->webroot = $webroot;
  269. }
  270. /**
  271. * Tests creation of an image tag using a theme and asset timestamping
  272. *
  273. * @access public
  274. * @return void
  275. * @link https://trac.cakephp.org/ticket/6490
  276. */
  277. function testImageTagWithTheme() {
  278. $file = WWW_ROOT . 'themed' . DS . 'default' . DS . 'img' . DS . 'cake.power.gif';
  279. $message = "File '{$file}' not present. %s";
  280. $this->skipUnless(file_exists($file), $message);
  281. Configure::write('Asset.timestamp', true);
  282. Configure::write('debug', 1);
  283. $this->Html->themeWeb = 'themed/default/';
  284. $result = $this->Html->image('cake.power.gif');
  285. $this->assertTags($result, array(
  286. 'img' => array(
  287. 'src' => 'preg:/themed\/default\/img\/cake\.power\.gif\?\d+/',
  288. 'alt' => ''
  289. )));
  290. $webroot = $this->Html->webroot;
  291. $this->Html->webroot = '/testing/';
  292. $result = $this->Html->image('cake.power.gif');
  293. $this->assertTags($result, array(
  294. 'img' => array(
  295. 'src' => 'preg:/\/testing\/themed\/default\/img\/cake\.power\.gif\?\d+/',
  296. 'alt' => ''
  297. )));
  298. $this->Html->webroot = $webroot;
  299. }
  300. /**
  301. * testStyle method
  302. *
  303. * @access public
  304. * @return void
  305. */
  306. function testStyle() {
  307. $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'));
  308. $expected = 'display:none; margin:10px;';
  309. $this->assertPattern('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected);
  310. $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'), false);
  311. $lines = explode("\n", $result);
  312. $this->assertPattern('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]);
  313. $this->assertPattern('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]);
  314. }
  315. /**
  316. * testCssLink method
  317. *
  318. * @access public
  319. * @return void
  320. */
  321. function testCssLink() {
  322. Configure::write('Asset.timestamp', false);
  323. Configure::write('Asset.filter.css', false);
  324. $result = $this->Html->css('screen');
  325. $expected = array(
  326. 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
  327. );
  328. $this->assertTags($result, $expected);
  329. $result = $this->Html->css('screen.css');
  330. $this->assertTags($result, $expected);
  331. $result = $this->Html->css('my.css.library');
  332. $expected['link']['href'] = 'preg:/.*css\/my\.css\.library\.css/';
  333. $this->assertTags($result, $expected);
  334. $result = $this->Html->css('my.css.php');
  335. $expected['link']['href'] = 'preg:/.*css\/my\.css\.php/';
  336. $this->assertTags($result, $expected);
  337. $result = $this->Html->css('screen.css?1234');
  338. $expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/';
  339. $this->assertTags($result, $expected);
  340. $result = $this->Html->css('http://whatever.com/screen.css?1234');
  341. $expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
  342. $this->assertTags($result, $expected);
  343. $result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
  344. $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
  345. $this->assertTags($result[0], $expected);
  346. $expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
  347. $this->assertTags($result[1], $expected);
  348. $this->assertEqual(count($result), 2);
  349. Configure::write('Asset.timestamp', true);
  350. $result = $this->Html->css('cake.generic');
  351. $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
  352. $this->assertTags($result, $expected);
  353. Configure::write('debug', 0);
  354. $result = $this->Html->css('cake.generic');
  355. $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
  356. $this->assertTags($result, $expected);
  357. Configure::write('Asset.timestamp', 'force');
  358. $result = $this->Html->css('cake.generic');
  359. $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
  360. $this->assertTags($result, $expected);
  361. $webroot = $this->Html->webroot;
  362. $this->Html->webroot = '/testing/';
  363. $result = $this->Html->css('cake.generic');
  364. $expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
  365. $this->assertTags($result, $expected);
  366. $this->Html->webroot = $webroot;
  367. $webroot = $this->Html->webroot;
  368. $this->Html->webroot = '/testing/longer/';
  369. $result = $this->Html->css('cake.generic');
  370. $expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
  371. $this->assertTags($result, $expected);
  372. $this->Html->webroot = $webroot;
  373. }
  374. /**
  375. * test css() with Asset.Css.filter
  376. *
  377. * @return void
  378. **/
  379. function testCssFiltering() {
  380. $this->Html->webroot = '/';
  381. Configure::write('Asset.filter.css', 'css.php');
  382. $result = $this->Html->css('cake.generic');
  383. $expected = array(
  384. 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/\/ccss\/cake\.generic\.css/')
  385. );
  386. $this->assertTags($result, $expected);
  387. Configure::write('Asset.timestamp', true);
  388. Configure::write('Asset.filter.css', 'css.php');
  389. $result = $this->Html->css('cake.generic');
  390. $expected['link']['href'] = 'preg:/\/ccss\/cake\.generic\.css\?[0-9]+/';
  391. $this->assertTags($result, $expected);
  392. Configure::write('Asset.timestamp', false);
  393. $result = $this->Html->css('myfoldercss/cake.generic');
  394. $expected['link']['href'] = 'preg:/\/ccss\/myfoldercss\/cake\.generic\.css/';
  395. $this->assertTags($result, $expected);
  396. $this->Html->webroot = '/testing/longer/';
  397. $result = $this->Html->css('myfoldercss/cake.generic');
  398. $expected['link']['href'] = 'preg:/\/testing\/longer\/ccss\/myfoldercss\/cake\.generic\.css/';
  399. $this->assertTags($result, $expected);
  400. Configure::write('Asset.filter.css', false);
  401. }
  402. /**
  403. * testCharsetTag method
  404. *
  405. * @access public
  406. * @return void
  407. */
  408. function testCharsetTag() {
  409. Configure::write('App.encoding', null);
  410. $result = $this->Html->charset();
  411. $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8')));
  412. Configure::write('App.encoding', 'ISO-8859-1');
  413. $result = $this->Html->charset();
  414. $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=iso-8859-1')));
  415. $result = $this->Html->charset('UTF-7');
  416. $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-7')));
  417. }
  418. /**
  419. * testBreadcrumb method
  420. *
  421. * @access public
  422. * @return void
  423. */
  424. function testBreadcrumb() {
  425. $this->Html->addCrumb('First', '#first');
  426. $this->Html->addCrumb('Second', '#second');
  427. $this->Html->addCrumb('Third', '#third');
  428. $result = $this->Html->getCrumbs();
  429. $expected = array(
  430. array('a' => array('href' => '#first')),
  431. 'First',
  432. '/a',
  433. '&raquo;',
  434. array('a' => array('href' => '#second')),
  435. 'Second',
  436. '/a',
  437. '&raquo;',
  438. array('a' => array('href' => '#third')),
  439. 'Third',
  440. '/a',
  441. );
  442. $this->assertTags($result, $expected);
  443. $result = $this->Html->getCrumbs(' &gt; ');
  444. $expected = array(
  445. array('a' => array('href' => '#first')),
  446. 'First',
  447. '/a',
  448. ' &gt; ',
  449. array('a' => array('href' => '#second')),
  450. 'Second',
  451. '/a',
  452. ' &gt; ',
  453. array('a' => array('href' => '#third')),
  454. 'Third',
  455. '/a',
  456. );
  457. $this->assertTags($result, $expected);
  458. $this->assertPattern('/^<a[^<>]+>First<\/a> &gt; <a[^<>]+>Second<\/a> &gt; <a[^<>]+>Third<\/a>$/', $result);
  459. $this->assertPattern('/<a\s+href=["\']+\#first["\']+[^<>]*>First<\/a>/', $result);
  460. $this->assertPattern('/<a\s+href=["\']+\#second["\']+[^<>]*>Second<\/a>/', $result);
  461. $this->assertPattern('/<a\s+href=["\']+\#third["\']+[^<>]*>Third<\/a>/', $result);
  462. $this->assertNoPattern('/<a[^<>]+[^href]=[^<>]*>/', $result);
  463. $this->Html->addCrumb('Fourth', null);
  464. $result = $this->Html->getCrumbs();
  465. $expected = array(
  466. array('a' => array('href' => '#first')),
  467. 'First',
  468. '/a',
  469. '&raquo;',
  470. array('a' => array('href' => '#second')),
  471. 'Second',
  472. '/a',
  473. '&raquo;',
  474. array('a' => array('href' => '#third')),
  475. 'Third',
  476. '/a',
  477. '&raquo;',
  478. 'Fourth'
  479. );
  480. $this->assertTags($result, $expected);
  481. }
  482. /**
  483. * testNestedList method
  484. *
  485. * @access public
  486. * @return void
  487. */
  488. function testNestedList() {
  489. $list = array(
  490. 'Item 1',
  491. 'Item 2' => array(
  492. 'Item 2.1'
  493. ),
  494. 'Item 3',
  495. 'Item 4' => array(
  496. 'Item 4.1',
  497. 'Item 4.2',
  498. 'Item 4.3' => array(
  499. 'Item 4.3.1',
  500. 'Item 4.3.2'
  501. )
  502. ),
  503. 'Item 5' => array(
  504. 'Item 5.1',
  505. 'Item 5.2'
  506. )
  507. );
  508. $result = $this->Html->nestedList($list);
  509. $expected = array(
  510. '<ul',
  511. '<li', 'Item 1', '/li',
  512. '<li', 'Item 2',
  513. '<ul', '<li', 'Item 2.1', '/li', '/ul',
  514. '/li',
  515. '<li', 'Item 3', '/li',
  516. '<li', 'Item 4',
  517. '<ul',
  518. '<li', 'Item 4.1', '/li',
  519. '<li', 'Item 4.2', '/li',
  520. '<li', 'Item 4.3',
  521. '<ul',
  522. '<li', 'Item 4.3.1', '/li',
  523. '<li', 'Item 4.3.2', '/li',
  524. '/ul',
  525. '/li',
  526. '/ul',
  527. '/li',
  528. '<li', 'Item 5',
  529. '<ul',
  530. '<li', 'Item 5.1', '/li',
  531. '<li', 'Item 5.2', '/li',
  532. '/ul',
  533. '/li',
  534. '/ul'
  535. );
  536. $this->assertTags($result, $expected);
  537. $result = $this->Html->nestedList($list, null);
  538. $expected = array(
  539. '<ul',
  540. '<li', 'Item 1', '/li',
  541. '<li', 'Item 2',
  542. '<ul', '<li', 'Item 2.1', '/li', '/ul',
  543. '/li',
  544. '<li', 'Item 3', '/li',
  545. '<li', 'Item 4',
  546. '<ul',
  547. '<li', 'Item 4.1', '/li',
  548. '<li', 'Item 4.2', '/li',
  549. '<li', 'Item 4.3',
  550. '<ul',
  551. '<li', 'Item 4.3.1', '/li',
  552. '<li', 'Item 4.3.2', '/li',
  553. '/ul',
  554. '/li',
  555. '/ul',
  556. '/li',
  557. '<li', 'Item 5',
  558. '<ul',
  559. '<li', 'Item 5.1', '/li',
  560. '<li', 'Item 5.2', '/li',
  561. '/ul',
  562. '/li',
  563. '/ul'
  564. );
  565. $this->assertTags($result, $expected);
  566. $result = $this->Html->nestedList($list, array(), array(), 'ol');
  567. $expected = array(
  568. '<ol',
  569. '<li', 'Item 1', '/li',
  570. '<li', 'Item 2',
  571. '<ol', '<li', 'Item 2.1', '/li', '/ol',
  572. '/li',
  573. '<li', 'Item 3', '/li',
  574. '<li', 'Item 4',
  575. '<ol',
  576. '<li', 'Item 4.1', '/li',
  577. '<li', 'Item 4.2', '/li',
  578. '<li', 'Item 4.3',
  579. '<ol',
  580. '<li', 'Item 4.3.1', '/li',
  581. '<li', 'Item 4.3.2', '/li',
  582. '/ol',
  583. '/li',
  584. '/ol',
  585. '/li',
  586. '<li', 'Item 5',
  587. '<ol',
  588. '<li', 'Item 5.1', '/li',
  589. '<li', 'Item 5.2', '/li',
  590. '/ol',
  591. '/li',
  592. '/ol'
  593. );
  594. $this->assertTags($result, $expected);
  595. $result = $this->Html->nestedList($list, 'ol');
  596. $expected = array(
  597. '<ol',
  598. '<li', 'Item 1', '/li',
  599. '<li', 'Item 2',
  600. '<ol', '<li', 'Item 2.1', '/li', '/ol',
  601. '/li',
  602. '<li', 'Item 3', '/li',
  603. '<li', 'Item 4',
  604. '<ol',
  605. '<li', 'Item 4.1', '/li',
  606. '<li', 'Item 4.2', '/li',
  607. '<li', 'Item 4.3',
  608. '<ol',
  609. '<li', 'Item 4.3.1', '/li',
  610. '<li', 'Item 4.3.2', '/li',
  611. '/ol',
  612. '/li',
  613. '/ol',
  614. '/li',
  615. '<li', 'Item 5',
  616. '<ol',
  617. '<li', 'Item 5.1', '/li',
  618. '<li', 'Item 5.2', '/li',
  619. '/ol',
  620. '/li',
  621. '/ol'
  622. );
  623. $this->assertTags($result, $expected);
  624. $result = $this->Html->nestedList($list, array('class'=>'list'));
  625. $expected = array(
  626. array('ul' => array('class' => 'list')),
  627. '<li', 'Item 1', '/li',
  628. '<li', 'Item 2',
  629. array('ul' => array('class' => 'list')), '<li', 'Item 2.1', '/li', '/ul',
  630. '/li',
  631. '<li', 'Item 3', '/li',
  632. '<li', 'Item 4',
  633. array('ul' => array('class' => 'list')),
  634. '<li', 'Item 4.1', '/li',
  635. '<li', 'Item 4.2', '/li',
  636. '<li', 'Item 4.3',
  637. array('ul' => array('class' => 'list')),
  638. '<li', 'Item 4.3.1', '/li',
  639. '<li', 'Item 4.3.2', '/li',
  640. '/ul',
  641. '/li',
  642. '/ul',
  643. '/li',
  644. '<li', 'Item 5',
  645. array('ul' => array('class' => 'list')),
  646. '<li', 'Item 5.1', '/li',
  647. '<li', 'Item 5.2', '/li',
  648. '/ul',
  649. '/li',
  650. '/ul'
  651. );
  652. $this->assertTags($result, $expected);
  653. $result = $this->Html->nestedList($list, array(), array('class' => 'item'));
  654. $expected = array(
  655. '<ul',
  656. array('li' => array('class' => 'item')), 'Item 1', '/li',
  657. array('li' => array('class' => 'item')), 'Item 2',
  658. '<ul', array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
  659. '/li',
  660. array('li' => array('class' => 'item')), 'Item 3', '/li',
  661. array('li' => array('class' => 'item')), 'Item 4',
  662. '<ul',
  663. array('li' => array('class' => 'item')), 'Item 4.1', '/li',
  664. array('li' => array('class' => 'item')), 'Item 4.2', '/li',
  665. array('li' => array('class' => 'item')), 'Item 4.3',
  666. '<ul',
  667. array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
  668. array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
  669. '/ul',
  670. '/li',
  671. '/ul',
  672. '/li',
  673. array('li' => array('class' => 'item')), 'Item 5',
  674. '<ul',
  675. array('li' => array('class' => 'item')), 'Item 5.1', '/li',
  676. array('li' => array('class' => 'item')), 'Item 5.2', '/li',
  677. '/ul',
  678. '/li',
  679. '/ul'
  680. );
  681. $this->assertTags($result, $expected);
  682. $result = $this->Html->nestedList($list, array(), array('even' => 'even', 'odd' => 'odd'));
  683. $expected = array(
  684. '<ul',
  685. array('li' => array('class' => 'odd')), 'Item 1', '/li',
  686. array('li' => array('class' => 'even')), 'Item 2',
  687. '<ul', array('li' => array('class' => 'odd')), 'Item 2.1', '/li', '/ul',
  688. '/li',
  689. array('li' => array('class' => 'odd')), 'Item 3', '/li',
  690. array('li' => array('class' => 'even')), 'Item 4',
  691. '<ul',
  692. array('li' => array('class' => 'odd')), 'Item 4.1', '/li',
  693. array('li' => array('class' => 'even')), 'Item 4.2', '/li',
  694. array('li' => array('class' => 'odd')), 'Item 4.3',
  695. '<ul',
  696. array('li' => array('class' => 'odd')), 'Item 4.3.1', '/li',
  697. array('li' => array('class' => 'even')), 'Item 4.3.2', '/li',
  698. '/ul',
  699. '/li',
  700. '/ul',
  701. '/li',
  702. array('li' => array('class' => 'odd')), 'Item 5',
  703. '<ul',
  704. array('li' => array('class' => 'odd')), 'Item 5.1', '/li',
  705. array('li' => array('class' => 'even')), 'Item 5.2', '/li',
  706. '/ul',
  707. '/li',
  708. '/ul'
  709. );
  710. $this->assertTags($result, $expected);
  711. $result = $this->Html->nestedList($list, array('class'=>'list'), array('class' => 'item'));
  712. $expected = array(
  713. array('ul' => array('class' => 'list')),
  714. array('li' => array('class' => 'item')), 'Item 1', '/li',
  715. array('li' => array('class' => 'item')), 'Item 2',
  716. array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
  717. '/li',
  718. array('li' => array('class' => 'item')), 'Item 3', '/li',
  719. array('li' => array('class' => 'item')), 'Item 4',
  720. array('ul' => array('class' => 'list')),
  721. array('li' => array('class' => 'item')), 'Item 4.1', '/li',
  722. array('li' => array('class' => 'item')), 'Item 4.2', '/li',
  723. array('li' => array('class' => 'item')), 'Item 4.3',
  724. array('ul' => array('class' => 'list')),
  725. array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
  726. array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
  727. '/ul',
  728. '/li',
  729. '/ul',
  730. '/li',
  731. array('li' => array('class' => 'item')), 'Item 5',
  732. array('ul' => array('class' => 'list')),
  733. array('li' => array('class' => 'item')), 'Item 5.1', '/li',
  734. array('li' => array('class' => 'item')), 'Item 5.2', '/li',
  735. '/ul',
  736. '/li',
  737. '/ul'
  738. );
  739. $this->assertTags($result, $expected);
  740. }
  741. /**
  742. * testMeta method
  743. *
  744. * @access public
  745. * @return void
  746. */
  747. function testMeta() {
  748. $result = $this->Html->meta('this is an rss feed', array('controller' => 'posts', 'ext' => 'rss'));
  749. $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
  750. $result = $this->Html->meta('rss', array('controller' => 'posts', 'ext' => 'rss'), array('title' => 'this is an rss feed'));
  751. $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
  752. $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'));
  753. $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom')));
  754. $result = $this->Html->meta('non-existing');
  755. $this->assertTags($result, array('<meta'));
  756. $result = $this->Html->meta('non-existing', '/posts.xpp');
  757. $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'non-existing')));
  758. $result = $this->Html->meta('non-existing', '/posts.xpp', array('type' => 'atom'));
  759. $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing')));
  760. $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'), array('link' => '/articles.rss'));
  761. $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/articles\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom')));
  762. $result = $this->Html->meta(array('link' => 'favicon.ico', 'rel' => 'icon'));
  763. $expected = array(
  764. 'link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'icon'),
  765. array('link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'shortcut icon'))
  766. );
  767. $this->assertTags($result, $expected);
  768. $result = $this->Html->meta('icon', 'favicon.ico');
  769. $expected = array(
  770. 'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
  771. array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
  772. );
  773. $this->assertTags($result, $expected);
  774. $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
  775. $this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
  776. $this->assertPattern('/\s+\/>$/', $result);
  777. $result = $this->Html->meta('description', 'this is the meta description');
  778. $this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));
  779. $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
  780. $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
  781. $this->assertNull($this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array(), false));
  782. $view =& ClassRegistry::getObject('view');
  783. $result = $view->__scripts[0];
  784. $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
  785. }
  786. /**
  787. * testTableHeaders method
  788. *
  789. * @access public
  790. * @return void
  791. */
  792. function testTableHeaders() {
  793. $result = $this->Html->tableHeaders(array('ID', 'Name', 'Date'));
  794. $expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
  795. $this->assertTags($result, $expected);
  796. }
  797. /**
  798. * testTableCells method
  799. *
  800. * @access public
  801. * @return void
  802. */
  803. function testTableCells() {
  804. $tr = array(
  805. 'td content 1',
  806. array('td content 2', array("width" => "100px")),
  807. array('td content 3', "width=100px")
  808. );
  809. $result = $this->Html->tableCells($tr);
  810. $expected = array(
  811. '<tr',
  812. '<td', 'td content 1', '/td',
  813. array('td' => array('width' => '100px')), 'td content 2', '/td',
  814. array('td' => array('width' => 'preg:/100px/')), 'td content 3', '/td',
  815. '/tr'
  816. );
  817. $this->assertTags($result, $expected);
  818. $tr = array('td content 1', 'td content 2', 'td content 3');
  819. $result = $this->Html->tableCells($tr, null, null, true);
  820. $expected = array(
  821. '<tr',
  822. array('td' => array('class' => 'column-1')), 'td content 1', '/td',
  823. array('td' => array('class' => 'column-2')), 'td content 2', '/td',
  824. array('td' => array('class' => 'column-3')), 'td content 3', '/td',
  825. '/tr'
  826. );
  827. $this->assertTags($result, $expected);
  828. $tr = array('td content 1', 'td content 2', 'td content 3');
  829. $result = $this->Html->tableCells($tr, true);
  830. $expected = array(
  831. '<tr',
  832. array('td' => array('class' => 'column-1')), 'td content 1', '/td',
  833. array('td' => array('class' => 'column-2')), 'td content 2', '/td',
  834. array('td' => array('class' => 'column-3')), 'td content 3', '/td',
  835. '/tr'
  836. );
  837. $this->assertTags($result, $expected);
  838. $tr = array(
  839. array('td content 1', 'td content 2', 'td content 3'),
  840. array('td content 1', 'td content 2', 'td content 3'),
  841. array('td content 1', 'td content 2', 'td content 3')
  842. );
  843. $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
  844. $expected = "<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
  845. $this->assertEqual($result, $expected);
  846. $tr = array(
  847. array('td content 1', 'td content 2', 'td content 3'),
  848. array('td content 1', 'td content 2', 'td content 3'),
  849. array('td content 1', 'td content 2', 'td content 3'),
  850. array('td content 1', 'td content 2', 'td content 3')
  851. );
  852. $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
  853. $expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
  854. $this->assertEqual($result, $expected);
  855. $tr = array(
  856. array('td content 1', 'td content 2', 'td content 3'),
  857. array('td content 1', 'td content 2', 'td content 3'),
  858. array('td content 1', 'td content 2', 'td content 3')
  859. );
  860. $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
  861. $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false);
  862. $expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
  863. $this->assertEqual($result, $expected);
  864. }
  865. /**
  866. * testTag method
  867. *
  868. * @access public
  869. * @return void
  870. */
  871. function testTag() {
  872. $result = $this->Html->tag('div');
  873. $this->assertTags($result, '<div');
  874. $result = $this->Html->tag('div', 'text');
  875. $this->assertTags($result, '<div', 'text', '/div');
  876. $result = $this->Html->tag('div', '<text>', array('class' => 'class-name'), true);
  877. $this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
  878. $result = $this->Html->tag('div', '<text>', 'class-name', true);
  879. $this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
  880. }
  881. /**
  882. * testDiv method
  883. *
  884. * @access public
  885. * @return void
  886. */
  887. function testDiv() {
  888. $result = $this->Html->div('class-name');
  889. $this->assertTags($result, array('div' => array('class' => 'class-name')));
  890. $result = $this->Html->div('class-name', 'text');
  891. $this->assertTags($result, array('div' => array('class' => 'class-name'), 'text', '/div'));
  892. $result = $this->Html->div('class-name', '<text>', array(), true);
  893. $this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
  894. }
  895. /**
  896. * testPara method
  897. *
  898. * @access public
  899. * @return void
  900. */
  901. function testPara() {
  902. $result = $this->Html->para('class-name', '');
  903. $this->assertTags($result, array('p' => array('class' => 'class-name')));
  904. $result = $this->Html->para('class-name', 'text');
  905. $this->assertTags($result, array('p' => array('class' => 'class-name'), 'text', '/p'));
  906. $result = $this->Html->para('class-name', '<text>', array(), true);
  907. $this->assertTags($result, array('p' => array('class' => 'class-name'), '&lt;text&gt;', '/p'));
  908. }
  909. }
  910. ?>