2007-02-26 12:58:02 +00:00
< ? php
/* SVN FILE: $Id$ */
/**
* Short description for file .
*
* Long description for file
*
* PHP versions 4 and 5
*
2008-01-01 22:18:17 +00:00
* CakePHP ( tm ) Tests < https :// trac . cakephp . org / wiki / Developement / TestSuite >
* Copyright 2006 - 2008 , Cake Software Foundation , Inc .
* 1785 E . Sahara Avenue , Suite 490 - 204
* Las Vegas , Nevada 89104
2007-02-26 12:58:02 +00:00
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
2008-01-01 22:18:17 +00:00
* @ copyright Copyright 2006 - 2008 , Cake Software Foundation , Inc .
* @ link https :// trac . cakephp . org / wiki / Developement / TestSuite CakePHP ( tm ) Tests
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . view . helpers
* @ since CakePHP ( tm ) v 1.2 . 0.4206
* @ version $Revision $
* @ modifiedby $LastChangedBy $
* @ lastmodified $Date $
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
2007-02-26 12:58:02 +00:00
*/
2008-05-08 17:48:14 +00:00
App :: import ( 'Core' , array ( 'Helper' , 'AppHelper' , 'ClassRegistry' , 'Controller' , 'Model' ));
App :: import ( 'Helper' , array ( 'Html' , 'Form' ));
2007-02-26 12:58:02 +00:00
2007-03-06 08:48:45 +00:00
class TheHtmlTestController extends Controller {
2007-02-26 12:58:02 +00:00
var $name = 'TheTest' ;
var $uses = null ;
2007-03-06 08:48:45 +00:00
}
2007-02-26 12:58:02 +00:00
2008-05-08 17:48:14 +00:00
class HtmlHelperTest extends CakeTestCase {
2007-02-26 12:58:02 +00:00
var $html = null ;
2007-07-06 04:31:45 +00:00
2007-02-26 12:58:02 +00:00
function setUp () {
2007-04-06 19:12:15 +00:00
$this -> Html =& new HtmlHelper ();
$view =& new View ( new TheHtmlTestController ());
2007-02-26 12:58:02 +00:00
ClassRegistry :: addObject ( 'view' , $view );
}
2007-07-06 04:31:45 +00:00
2008-05-08 17:48:14 +00:00
function testDocType () {
$result = $this -> Html -> docType ();
$expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' ;
$this -> assertEqual ( $result , $expected );
2008-05-10 04:32:55 +00:00
2008-05-08 17:48:14 +00:00
$result = $this -> Html -> docType ( 'html4-strict' );
$expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' ;
$this -> assertEqual ( $result , $expected );
2008-05-10 04:57:46 +00:00
$this -> assertNull ( $this -> Html -> docType ( 'non-existing-doctype' ));
2008-05-08 17:48:14 +00:00
}
function testLink () {
$result = $this -> Html -> link ( '/home' );
$expected = array ( 'a' => array ( 'href' => '/home' ), 'preg:/\/home/' , '/a' );
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> link ( 'Home' , '/home' , array ( 'confirm' => 'Are you sure you want to do this?' ));
$expected = array (
2008-05-10 04:32:55 +00:00
'a' => array ( 'href' => '/home' , 'onclick' => 'return confirm('Are you sure you want to do this?');' ),
2008-05-08 17:48:14 +00:00
'Home' ,
'/a'
);
$this -> assertTags ( $result , $expected , true );
$result = $this -> Html -> link ( 'Home' , '/home' , array ( 'default' => false ));
$expected = array (
2008-05-10 04:32:55 +00:00
'a' => array ( 'href' => '/home' , 'onclick' => 'event.returnValue = false; return false;' ),
2008-05-08 17:48:14 +00:00
'Home' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2007-04-28 07:42:54 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' );
2008-05-10 04:32:55 +00:00
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2007-07-06 04:31:45 +00:00
2008-05-10 04:57:46 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' , array ( 'escape' => true ));
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> link ( 'Next >' , '#' , array ( 'escape' => 'utf-8' ));
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2007-04-28 07:42:54 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' , array ( 'escape' => false ));
2008-05-10 04:32:55 +00:00
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2007-07-06 04:31:45 +00:00
2007-04-06 19:12:15 +00:00
$result = $this -> Html -> link ( $this -> Html -> image ( 'test.gif' ), '#' , array (), false , false , false );
2008-05-10 04:32:55 +00:00
$expected = array (
'a' => array ( 'href' => '#' ),
'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' ),
'/a'
);
$this -> assertTags ( $result , $expected );
2007-12-30 21:14:15 +00:00
$result = $this -> Html -> image ( 'test.gif' , array ( 'url' => '#' ));
2008-05-10 04:32:55 +00:00
$expected = array (
'a' => array ( 'href' => '#' ),
'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' ),
'/a'
);
$this -> assertTags ( $result , $expected );
2007-04-06 19:12:15 +00:00
}
2007-07-06 04:31:45 +00:00
2007-12-15 23:46:56 +00:00
function testImageTag () {
$result = $this -> Html -> image ( 'test.gif' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' )));
2007-12-15 23:46:56 +00:00
$result = $this -> Html -> image ( 'http://google.com/logo.gif' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'http://google.com/logo.gif' , 'alt' => '' )));
2007-12-15 23:46:56 +00:00
$result = $this -> Html -> image ( array ( 'controller' => 'test' , 'action' => 'view' , 1 , 'ext' => 'gif' ));
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '/test/view/1.gif' , 'alt' => '' )));
2007-12-15 23:46:56 +00:00
$result = $this -> Html -> image ( '/test/view/1.gif' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '/test/view/1.gif' , 'alt' => '' )));
2007-12-31 04:24:14 +00:00
Configure :: write ( 'Asset.timestamp' , true );
$result = $this -> Html -> image ( 'logo.gif' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'preg:/img\/logo\.gif\?\d*/' , 'alt' => '' )));
2007-12-31 04:24:14 +00:00
Configure :: write ( 'Asset.timestamp' , false );
2007-12-15 23:46:56 +00:00
}
2007-05-24 22:50:20 +00:00
function testStyle () {
$result = $this -> Html -> style ( array ( 'display' => 'none' , 'margin' => '10px' ));
2007-07-09 17:33:03 +00:00
$expected = 'display:none; margin:10px;' ;
2008-05-10 04:32:55 +00:00
$this -> assertPattern ( '/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/' , $expected );
2007-07-06 04:31:45 +00:00
2007-05-24 22:50:20 +00:00
$result = $this -> Html -> style ( array ( 'display' => 'none' , 'margin' => '10px' ), false );
2008-05-10 04:32:55 +00:00
$lines = explode ( " \n " , $result );
$this -> assertPattern ( '/^\s*display\s*:\s*none\s*;\s*$/' , $lines [ 0 ]);
$this -> assertPattern ( '/^\s*margin\s*:\s*10px\s*;?$/' , $lines [ 1 ]);
2007-09-13 23:19:48 +00:00
}
2007-09-16 18:32:02 +00:00
function testCssLink () {
$result = $this -> Html -> css ( 'screen' );
2008-05-08 17:48:14 +00:00
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => 'preg:/.*css\/screen\.css/' )
);
$this -> assertTags ( $result , $expected );
2007-11-25 20:17:25 +00:00
$result = $this -> Html -> css ( 'screen.css' );
2008-05-08 17:48:14 +00:00
$this -> assertTags ( $result , $expected );
2007-11-25 20:17:25 +00:00
$result = $this -> Html -> css ( 'screen.css?1234' );
2008-05-08 17:48:14 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/screen\.css\?1234/' ;
$this -> assertTags ( $result , $expected );
2007-12-30 21:14:15 +00:00
$result = $this -> Html -> css ( 'http://whatever.com/screen.css?1234' );
2008-05-08 17:48:14 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/http:\/\/.*\/screen\.css\?1234/' ;
$this -> assertTags ( $result , $expected );
2008-01-01 22:18:17 +00:00
2007-12-31 04:24:14 +00:00
Configure :: write ( 'Asset.timestamp' , true );
$result = $this -> Html -> css ( 'cake.generic' );
2008-05-11 16:39:18 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/' ;
2008-05-08 17:48:14 +00:00
$this -> assertTags ( $result , $expected );
2008-02-14 17:35:13 +00:00
$debug = Configure :: read ( 'debug' );
Configure :: write ( 'debug' , 0 );
$result = $this -> Html -> css ( 'cake.generic' );
2008-05-08 17:48:14 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/cake\.generic\.css/' ;
$this -> assertTags ( $result , $expected );
2008-02-14 17:35:13 +00:00
Configure :: write ( 'Asset.timestamp' , 'force' );
$result = $this -> Html -> css ( 'cake.generic' );
2008-05-11 16:39:18 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/' ;
2008-05-08 17:48:14 +00:00
$this -> assertTags ( $result , $expected );
2008-02-14 17:35:13 +00:00
2007-12-31 04:24:14 +00:00
Configure :: write ( 'Asset.timestamp' , false );
2008-02-14 17:35:13 +00:00
Configure :: write ( 'debug' , $debug );
2007-12-31 05:19:00 +00:00
Configure :: write ( 'Asset.filter.css' , 'css.php' );
$result = $this -> Html -> css ( 'cake.generic' );
2008-05-08 17:48:14 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/.*ccss\/cake\.generic\.css/' ;
$this -> assertTags ( $result , $expected );
2007-12-31 05:19:00 +00:00
Configure :: write ( 'Asset.filter.css' , false );
2008-05-08 17:48:14 +00:00
$result = explode ( " \n " , trim ( $this -> Html -> css ( array ( 'cake.generic' , 'vendor.generic' ))));
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/cake\.generic\.css/' ;
$this -> assertTags ( $result [ 0 ], $expected );
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/vendor\.generic\.css/' ;
$this -> assertTags ( $result [ 1 ], $expected );
$this -> assertEqual ( count ( $result ), 2 );
2007-09-16 18:32:02 +00:00
}
2008-04-20 12:02:58 +00:00
function testCharsetTag () {
Configure :: write ( 'App.encoding' , null );
2008-05-10 04:32:55 +00:00
$result = $this -> Html -> charset ();
$this -> assertTags ( $result , array ( 'meta' => array ( 'http-equiv' => 'Content-Type' , 'content' => 'text/html; charset=utf-8' )));
2008-04-20 12:02:58 +00:00
Configure :: write ( 'App.encoding' , 'ISO-8859-1' );
2008-05-10 04:32:55 +00:00
$result = $this -> Html -> charset ();
$this -> assertTags ( $result , array ( 'meta' => array ( 'http-equiv' => 'Content-Type' , 'content' => 'text/html; charset=iso-8859-1' )));
$result = $this -> Html -> charset ( 'UTF-7' );
$this -> assertTags ( $result , array ( 'meta' => array ( 'http-equiv' => 'Content-Type' , 'content' => 'text/html; charset=UTF-7' )));
2008-04-20 12:02:58 +00:00
}
2007-09-13 23:19:48 +00:00
function testBreadcrumb () {
$this -> Html -> addCrumb ( 'First' , '#first' );
$this -> Html -> addCrumb ( 'Second' , '#second' );
$this -> Html -> addCrumb ( 'Third' , '#third' );
$result = $this -> Html -> getCrumbs ();
2008-05-10 04:32:55 +00:00
$expected = array (
array ( 'a' => array ( 'href' => '#first' )),
'First' ,
'/a' ,
'»' ,
array ( 'a' => array ( 'href' => '#second' )),
'Second' ,
'/a' ,
'»' ,
array ( 'a' => array ( 'href' => '#third' )),
'Third' ,
'/a' ,
);
$this -> assertTags ( $result , $expected );
2007-09-13 23:19:48 +00:00
$result = $this -> Html -> getCrumbs ( ' > ' );
2008-05-10 04:32:55 +00:00
$expected = array (
array ( 'a' => array ( 'href' => '#first' )),
'First' ,
'/a' ,
' > ' ,
array ( 'a' => array ( 'href' => '#second' )),
'Second' ,
'/a' ,
' > ' ,
array ( 'a' => array ( 'href' => '#third' )),
'Third' ,
'/a' ,
);
$this -> assertTags ( $result , $expected );
2007-09-13 23:19:48 +00:00
$this -> assertPattern ( '/^<a[^<>]+>First<\/a> > <a[^<>]+>Second<\/a> > <a[^<>]+>Third<\/a>$/' , $result );
$this -> assertPattern ( '/<a\s+href=["\']+\#first["\']+[^<>]*>First<\/a>/' , $result );
$this -> assertPattern ( '/<a\s+href=["\']+\#second["\']+[^<>]*>Second<\/a>/' , $result );
$this -> assertPattern ( '/<a\s+href=["\']+\#third["\']+[^<>]*>Third<\/a>/' , $result );
$this -> assertNoPattern ( '/<a[^<>]+[^href]=[^<>]*>/' , $result );
$this -> Html -> addCrumb ( 'Fourth' , null );
2007-07-06 04:31:45 +00:00
2007-09-13 23:19:48 +00:00
$result = $this -> Html -> getCrumbs ();
2008-05-10 04:32:55 +00:00
$expected = array (
array ( 'a' => array ( 'href' => '#first' )),
'First' ,
'/a' ,
'»' ,
array ( 'a' => array ( 'href' => '#second' )),
'Second' ,
'/a' ,
'»' ,
array ( 'a' => array ( 'href' => '#third' )),
'Third' ,
'/a' ,
'»' ,
'Fourth'
);
$this -> assertTags ( $result , $expected );
2007-05-24 22:50:20 +00:00
}
2007-03-08 00:44:25 +00:00
2007-09-16 01:42:33 +00:00
function testNestedList () {
$list = array (
'Item 1' ,
'Item 2' => array (
'Item 2.1'
),
'Item 3' ,
'Item 4' => array (
'Item 4.1' ,
'Item 4.2' ,
'Item 4.3' => array (
'Item 4.3.1' ,
'Item 4.3.2'
)
),
'Item 5' => array (
'Item 5.1' ,
'Item 5.2'
)
);
$result = $this -> Html -> nestedList ( $list );
2008-05-10 04:32:55 +00:00
$expected = array (
'<ul' ,
'<li' , 'Item 1' , '/li' ,
'<li' , 'Item 2' ,
'<ul' , '<li' , 'Item 2.1' , '/li' , '/ul' ,
'/li' ,
'<li' , 'Item 3' , '/li' ,
'<li' , 'Item 4' ,
'<ul' ,
'<li' , 'Item 4.1' , '/li' ,
'<li' , 'Item 4.2' , '/li' ,
'<li' , 'Item 4.3' ,
'<ul' ,
'<li' , 'Item 4.3.1' , '/li' ,
'<li' , 'Item 4.3.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul' ,
'/li' ,
'<li' , 'Item 5' ,
'<ul' ,
'<li' , 'Item 5.1' , '/li' ,
'<li' , 'Item 5.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul'
);
$this -> assertTags ( $result , $expected );
2007-09-16 01:42:33 +00:00
2007-11-25 20:12:51 +00:00
$result = $this -> Html -> nestedList ( $list , null );
2008-05-10 04:32:55 +00:00
$expected = array (
'<ul' ,
'<li' , 'Item 1' , '/li' ,
'<li' , 'Item 2' ,
'<ul' , '<li' , 'Item 2.1' , '/li' , '/ul' ,
'/li' ,
'<li' , 'Item 3' , '/li' ,
'<li' , 'Item 4' ,
'<ul' ,
'<li' , 'Item 4.1' , '/li' ,
'<li' , 'Item 4.2' , '/li' ,
'<li' , 'Item 4.3' ,
'<ul' ,
'<li' , 'Item 4.3.1' , '/li' ,
'<li' , 'Item 4.3.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul' ,
'/li' ,
'<li' , 'Item 5' ,
'<ul' ,
'<li' , 'Item 5.1' , '/li' ,
'<li' , 'Item 5.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul'
);
$this -> assertTags ( $result , $expected );
2007-11-25 20:12:51 +00:00
2007-09-16 01:42:33 +00:00
$result = $this -> Html -> nestedList ( $list , array (), array (), 'ol' );
2008-05-10 04:32:55 +00:00
$expected = array (
'<ol' ,
'<li' , 'Item 1' , '/li' ,
'<li' , 'Item 2' ,
'<ol' , '<li' , 'Item 2.1' , '/li' , '/ol' ,
'/li' ,
'<li' , 'Item 3' , '/li' ,
'<li' , 'Item 4' ,
'<ol' ,
'<li' , 'Item 4.1' , '/li' ,
'<li' , 'Item 4.2' , '/li' ,
'<li' , 'Item 4.3' ,
'<ol' ,
'<li' , 'Item 4.3.1' , '/li' ,
'<li' , 'Item 4.3.2' , '/li' ,
'/ol' ,
'/li' ,
'/ol' ,
'/li' ,
'<li' , 'Item 5' ,
'<ol' ,
'<li' , 'Item 5.1' , '/li' ,
'<li' , 'Item 5.2' , '/li' ,
'/ol' ,
'/li' ,
'/ol'
);
$this -> assertTags ( $result , $expected );
2007-09-16 01:42:33 +00:00
2007-11-25 20:12:51 +00:00
$result = $this -> Html -> nestedList ( $list , 'ol' );
2008-05-10 04:32:55 +00:00
$expected = array (
'<ol' ,
'<li' , 'Item 1' , '/li' ,
'<li' , 'Item 2' ,
'<ol' , '<li' , 'Item 2.1' , '/li' , '/ol' ,
'/li' ,
'<li' , 'Item 3' , '/li' ,
'<li' , 'Item 4' ,
'<ol' ,
'<li' , 'Item 4.1' , '/li' ,
'<li' , 'Item 4.2' , '/li' ,
'<li' , 'Item 4.3' ,
'<ol' ,
'<li' , 'Item 4.3.1' , '/li' ,
'<li' , 'Item 4.3.2' , '/li' ,
'/ol' ,
'/li' ,
'/ol' ,
'/li' ,
'<li' , 'Item 5' ,
'<ol' ,
'<li' , 'Item 5.1' , '/li' ,
'<li' , 'Item 5.2' , '/li' ,
'/ol' ,
'/li' ,
'/ol'
);
$this -> assertTags ( $result , $expected );
2007-11-25 20:12:51 +00:00
2007-09-16 01:42:33 +00:00
$result = $this -> Html -> nestedList ( $list , array ( 'class' => 'list' ));
2008-05-10 04:32:55 +00:00
$expected = array (
array ( 'ul' => array ( 'class' => 'list' )),
'<li' , 'Item 1' , '/li' ,
'<li' , 'Item 2' ,
array ( 'ul' => array ( 'class' => 'list' )), '<li' , 'Item 2.1' , '/li' , '/ul' ,
'/li' ,
'<li' , 'Item 3' , '/li' ,
'<li' , 'Item 4' ,
array ( 'ul' => array ( 'class' => 'list' )),
'<li' , 'Item 4.1' , '/li' ,
'<li' , 'Item 4.2' , '/li' ,
'<li' , 'Item 4.3' ,
array ( 'ul' => array ( 'class' => 'list' )),
'<li' , 'Item 4.3.1' , '/li' ,
'<li' , 'Item 4.3.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul' ,
'/li' ,
'<li' , 'Item 5' ,
array ( 'ul' => array ( 'class' => 'list' )),
'<li' , 'Item 5.1' , '/li' ,
'<li' , 'Item 5.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul'
);
$this -> assertTags ( $result , $expected );
2007-09-16 01:42:33 +00:00
$result = $this -> Html -> nestedList ( $list , array (), array ( 'class' => 'item' ));
2008-05-10 04:32:55 +00:00
$expected = array (
'<ul' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 1' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 2' ,
'<ul' , array ( 'li' => array ( 'class' => 'item' )), 'Item 2.1' , '/li' , '/ul' ,
'/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 3' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4' ,
'<ul' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.1' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.2' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.3' ,
'<ul' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.3.1' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.3.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul' ,
'/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 5' ,
'<ul' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 5.1' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 5.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul'
);
$this -> assertTags ( $result , $expected );
2007-09-16 01:42:33 +00:00
$result = $this -> Html -> nestedList ( $list , array (), array ( 'even' => 'even' , 'odd' => 'odd' ));
2008-05-10 04:32:55 +00:00
$expected = array (
'<ul' ,
array ( 'li' => array ( 'class' => 'odd' )), 'Item 1' , '/li' ,
array ( 'li' => array ( 'class' => 'even' )), 'Item 2' ,
'<ul' , array ( 'li' => array ( 'class' => 'odd' )), 'Item 2.1' , '/li' , '/ul' ,
'/li' ,
array ( 'li' => array ( 'class' => 'odd' )), 'Item 3' , '/li' ,
array ( 'li' => array ( 'class' => 'even' )), 'Item 4' ,
'<ul' ,
array ( 'li' => array ( 'class' => 'odd' )), 'Item 4.1' , '/li' ,
array ( 'li' => array ( 'class' => 'even' )), 'Item 4.2' , '/li' ,
array ( 'li' => array ( 'class' => 'odd' )), 'Item 4.3' ,
'<ul' ,
array ( 'li' => array ( 'class' => 'odd' )), 'Item 4.3.1' , '/li' ,
array ( 'li' => array ( 'class' => 'even' )), 'Item 4.3.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul' ,
'/li' ,
array ( 'li' => array ( 'class' => 'odd' )), 'Item 5' ,
'<ul' ,
array ( 'li' => array ( 'class' => 'odd' )), 'Item 5.1' , '/li' ,
array ( 'li' => array ( 'class' => 'even' )), 'Item 5.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul'
);
$this -> assertTags ( $result , $expected );
2007-09-16 01:42:33 +00:00
$result = $this -> Html -> nestedList ( $list , array ( 'class' => 'list' ), array ( 'class' => 'item' ));
2008-05-10 04:32:55 +00:00
$expected = array (
array ( 'ul' => array ( 'class' => 'list' )),
array ( 'li' => array ( 'class' => 'item' )), 'Item 1' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 2' ,
array ( 'ul' => array ( 'class' => 'list' )), array ( 'li' => array ( 'class' => 'item' )), 'Item 2.1' , '/li' , '/ul' ,
'/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 3' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4' ,
array ( 'ul' => array ( 'class' => 'list' )),
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.1' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.2' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.3' ,
array ( 'ul' => array ( 'class' => 'list' )),
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.3.1' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 4.3.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul' ,
'/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 5' ,
array ( 'ul' => array ( 'class' => 'list' )),
array ( 'li' => array ( 'class' => 'item' )), 'Item 5.1' , '/li' ,
array ( 'li' => array ( 'class' => 'item' )), 'Item 5.2' , '/li' ,
'/ul' ,
'/li' ,
'/ul'
);
$this -> assertTags ( $result , $expected );
2007-09-16 01:42:33 +00:00
}
2007-12-22 23:36:24 +00:00
function testMeta () {
2008-05-10 04:57:46 +00:00
$result = $this -> Html -> meta ( 'this is an rss feed' , array ( 'controller' => 'posts' , 'ext' => 'rss' ));
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'link' => array ( 'href' => 'preg:/.*\/posts\.rss/' , 'type' => 'application/rss+xml' , 'rel' => 'alternate' , 'title' => 'this is an rss feed' )));
2007-12-22 23:36:24 +00:00
2008-05-10 04:57:46 +00:00
$result = $this -> Html -> meta ( 'rss' , array ( 'controller' => 'posts' , 'ext' => 'rss' ), array ( 'title' => 'this is an rss feed' ));
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'link' => array ( 'href' => 'preg:/.*\/posts\.rss/' , 'type' => 'application/rss+xml' , 'rel' => 'alternate' , 'title' => 'this is an rss feed' )));
2007-12-22 23:36:24 +00:00
2008-05-10 04:57:46 +00:00
$result = $this -> Html -> meta ( 'atom' , array ( 'controller' => 'posts' , 'ext' => 'xml' ));
$this -> assertTags ( $result , array ( 'link' => array ( 'href' => 'preg:/.*\/posts\.xml/' , 'type' => 'application/atom+xml' , 'title' => 'atom' )));
$result = $this -> Html -> meta ( 'non-existing' );
$this -> assertTags ( $result , array ( '<meta' ));
$result = $this -> Html -> meta ( 'non-existing' , '/posts.xpp' );
$this -> assertTags ( $result , array ( 'link' => array ( 'href' => 'preg:/.*\/posts\.xpp/' , 'type' => 'application/rss+xml' , 'rel' => 'alternate' , 'title' => 'non-existing' )));
$result = $this -> Html -> meta ( 'non-existing' , '/posts.xpp' , array ( 'type' => 'atom' ));
$this -> assertTags ( $result , array ( 'link' => array ( 'href' => 'preg:/.*\/posts\.xpp/' , 'type' => 'application/atom+xml' , 'title' => 'non-existing' )));
$result = $this -> Html -> meta ( 'atom' , array ( 'controller' => 'posts' , 'ext' => 'xml' ), array ( 'link' => '/articles.rss' ));
$this -> assertTags ( $result , array ( 'link' => array ( 'href' => 'preg:/.*\/articles\.rss/' , 'type' => 'application/atom+xml' , 'title' => 'atom' )));
$result = $this -> Html -> meta ( array ( 'link' => 'favicon.ico' , 'rel' => 'icon' ));
$expected = array (
'link' => array ( 'href' => 'preg:/.*favicon\.ico/' , 'rel' => 'icon' ),
array ( 'link' => array ( 'href' => 'preg:/.*favicon\.ico/' , 'rel' => 'shortcut icon' ))
);
$this -> assertTags ( $result , $expected );
2007-12-22 23:36:24 +00:00
$result = $this -> Html -> meta ( 'icon' , 'favicon.ico' );
2008-05-10 04:32:55 +00:00
$expected = array (
'link' => array ( 'href' => 'preg:/.*favicon\.ico/' , 'type' => 'image/x-icon' , 'rel' => 'icon' ),
array ( 'link' => array ( 'href' => 'preg:/.*favicon\.ico/' , 'type' => 'image/x-icon' , 'rel' => 'shortcut icon' ))
);
$this -> assertTags ( $result , $expected );
2007-12-22 23:36:24 +00:00
$result = $this -> Html -> meta ( 'keywords' , 'these, are, some, meta, keywords' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'meta' => array ( 'name' => 'keywords' , 'content' => 'these, are, some, meta, keywords' )));
2007-12-22 23:36:24 +00:00
$result = $this -> Html -> meta ( 'description' , 'this is the meta description' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'meta' => array ( 'name' => 'description' , 'content' => 'this is the meta description' )));
2007-12-22 23:36:24 +00:00
$result = $this -> Html -> meta ( array ( 'name' => 'ROBOTS' , 'content' => 'ALL' ));
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'meta' => array ( 'name' => 'ROBOTS' , 'content' => 'ALL' )));
2008-05-08 17:48:14 +00:00
$this -> assertNull ( $this -> Html -> meta ( array ( 'name' => 'ROBOTS' , 'content' => 'ALL' ), null , array (), false ));
$view =& ClassRegistry :: getObject ( 'view' );
$result = $view -> __scripts [ 0 ];
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'meta' => array ( 'name' => 'ROBOTS' , 'content' => 'ALL' )));
2008-05-08 17:48:14 +00:00
}
function testTableHeaders () {
$result = $this -> Html -> tableHeaders ( array ( 'ID' , 'Name' , 'Date' ));
$expected = array ( '<tr' , '<th' , 'ID' , '/th' , '<th' , 'Name' , '/th' , '<th' , 'Date' , '/th' , '/tr' );
$this -> assertTags ( $result , $expected );
2007-12-22 23:36:24 +00:00
}
2007-12-30 21:14:15 +00:00
function testTableCells () {
2008-05-08 17:48:14 +00:00
$tr = array (
'td content 1' ,
array ( 'td content 2' , array ( " width " => " 100px " )),
array ( 'td content 3' , " width=100px " )
2007-12-30 21:14:15 +00:00
);
$result = $this -> Html -> tableCells ( $tr );
2008-05-10 04:32:55 +00:00
$expected = array (
'<tr' ,
'<td' , 'td content 1' , '/td' ,
array ( 'td' => array ( 'width' => '100px' )), 'td content 2' , '/td' ,
array ( 'td' => array ( 'width' => 'preg:/100px/' )), 'td content 3' , '/td' ,
'/tr'
);
$this -> assertTags ( $result , $expected );
2007-12-30 21:14:15 +00:00
$tr = array ( 'td content 1' , 'td content 2' , 'td content 3' );
$result = $this -> Html -> tableCells ( $tr , null , null , true );
2008-05-10 04:32:55 +00:00
$expected = array (
'<tr' ,
array ( 'td' => array ( 'class' => 'column-1' )), 'td content 1' , '/td' ,
array ( 'td' => array ( 'class' => 'column-2' )), 'td content 2' , '/td' ,
array ( 'td' => array ( 'class' => 'column-3' )), 'td content 3' , '/td' ,
'/tr'
);
$this -> assertTags ( $result , $expected );
2007-12-30 21:14:15 +00:00
$tr = array ( 'td content 1' , 'td content 2' , 'td content 3' );
$result = $this -> Html -> tableCells ( $tr , true );
2008-05-10 04:32:55 +00:00
$expected = array (
'<tr' ,
array ( 'td' => array ( 'class' => 'column-1' )), 'td content 1' , '/td' ,
array ( 'td' => array ( 'class' => 'column-2' )), 'td content 2' , '/td' ,
array ( 'td' => array ( 'class' => 'column-3' )), 'td content 3' , '/td' ,
'/tr'
);
$this -> assertTags ( $result , $expected );
2008-05-08 17:48:14 +00:00
}
2008-05-21 03:57:35 +00:00
function testTag () {
2008-05-13 23:04:52 +00:00
$result = $this -> Html -> tag ( 'div' );
2008-05-21 03:57:35 +00:00
$this -> assertTags ( $result , '<div' );
2008-05-13 23:04:52 +00:00
$result = $this -> Html -> tag ( 'div' , 'text' );
2008-05-21 03:57:35 +00:00
$this -> assertTags ( $result , '<div' , 'text' , '/div' );
2008-05-13 23:04:52 +00:00
$result = $this -> Html -> tag ( 'div' , '<text>' , array ( 'class' => 'class-name' ), true );
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), '<text>' , '/div' ));
2008-05-13 23:09:37 +00:00
$result = $this -> Html -> tag ( 'div' , '<text>' , 'class-name' , true );
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), '<text>' , '/div' ));
2008-05-13 23:04:52 +00:00
}
2008-05-08 17:48:14 +00:00
function testDiv () {
$result = $this -> Html -> div ( 'class-name' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' )));
2008-05-08 17:48:14 +00:00
$result = $this -> Html -> div ( 'class-name' , 'text' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), 'text' , '/div' ));
2008-05-08 17:48:14 +00:00
$result = $this -> Html -> div ( 'class-name' , '<text>' , array (), true );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), '<text>' , '/div' ));
2008-05-08 17:48:14 +00:00
}
function testPara () {
$result = $this -> Html -> para ( 'class-name' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'p' => array ( 'class' => 'class-name' )));
2008-05-08 17:48:14 +00:00
$result = $this -> Html -> para ( 'class-name' , 'text' );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'p' => array ( 'class' => 'class-name' ), 'text' , '/p' ));
2007-12-30 21:14:15 +00:00
2008-05-08 17:48:14 +00:00
$result = $this -> Html -> para ( 'class-name' , '<text>' , array (), true );
2008-05-10 04:32:55 +00:00
$this -> assertTags ( $result , array ( 'p' => array ( 'class' => 'class-name' ), '<text>' , '/p' ));
2007-12-30 21:14:15 +00:00
}
2007-02-26 12:58:02 +00:00
function tearDown () {
2007-03-16 14:58:19 +00:00
unset ( $this -> Html );
2007-02-26 12:58:02 +00:00
}
}
2007-10-28 04:18:18 +00:00
?>