comparison cake/tests/cases/libs/view/helpers/html.test.php @ 0:261e66bd5a0c

hg init
author Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Jul 2011 21:08:31 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:261e66bd5a0c
1 <?php
2 /**
3 * HtmlHelperTest file
4 *
5 * PHP versions 4 and 5
6 *
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8 * Copyright 2006-2010, Cake Software Foundation, Inc.
9 *
10 * Licensed under The Open Group Test Suite License
11 * Redistributions of files must retain the above copyright notice.
12 *
13 * @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
14 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
15 * @package cake
16 * @subpackage cake.tests.cases.libs.view.helpers
17 * @since CakePHP(tm) v 1.2.0.4206
18 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
19 */
20 App::import('Core', array('Helper', 'AppHelper', 'ClassRegistry', 'Controller', 'Model'));
21 App::import('Helper', array('Html', 'Form'));
22
23 if (!defined('FULL_BASE_URL')) {
24 define('FULL_BASE_URL', 'http://cakephp.org');
25 }
26
27 /**
28 * TheHtmlTestController class
29 *
30 * @package cake
31 * @subpackage cake.tests.cases.libs.view.helpers
32 */
33 class TheHtmlTestController extends Controller {
34
35 /**
36 * name property
37 *
38 * @var string 'TheTest'
39 * @access public
40 */
41 var $name = 'TheTest';
42
43 /**
44 * uses property
45 *
46 * @var mixed null
47 * @access public
48 */
49 var $uses = null;
50 }
51
52 Mock::generate('View', 'HtmlHelperMockView');
53
54 /**
55 * HtmlHelperTest class
56 *
57 * @package cake
58 * @subpackage cake.tests.cases.libs.view.helpers
59 */
60 class HtmlHelperTest extends CakeTestCase {
61
62 /**
63 * Regexp for CDATA start block
64 *
65 * @var string
66 */
67 var $cDataStart = 'preg:/^\/\/<!\[CDATA\[[\n\r]*/';
68 /**
69 * Regexp for CDATA end block
70 *
71 * @var string
72 */
73 var $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/';
74 /**
75 * html property
76 *
77 * @var object
78 * @access public
79 */
80 var $Html = null;
81
82 /**
83 * Backup of app encoding configuration setting
84 *
85 * @var string
86 * @access protected
87 */
88 var $_appEncoding;
89
90 /**
91 * Backup of asset configuration settings
92 *
93 * @var string
94 * @access protected
95 */
96 var $_asset;
97
98 /**
99 * Backup of debug configuration setting
100 *
101 * @var integer
102 * @access protected
103 */
104 var $_debug;
105
106 /**
107 * setUp method
108 *
109 * @access public
110 * @return void
111 */
112 function startTest() {
113 $this->Html =& new HtmlHelper();
114 $view =& new View(new TheHtmlTestController());
115 ClassRegistry::addObject('view', $view);
116 $this->_appEncoding = Configure::read('App.encoding');
117 $this->_asset = Configure::read('Asset');
118 $this->_debug = Configure::read('debug');
119 }
120
121 /**
122 * endTest method
123 *
124 * @access public
125 * @return void
126 */
127 function endTest() {
128 Configure::write('App.encoding', $this->_appEncoding);
129 Configure::write('Asset', $this->_asset);
130 Configure::write('debug', $this->_debug);
131 ClassRegistry::flush();
132 unset($this->Html);
133 }
134
135 /**
136 * testDocType method
137 *
138 * @access public
139 * @return void
140 */
141 function testDocType() {
142 $result = $this->Html->docType();
143 $expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
144 $this->assertEqual($result, $expected);
145
146 $result = $this->Html->docType('html4-strict');
147 $expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
148 $this->assertEqual($result, $expected);
149
150 $this->assertNull($this->Html->docType('non-existing-doctype'));
151 }
152
153 /**
154 * testLink method
155 *
156 * @access public
157 * @return void
158 */
159 function testLink() {
160 $result = $this->Html->link('/home');
161 $expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
162 $this->assertTags($result, $expected);
163
164 $result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', 'full_base' => true));
165 $expected = array('a' => array('href' => FULL_BASE_URL . '/posts'), 'Posts', '/a');
166 $this->assertTags($result, $expected);
167
168 $result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
169 $expected = array(
170 'a' => array('href' => '/home', 'onclick' => 'return confirm(&#039;Are you sure you want to do this?&#039;);'),
171 'Home',
172 '/a'
173 );
174 $this->assertTags($result, $expected, true);
175
176 $result = $this->Html->link('Home', '/home', array('default' => false));
177 $expected = array(
178 'a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'),
179 'Home',
180 '/a'
181 );
182 $this->assertTags($result, $expected);
183
184 $result = $this->Html->link('Next >', '#');
185 $expected = array(
186 'a' => array('href' => '#'),
187 'Next &gt;',
188 '/a'
189 );
190 $this->assertTags($result, $expected);
191
192 $result = $this->Html->link('Next >', '#', array('escape' => true));
193 $expected = array(
194 'a' => array('href' => '#'),
195 'Next &gt;',
196 '/a'
197 );
198 $this->assertTags($result, $expected);
199
200 $result = $this->Html->link('Next >', '#', array('escape' => 'utf-8'));
201 $expected = array(
202 'a' => array('href' => '#'),
203 'Next &gt;',
204 '/a'
205 );
206 $this->assertTags($result, $expected);
207
208 $result = $this->Html->link('Next >', '#', array('escape' => false));
209 $expected = array(
210 'a' => array('href' => '#'),
211 'Next >',
212 '/a'
213 );
214 $this->assertTags($result, $expected);
215
216 $result = $this->Html->link('Next >', '#', array(
217 'title' => 'to escape &#8230; or not escape?',
218 'escape' => false
219 ));
220 $expected = array(
221 'a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'),
222 'Next >',
223 '/a'
224 );
225 $this->assertTags($result, $expected);
226
227 $result = $this->Html->link('Next >', '#', array(
228 'title' => 'to escape &#8230; or not escape?',
229 'escape' => true
230 ));
231 $expected = array(
232 'a' => array('href' => '#', 'title' => 'to escape &amp;#8230; or not escape?'),
233 'Next &gt;',
234 '/a'
235 );
236 $this->assertTags($result, $expected);
237
238 $result = $this->Html->link('Original size', array(
239 'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
240 ));
241 $expected = array(
242 'a' => array('href' => '/images/view/3?height=100&amp;width=200'),
243 'Original size',
244 '/a'
245 );
246 $this->assertTags($result, $expected);
247
248 Configure::write('Asset.timestamp', false);
249
250 $result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false));
251 $expected = array(
252 'a' => array('href' => '#'),
253 'img' => array('src' => 'img/test.gif', 'alt' => ''),
254 '/a'
255 );
256 $this->assertTags($result, $expected);
257
258 $result = $this->Html->image('test.gif', array('url' => '#'));
259 $expected = array(
260 'a' => array('href' => '#'),
261 'img' => array('src' => 'img/test.gif', 'alt' => ''),
262 '/a'
263 );
264 $this->assertTags($result, $expected);
265
266 Configure::write('Asset.timestamp', 'force');
267
268 $result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false));
269 $expected = array(
270 'a' => array('href' => '#'),
271 'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''),
272 '/a'
273 );
274 $this->assertTags($result, $expected);
275
276 $result = $this->Html->image('test.gif', array('url' => '#'));
277 $expected = array(
278 'a' => array('href' => '#'),
279 'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''),
280 '/a'
281 );
282 $this->assertTags($result, $expected);
283 }
284
285 /**
286 * testImageTag method
287 *
288 * @access public
289 * @return void
290 */
291 function testImageTag() {
292 Configure::write('Asset.timestamp', false);
293
294 $result = $this->Html->image('test.gif');
295 $this->assertTags($result, array('img' => array('src' => 'img/test.gif', 'alt' => '')));
296
297 $result = $this->Html->image('http://google.com/logo.gif');
298 $this->assertTags($result, array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => '')));
299
300 $result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, 'ext' => 'gif'));
301 $this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
302
303 $result = $this->Html->image('/test/view/1.gif');
304 $this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
305 }
306
307 /**
308 * test image() with Asset.timestamp
309 *
310 * @return void
311 */
312 function testImageWithTimestampping() {
313 Configure::write('Asset.timestamp', 'force');
314
315 $this->Html->webroot = '/';
316 $result = $this->Html->image('cake.icon.png');
317 $this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
318
319 Configure::write('debug', 0);
320 Configure::write('Asset.timestamp', 'force');
321
322 $result = $this->Html->image('cake.icon.png');
323 $this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
324
325 $webroot = $this->Html->webroot;
326 $this->Html->webroot = '/testing/longer/';
327 $result = $this->Html->image('cake.icon.png');
328 $expected = array(
329 'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/', 'alt' => '')
330 );
331 $this->assertTags($result, $expected);
332 $this->Html->webroot = $webroot;
333 }
334
335 /**
336 * Tests creation of an image tag using a theme and asset timestamping
337 *
338 * @access public
339 * @return void
340 * @link https://trac.cakephp.org/ticket/6490
341 */
342 function testImageTagWithTheme() {
343 if ($this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme')) {
344 return;
345 }
346 App::import('Core', 'File');
347
348 $testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
349 $file =& new File($testfile, true);
350
351 App::build(array(
352 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
353 ));
354 Configure::write('Asset.timestamp', true);
355 Configure::write('debug', 1);
356
357 $this->Html->webroot = '/';
358 $this->Html->theme = 'test_theme';
359 $result = $this->Html->image('__cake_test_image.gif');
360 $this->assertTags($result, array(
361 'img' => array(
362 'src' => 'preg:/\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
363 'alt' => ''
364 )));
365
366 $webroot = $this->Html->webroot;
367 $this->Html->webroot = '/testing/';
368 $result = $this->Html->image('__cake_test_image.gif');
369
370 $this->assertTags($result, array(
371 'img' => array(
372 'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
373 'alt' => ''
374 )));
375 $this->Html->webroot = $webroot;
376
377 $dir =& new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
378 $dir->delete();
379 }
380
381 /**
382 * test theme assets in main webroot path
383 *
384 * @access public
385 * @return void
386 */
387 function testThemeAssetsInMainWebrootPath() {
388 Configure::write('Asset.timestamp', false);
389 App::build(array(
390 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
391 ));
392 $webRoot = Configure::read('App.www_root');
393 Configure::write('App.www_root', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'webroot' . DS);
394
395 $webroot = $this->Html->webroot;
396 $this->Html->theme = 'test_theme';
397 $result = $this->Html->css('webroot_test');
398 $expected = array(
399 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/webroot_test\.css/')
400 );
401 $this->assertTags($result, $expected);
402
403 $webroot = $this->Html->webroot;
404 $this->Html->theme = 'test_theme';
405 $result = $this->Html->css('theme_webroot');
406 $expected = array(
407 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/theme_webroot\.css/')
408 );
409 $this->assertTags($result, $expected);
410
411 Configure::write('App.www_root', $webRoot);
412 }
413
414 /**
415 * testStyle method
416 *
417 * @access public
418 * @return void
419 */
420 function testStyle() {
421 $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'));
422 $expected = 'display:none; margin:10px;';
423 $this->assertPattern('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected);
424
425 $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'), false);
426 $lines = explode("\n", $result);
427 $this->assertPattern('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]);
428 $this->assertPattern('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]);
429 }
430
431 /**
432 * testCssLink method
433 *
434 * @access public
435 * @return void
436 */
437 function testCssLink() {
438 Configure::write('Asset.timestamp', false);
439 Configure::write('Asset.filter.css', false);
440
441 $result = $this->Html->css('screen');
442 $expected = array(
443 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
444 );
445 $this->assertTags($result, $expected);
446
447 $result = $this->Html->css('screen.css');
448 $this->assertTags($result, $expected);
449
450 $result = $this->Html->css('my.css.library');
451 $expected['link']['href'] = 'preg:/.*css\/my\.css\.library\.css/';
452 $this->assertTags($result, $expected);
453
454 $result = $this->Html->css('screen.css?1234');
455 $expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/';
456 $this->assertTags($result, $expected);
457
458 $result = $this->Html->css('http://whatever.com/screen.css?1234');
459 $expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
460 $this->assertTags($result, $expected);
461
462 Configure::write('Asset.filter.css', 'css.php');
463 $result = $this->Html->css('cake.generic');
464 $expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
465 $this->assertTags($result, $expected);
466
467 Configure::write('Asset.filter.css', false);
468
469 $result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
470 $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
471 $this->assertTags($result[0], $expected);
472 $expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
473 $this->assertTags($result[1], $expected);
474 $this->assertEqual(count($result), 2);
475
476 ClassRegistry::removeObject('view');
477 $view =& new HtmlHelperMockView();
478 ClassRegistry::addObject('view', $view);
479 $view->expectAt(0, 'addScript', array(new PatternExpectation('/css_in_head.css/')));
480 $result = $this->Html->css('css_in_head', null, array('inline' => false));
481 $this->assertNull($result);
482
483 $view =& ClassRegistry::getObject('view');
484 $view->expectAt(1, 'addScript', array(new NoPatternExpectation('/inline=""/')));
485 $result = $this->Html->css('more_css_in_head', null, array('inline' => false));
486 $this->assertNull($result);
487 }
488
489 /**
490 * test use of css() and timestamping
491 *
492 * @return void
493 */
494 function testCssTimestamping() {
495 Configure::write('debug', 2);
496 Configure::write('Asset.timestamp', true);
497
498 $expected = array(
499 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => '')
500 );
501
502 $result = $this->Html->css('cake.generic');
503 $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
504 $this->assertTags($result, $expected);
505
506 Configure::write('debug', 0);
507
508 $result = $this->Html->css('cake.generic');
509 $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
510 $this->assertTags($result, $expected);
511
512 Configure::write('Asset.timestamp', 'force');
513
514 $result = $this->Html->css('cake.generic');
515 $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
516 $this->assertTags($result, $expected);
517
518 $webroot = $this->Html->webroot;
519 $this->Html->webroot = '/testing/';
520 $result = $this->Html->css('cake.generic');
521 $expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
522 $this->assertTags($result, $expected);
523 $this->Html->webroot = $webroot;
524
525 $webroot = $this->Html->webroot;
526 $this->Html->webroot = '/testing/longer/';
527 $result = $this->Html->css('cake.generic');
528 $expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
529 $this->assertTags($result, $expected);
530 $this->Html->webroot = $webroot;
531 }
532
533 /**
534 * test timestamp enforcement for script tags.
535 *
536 * @return void
537 */
538 function testScriptTimestamping() {
539 $skip = $this->skipIf(!is_writable(JS), 'webroot/js is not Writable, timestamp testing has been skipped');
540 if ($skip) {
541 return;
542 }
543 Configure::write('debug', 2);
544 Configure::write('Asset.timestamp', true);
545
546 touch(WWW_ROOT . 'js' . DS. '__cake_js_test.js');
547 $timestamp = substr(strtotime('now'), 0, 8);
548
549 $result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false));
550 $this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
551
552 Configure::write('debug', 0);
553 Configure::write('Asset.timestamp', 'force');
554 $result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false));
555 $this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
556 unlink(WWW_ROOT . 'js' . DS. '__cake_js_test.js');
557 Configure::write('Asset.timestamp', false);
558 }
559
560 /**
561 * test that scripts added with uses() are only ever included once.
562 * test script tag generation
563 *
564 * @return void
565 */
566 function testScript() {
567 Configure::write('Asset.timestamp', false);
568 $result = $this->Html->script('foo');
569 $expected = array(
570 'script' => array('type' => 'text/javascript', 'src' => 'js/foo.js')
571 );
572 $this->assertTags($result, $expected);
573
574 $result = $this->Html->script(array('foobar', 'bar'));
575 $expected = array(
576 array('script' => array('type' => 'text/javascript', 'src' => 'js/foobar.js')),
577 '/script',
578 array('script' => array('type' => 'text/javascript', 'src' => 'js/bar.js')),
579 '/script',
580 );
581 $this->assertTags($result, $expected);
582
583 $result = $this->Html->script('jquery-1.3');
584 $expected = array(
585 'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.js')
586 );
587 $this->assertTags($result, $expected);
588
589 $result = $this->Html->script('test.json');
590 $expected = array(
591 'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js')
592 );
593 $this->assertTags($result, $expected);
594
595 $result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo');
596 $expected = array(
597 'script' => array('type' => 'text/javascript', 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo')
598 );
599 $this->assertTags($result, $expected);
600
601 $result = $this->Html->script('test.json.js?foo=bar');
602 $expected = array(
603 'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js?foo=bar')
604 );
605 $this->assertTags($result, $expected);
606
607 $result = $this->Html->script('foo');
608 $this->assertNull($result, 'Script returned upon duplicate inclusion %s');
609
610 $result = $this->Html->script(array('foo', 'bar', 'baz'));
611 $this->assertNoPattern('/foo.js/', $result);
612
613 $result = $this->Html->script('foo', array('inline' => true, 'once' => false));
614 $this->assertNotNull($result);
615
616 $result = $this->Html->script('jquery-1.3.2', array('defer' => true, 'encoding' => 'utf-8'));
617 $expected = array(
618 'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8')
619 );
620 $this->assertTags($result, $expected);
621
622 $view =& ClassRegistry::getObject('view');
623 $view =& new HtmlHelperMockView();
624 $view->expectAt(0, 'addScript', array(new PatternExpectation('/script_in_head.js/')));
625 $result = $this->Html->script('script_in_head', array('inline' => false));
626 $this->assertNull($result);
627 }
628
629 /**
630 * test a script file in the webroot/theme dir.
631 *
632 * @return void
633 */
634 function testScriptInTheme() {
635 if ($this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme')) {
636 return;
637 }
638 App::import('Core', 'File');
639
640 $testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'js' . DS . '__test_js.js';
641 $file =& new File($testfile, true);
642
643 App::build(array(
644 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
645 ));
646
647 $this->Html->webroot = '/';
648 $this->Html->theme = 'test_theme';
649 $result = $this->Html->script('__test_js.js');
650 $expected = array(
651 'script' => array('src' => '/theme/test_theme/js/__test_js.js', 'type' => 'text/javascript')
652 );
653 $this->assertTags($result, $expected);
654 App::build();
655 }
656
657 /**
658 * test Script block generation
659 *
660 * @return void
661 */
662 function testScriptBlock() {
663 $result = $this->Html->scriptBlock('window.foo = 2;');
664 $expected = array(
665 'script' => array('type' => 'text/javascript'),
666 $this->cDataStart,
667 'window.foo = 2;',
668 $this->cDataEnd,
669 '/script',
670 );
671 $this->assertTags($result, $expected);
672
673 $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false));
674 $expected = array(
675 'script' => array('type' => 'text/javascript'),
676 'window.foo = 2;',
677 '/script',
678 );
679 $this->assertTags($result, $expected);
680
681 $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => true));
682 $expected = array(
683 'script' => array('type' => 'text/javascript'),
684 $this->cDataStart,
685 'window.foo = 2;',
686 $this->cDataEnd,
687 '/script',
688 );
689 $this->assertTags($result, $expected);
690
691 $view =& ClassRegistry::getObject('view');
692 $view =& new HtmlHelperMockView();
693 $view->expectAt(0, 'addScript', array(new PatternExpectation('/window\.foo\s\=\s2;/')));
694
695 $result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false));
696 $this->assertNull($result);
697
698 $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false, 'encoding' => 'utf-8'));
699 $expected = array(
700 'script' => array('type' => 'text/javascript', 'encoding' => 'utf-8'),
701 'window.foo = 2;',
702 '/script',
703 );
704 $this->assertTags($result, $expected);
705 }
706
707 /**
708 * test script tag output buffering when using scriptStart() and scriptEnd();
709 *
710 * @return void
711 */
712 function testScriptStartAndScriptEnd() {
713 $result = $this->Html->scriptStart(array('safe' => true));
714 $this->assertNull($result);
715 echo 'this is some javascript';
716
717 $result = $this->Html->scriptEnd();
718 $expected = array(
719 'script' => array('type' => 'text/javascript'),
720 $this->cDataStart,
721 'this is some javascript',
722 $this->cDataEnd,
723 '/script'
724 );
725 $this->assertTags($result, $expected);
726
727
728 $result = $this->Html->scriptStart(array('safe' => false));
729 $this->assertNull($result);
730 echo 'this is some javascript';
731
732 $result = $this->Html->scriptEnd();
733 $expected = array(
734 'script' => array('type' => 'text/javascript'),
735 'this is some javascript',
736 '/script'
737 );
738 $this->assertTags($result, $expected);
739
740 ClassRegistry::removeObject('view');
741 $View =& new HtmlHelperMockView();
742
743 $View->expectOnce('addScript');
744 ClassRegistry::addObject('view', $View);
745
746 $result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
747 $this->assertNull($result);
748 echo 'this is some javascript';
749
750 $result = $this->Html->scriptEnd();
751 $this->assertNull($result);
752 }
753
754 /**
755 * testCharsetTag method
756 *
757 * @access public
758 * @return void
759 */
760 function testCharsetTag() {
761 Configure::write('App.encoding', null);
762 $result = $this->Html->charset();
763 $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8')));
764
765 Configure::write('App.encoding', 'ISO-8859-1');
766 $result = $this->Html->charset();
767 $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=iso-8859-1')));
768
769 $result = $this->Html->charset('UTF-7');
770 $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-7')));
771 }
772
773 /**
774 * testBreadcrumb method
775 *
776 * @access public
777 * @return void
778 */
779 function testBreadcrumb() {
780 $this->Html->addCrumb('First', '#first');
781 $this->Html->addCrumb('Second', '#second');
782 $this->Html->addCrumb('Third', '#third');
783
784 $result = $this->Html->getCrumbs();
785 $expected = array(
786 array('a' => array('href' => '#first')),
787 'First',
788 '/a',
789 '&raquo;',
790 array('a' => array('href' => '#second')),
791 'Second',
792 '/a',
793 '&raquo;',
794 array('a' => array('href' => '#third')),
795 'Third',
796 '/a',
797 );
798 $this->assertTags($result, $expected);
799
800 $result = $this->Html->getCrumbs(' &gt; ');
801 $expected = array(
802 array('a' => array('href' => '#first')),
803 'First',
804 '/a',
805 ' &gt; ',
806 array('a' => array('href' => '#second')),
807 'Second',
808 '/a',
809 ' &gt; ',
810 array('a' => array('href' => '#third')),
811 'Third',
812 '/a',
813 );
814 $this->assertTags($result, $expected);
815
816 $this->assertPattern('/^<a[^<>]+>First<\/a> &gt; <a[^<>]+>Second<\/a> &gt; <a[^<>]+>Third<\/a>$/', $result);
817 $this->assertPattern('/<a\s+href=["\']+\#first["\']+[^<>]*>First<\/a>/', $result);
818 $this->assertPattern('/<a\s+href=["\']+\#second["\']+[^<>]*>Second<\/a>/', $result);
819 $this->assertPattern('/<a\s+href=["\']+\#third["\']+[^<>]*>Third<\/a>/', $result);
820 $this->assertNoPattern('/<a[^<>]+[^href]=[^<>]*>/', $result);
821
822 $this->Html->addCrumb('Fourth', null);
823
824 $result = $this->Html->getCrumbs();
825 $expected = array(
826 array('a' => array('href' => '#first')),
827 'First',
828 '/a',
829 '&raquo;',
830 array('a' => array('href' => '#second')),
831 'Second',
832 '/a',
833 '&raquo;',
834 array('a' => array('href' => '#third')),
835 'Third',
836 '/a',
837 '&raquo;',
838 'Fourth'
839 );
840 $this->assertTags($result, $expected);
841 }
842
843 /**
844 * testNestedList method
845 *
846 * @access public
847 * @return void
848 */
849 function testNestedList() {
850 $list = array(
851 'Item 1',
852 'Item 2' => array(
853 'Item 2.1'
854 ),
855 'Item 3',
856 'Item 4' => array(
857 'Item 4.1',
858 'Item 4.2',
859 'Item 4.3' => array(
860 'Item 4.3.1',
861 'Item 4.3.2'
862 )
863 ),
864 'Item 5' => array(
865 'Item 5.1',
866 'Item 5.2'
867 )
868 );
869
870 $result = $this->Html->nestedList($list);
871 $expected = array(
872 '<ul',
873 '<li', 'Item 1', '/li',
874 '<li', 'Item 2',
875 '<ul', '<li', 'Item 2.1', '/li', '/ul',
876 '/li',
877 '<li', 'Item 3', '/li',
878 '<li', 'Item 4',
879 '<ul',
880 '<li', 'Item 4.1', '/li',
881 '<li', 'Item 4.2', '/li',
882 '<li', 'Item 4.3',
883 '<ul',
884 '<li', 'Item 4.3.1', '/li',
885 '<li', 'Item 4.3.2', '/li',
886 '/ul',
887 '/li',
888 '/ul',
889 '/li',
890 '<li', 'Item 5',
891 '<ul',
892 '<li', 'Item 5.1', '/li',
893 '<li', 'Item 5.2', '/li',
894 '/ul',
895 '/li',
896 '/ul'
897 );
898 $this->assertTags($result, $expected);
899
900 $result = $this->Html->nestedList($list, null);
901 $expected = array(
902 '<ul',
903 '<li', 'Item 1', '/li',
904 '<li', 'Item 2',
905 '<ul', '<li', 'Item 2.1', '/li', '/ul',
906 '/li',
907 '<li', 'Item 3', '/li',
908 '<li', 'Item 4',
909 '<ul',
910 '<li', 'Item 4.1', '/li',
911 '<li', 'Item 4.2', '/li',
912 '<li', 'Item 4.3',
913 '<ul',
914 '<li', 'Item 4.3.1', '/li',
915 '<li', 'Item 4.3.2', '/li',
916 '/ul',
917 '/li',
918 '/ul',
919 '/li',
920 '<li', 'Item 5',
921 '<ul',
922 '<li', 'Item 5.1', '/li',
923 '<li', 'Item 5.2', '/li',
924 '/ul',
925 '/li',
926 '/ul'
927 );
928 $this->assertTags($result, $expected);
929
930 $result = $this->Html->nestedList($list, array(), array(), 'ol');
931 $expected = array(
932 '<ol',
933 '<li', 'Item 1', '/li',
934 '<li', 'Item 2',
935 '<ol', '<li', 'Item 2.1', '/li', '/ol',
936 '/li',
937 '<li', 'Item 3', '/li',
938 '<li', 'Item 4',
939 '<ol',
940 '<li', 'Item 4.1', '/li',
941 '<li', 'Item 4.2', '/li',
942 '<li', 'Item 4.3',
943 '<ol',
944 '<li', 'Item 4.3.1', '/li',
945 '<li', 'Item 4.3.2', '/li',
946 '/ol',
947 '/li',
948 '/ol',
949 '/li',
950 '<li', 'Item 5',
951 '<ol',
952 '<li', 'Item 5.1', '/li',
953 '<li', 'Item 5.2', '/li',
954 '/ol',
955 '/li',
956 '/ol'
957 );
958 $this->assertTags($result, $expected);
959
960 $result = $this->Html->nestedList($list, 'ol');
961 $expected = array(
962 '<ol',
963 '<li', 'Item 1', '/li',
964 '<li', 'Item 2',
965 '<ol', '<li', 'Item 2.1', '/li', '/ol',
966 '/li',
967 '<li', 'Item 3', '/li',
968 '<li', 'Item 4',
969 '<ol',
970 '<li', 'Item 4.1', '/li',
971 '<li', 'Item 4.2', '/li',
972 '<li', 'Item 4.3',
973 '<ol',
974 '<li', 'Item 4.3.1', '/li',
975 '<li', 'Item 4.3.2', '/li',
976 '/ol',
977 '/li',
978 '/ol',
979 '/li',
980 '<li', 'Item 5',
981 '<ol',
982 '<li', 'Item 5.1', '/li',
983 '<li', 'Item 5.2', '/li',
984 '/ol',
985 '/li',
986 '/ol'
987 );
988 $this->assertTags($result, $expected);
989
990 $result = $this->Html->nestedList($list, array('class'=>'list'));
991 $expected = array(
992 array('ul' => array('class' => 'list')),
993 '<li', 'Item 1', '/li',
994 '<li', 'Item 2',
995 array('ul' => array('class' => 'list')), '<li', 'Item 2.1', '/li', '/ul',
996 '/li',
997 '<li', 'Item 3', '/li',
998 '<li', 'Item 4',
999 array('ul' => array('class' => 'list')),
1000 '<li', 'Item 4.1', '/li',
1001 '<li', 'Item 4.2', '/li',
1002 '<li', 'Item 4.3',
1003 array('ul' => array('class' => 'list')),
1004 '<li', 'Item 4.3.1', '/li',
1005 '<li', 'Item 4.3.2', '/li',
1006 '/ul',
1007 '/li',
1008 '/ul',
1009 '/li',
1010 '<li', 'Item 5',
1011 array('ul' => array('class' => 'list')),
1012 '<li', 'Item 5.1', '/li',
1013 '<li', 'Item 5.2', '/li',
1014 '/ul',
1015 '/li',
1016 '/ul'
1017 );
1018 $this->assertTags($result, $expected);
1019
1020 $result = $this->Html->nestedList($list, array(), array('class' => 'item'));
1021 $expected = array(
1022 '<ul',
1023 array('li' => array('class' => 'item')), 'Item 1', '/li',
1024 array('li' => array('class' => 'item')), 'Item 2',
1025 '<ul', array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
1026 '/li',
1027 array('li' => array('class' => 'item')), 'Item 3', '/li',
1028 array('li' => array('class' => 'item')), 'Item 4',
1029 '<ul',
1030 array('li' => array('class' => 'item')), 'Item 4.1', '/li',
1031 array('li' => array('class' => 'item')), 'Item 4.2', '/li',
1032 array('li' => array('class' => 'item')), 'Item 4.3',
1033 '<ul',
1034 array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
1035 array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
1036 '/ul',
1037 '/li',
1038 '/ul',
1039 '/li',
1040 array('li' => array('class' => 'item')), 'Item 5',
1041 '<ul',
1042 array('li' => array('class' => 'item')), 'Item 5.1', '/li',
1043 array('li' => array('class' => 'item')), 'Item 5.2', '/li',
1044 '/ul',
1045 '/li',
1046 '/ul'
1047 );
1048 $this->assertTags($result, $expected);
1049
1050 $result = $this->Html->nestedList($list, array(), array('even' => 'even', 'odd' => 'odd'));
1051 $expected = array(
1052 '<ul',
1053 array('li' => array('class' => 'odd')), 'Item 1', '/li',
1054 array('li' => array('class' => 'even')), 'Item 2',
1055 '<ul', array('li' => array('class' => 'odd')), 'Item 2.1', '/li', '/ul',
1056 '/li',
1057 array('li' => array('class' => 'odd')), 'Item 3', '/li',
1058 array('li' => array('class' => 'even')), 'Item 4',
1059 '<ul',
1060 array('li' => array('class' => 'odd')), 'Item 4.1', '/li',
1061 array('li' => array('class' => 'even')), 'Item 4.2', '/li',
1062 array('li' => array('class' => 'odd')), 'Item 4.3',
1063 '<ul',
1064 array('li' => array('class' => 'odd')), 'Item 4.3.1', '/li',
1065 array('li' => array('class' => 'even')), 'Item 4.3.2', '/li',
1066 '/ul',
1067 '/li',
1068 '/ul',
1069 '/li',
1070 array('li' => array('class' => 'odd')), 'Item 5',
1071 '<ul',
1072 array('li' => array('class' => 'odd')), 'Item 5.1', '/li',
1073 array('li' => array('class' => 'even')), 'Item 5.2', '/li',
1074 '/ul',
1075 '/li',
1076 '/ul'
1077 );
1078 $this->assertTags($result, $expected);
1079
1080 $result = $this->Html->nestedList($list, array('class'=>'list'), array('class' => 'item'));
1081 $expected = array(
1082 array('ul' => array('class' => 'list')),
1083 array('li' => array('class' => 'item')), 'Item 1', '/li',
1084 array('li' => array('class' => 'item')), 'Item 2',
1085 array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
1086 '/li',
1087 array('li' => array('class' => 'item')), 'Item 3', '/li',
1088 array('li' => array('class' => 'item')), 'Item 4',
1089 array('ul' => array('class' => 'list')),
1090 array('li' => array('class' => 'item')), 'Item 4.1', '/li',
1091 array('li' => array('class' => 'item')), 'Item 4.2', '/li',
1092 array('li' => array('class' => 'item')), 'Item 4.3',
1093 array('ul' => array('class' => 'list')),
1094 array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
1095 array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
1096 '/ul',
1097 '/li',
1098 '/ul',
1099 '/li',
1100 array('li' => array('class' => 'item')), 'Item 5',
1101 array('ul' => array('class' => 'list')),
1102 array('li' => array('class' => 'item')), 'Item 5.1', '/li',
1103 array('li' => array('class' => 'item')), 'Item 5.2', '/li',
1104 '/ul',
1105 '/li',
1106 '/ul'
1107 );
1108 $this->assertTags($result, $expected);
1109 }
1110
1111 /**
1112 * testMeta method
1113 *
1114 * @access public
1115 * @return void
1116 */
1117 function testMeta() {
1118 $result = $this->Html->meta('this is an rss feed', array('controller' => 'posts', 'ext' => 'rss'));
1119 $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
1120
1121 $result = $this->Html->meta('rss', array('controller' => 'posts', 'ext' => 'rss'), array('title' => 'this is an rss feed'));
1122 $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
1123
1124 $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'));
1125 $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom')));
1126
1127 $result = $this->Html->meta('non-existing');
1128 $this->assertTags($result, array('<meta'));
1129
1130 $result = $this->Html->meta('non-existing', '/posts.xpp');
1131 $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'non-existing')));
1132
1133 $result = $this->Html->meta('non-existing', '/posts.xpp', array('type' => 'atom'));
1134 $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing')));
1135
1136 $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'), array('link' => '/articles.rss'));
1137 $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/articles\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom')));
1138
1139 $result = $this->Html->meta(array('link' => 'favicon.ico', 'rel' => 'icon'));
1140 $expected = array(
1141 'link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'icon'),
1142 array('link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'shortcut icon'))
1143 );
1144 $this->assertTags($result, $expected);
1145
1146 $result = $this->Html->meta('icon', 'favicon.ico');
1147 $expected = array(
1148 'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
1149 array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
1150 );
1151 $this->assertTags($result, $expected);
1152
1153 $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
1154 $this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
1155 $this->assertPattern('/\s+\/>$/', $result);
1156
1157
1158 $result = $this->Html->meta('description', 'this is the meta description');
1159 $this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));
1160
1161 $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
1162 $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
1163
1164 $this->assertNull($this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false)));
1165 $view =& ClassRegistry::getObject('view');
1166 $result = $view->__scripts[0];
1167 $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
1168 }
1169
1170 /**
1171 * testTableHeaders method
1172 *
1173 * @access public
1174 * @return void
1175 */
1176 function testTableHeaders() {
1177 $result = $this->Html->tableHeaders(array('ID', 'Name', 'Date'));
1178 $expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
1179 $this->assertTags($result, $expected);
1180 }
1181
1182 /**
1183 * testTableCells method
1184 *
1185 * @access public
1186 * @return void
1187 */
1188 function testTableCells() {
1189 $tr = array(
1190 'td content 1',
1191 array('td content 2', array("width" => "100px")),
1192 array('td content 3', "width=100px")
1193 );
1194 $result = $this->Html->tableCells($tr);
1195 $expected = array(
1196 '<tr',
1197 '<td', 'td content 1', '/td',
1198 array('td' => array('width' => '100px')), 'td content 2', '/td',
1199 array('td' => array('width' => 'preg:/100px/')), 'td content 3', '/td',
1200 '/tr'
1201 );
1202 $this->assertTags($result, $expected);
1203
1204 $tr = array('td content 1', 'td content 2', 'td content 3');
1205 $result = $this->Html->tableCells($tr, null, null, true);
1206 $expected = array(
1207 '<tr',
1208 array('td' => array('class' => 'column-1')), 'td content 1', '/td',
1209 array('td' => array('class' => 'column-2')), 'td content 2', '/td',
1210 array('td' => array('class' => 'column-3')), 'td content 3', '/td',
1211 '/tr'
1212 );
1213 $this->assertTags($result, $expected);
1214
1215 $tr = array('td content 1', 'td content 2', 'td content 3');
1216 $result = $this->Html->tableCells($tr, true);
1217 $expected = array(
1218 '<tr',
1219 array('td' => array('class' => 'column-1')), 'td content 1', '/td',
1220 array('td' => array('class' => 'column-2')), 'td content 2', '/td',
1221 array('td' => array('class' => 'column-3')), 'td content 3', '/td',
1222 '/tr'
1223 );
1224 $this->assertTags($result, $expected);
1225
1226 $tr = array(
1227 array('td content 1', 'td content 2', 'td content 3'),
1228 array('td content 1', 'td content 2', 'td content 3'),
1229 array('td content 1', 'td content 2', 'td content 3')
1230 );
1231 $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
1232 $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>";
1233 $this->assertEqual($result, $expected);
1234
1235 $tr = array(
1236 array('td content 1', 'td content 2', 'td content 3'),
1237 array('td content 1', 'td content 2', 'td content 3'),
1238 array('td content 1', 'td content 2', 'td content 3'),
1239 array('td content 1', 'td content 2', 'td content 3')
1240 );
1241 $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
1242 $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>";
1243 $this->assertEqual($result, $expected);
1244
1245 $tr = array(
1246 array('td content 1', 'td content 2', 'td content 3'),
1247 array('td content 1', 'td content 2', 'td content 3'),
1248 array('td content 1', 'td content 2', 'td content 3')
1249 );
1250 $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
1251 $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false);
1252 $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>";
1253 $this->assertEqual($result, $expected);
1254 }
1255
1256 /**
1257 * testTag method
1258 *
1259 * @access public
1260 * @return void
1261 */
1262 function testTag() {
1263 $result = $this->Html->tag('div');
1264 $this->assertTags($result, '<div');
1265
1266 $result = $this->Html->tag('div', 'text');
1267 $this->assertTags($result, '<div', 'text', '/div');
1268
1269 $result = $this->Html->tag('div', '<text>', 'class-name');
1270 $this->assertTags($result, array('div' => array('class' => 'class-name'), 'preg:/<text>/', '/div'));
1271
1272 $result = $this->Html->tag('div', '<text>', array('class' => 'class-name', 'escape' => true));
1273 $this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
1274 }
1275
1276 /**
1277 * testDiv method
1278 *
1279 * @access public
1280 * @return void
1281 */
1282 function testDiv() {
1283 $result = $this->Html->div('class-name');
1284 $this->assertTags($result, array('div' => array('class' => 'class-name')));
1285
1286 $result = $this->Html->div('class-name', 'text');
1287 $this->assertTags($result, array('div' => array('class' => 'class-name'), 'text', '/div'));
1288
1289 $result = $this->Html->div('class-name', '<text>', array('escape' => true));
1290 $this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
1291 }
1292
1293 /**
1294 * testPara method
1295 *
1296 * @access public
1297 * @return void
1298 */
1299 function testPara() {
1300 $result = $this->Html->para('class-name', '');
1301 $this->assertTags($result, array('p' => array('class' => 'class-name')));
1302
1303 $result = $this->Html->para('class-name', 'text');
1304 $this->assertTags($result, array('p' => array('class' => 'class-name'), 'text', '/p'));
1305
1306 $result = $this->Html->para('class-name', '<text>', array('escape' => true));
1307 $this->assertTags($result, array('p' => array('class' => 'class-name'), '&lt;text&gt;', '/p'));
1308 }
1309 }