2008-05-30 11:40:08 +00:00
< ? php
/**
2009-03-19 21:10:13 +00:00
* HtmlHelperTest file
2008-05-30 11:40:08 +00:00
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP ( tm ) Tests < https :// trac . cakephp . org / wiki / Developement / TestSuite >
2009-09-03 16:43:13 +00:00
* Copyright 2006 - 2009 , Cake Software Foundation , Inc .
2008-05-30 11:40:08 +00:00
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
2009-09-03 16:43:13 +00:00
* @ copyright Copyright 2006 - 2009 , Cake Software Foundation , Inc .
2008-10-30 17:30:26 +00:00
* @ link https :// trac . cakephp . org / wiki / Developement / TestSuite CakePHP ( tm ) Tests
2009-03-19 21:10:13 +00:00
* @ package cake
2008-10-30 17:30:26 +00:00
* @ subpackage cake . tests . cases . libs . view . helpers
* @ since CakePHP ( tm ) v 1.2 . 0.4206
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
2008-05-30 11:40:08 +00:00
*/
App :: import ( 'Core' , array ( 'Helper' , 'AppHelper' , 'ClassRegistry' , 'Controller' , 'Model' ));
App :: import ( 'Helper' , array ( 'Html' , 'Form' ));
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* TheHtmlTestController class
2008-11-08 00:24:51 +00:00
*
2008-10-30 17:30:26 +00:00
* @ package cake
* @ subpackage cake . tests . cases . libs . view . helpers
2008-06-02 19:22:55 +00:00
*/
2008-05-30 11:40:08 +00:00
class TheHtmlTestController extends Controller {
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* name property
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ var string 'TheTest'
* @ access public
*/
2008-05-30 11:40:08 +00:00
var $name = 'TheTest' ;
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* uses property
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ var mixed null
* @ access public
*/
2008-05-30 11:40:08 +00:00
var $uses = null ;
}
2009-03-13 02:59:55 +00:00
Mock :: generate ( 'View' , 'HtmlHelperMockView' );
2008-06-02 19:22:55 +00:00
/**
* HtmlHelperTest class
2008-11-08 00:24:51 +00:00
*
2008-10-30 17:30:26 +00:00
* @ package cake
* @ subpackage cake . tests . cases . libs . view . helpers
2008-06-02 19:22:55 +00:00
*/
2008-05-30 11:40:08 +00:00
class HtmlHelperTest extends CakeTestCase {
2009-07-24 19:18:37 +00:00
2009-03-13 02:59:55 +00:00
/**
* Regexp for CDATA start block
*
* @ var string
*/
var $cDataStart = 'preg:/^\/\/<!\[CDATA\[[\n\r]*/' ;
/**
* Regexp for CDATA end block
*
* @ var string
*/
var $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/' ;
2008-06-02 19:22:55 +00:00
/**
* html property
2008-11-08 00:24:51 +00:00
*
2009-07-04 22:04:40 +00:00
* @ var object
2008-06-02 19:22:55 +00:00
* @ access public
*/
2009-07-04 22:04:40 +00:00
var $Html = null ;
2009-07-24 19:18:37 +00:00
2009-07-04 22:04:40 +00:00
/**
* Backup of app encoding configuration setting
*
* @ var string
* @ access protected
*/
var $_appEncoding ;
2009-07-24 19:18:37 +00:00
2009-07-04 22:04:40 +00:00
/**
* Backup of asset configuration settings
*
* @ var string
* @ access protected
*/
var $_asset ;
2009-07-24 19:18:37 +00:00
2009-07-04 22:04:40 +00:00
/**
* Backup of debug configuration setting
*
* @ var integer
* @ access protected
*/
var $_debug ;
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* setUp method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2009-03-13 02:59:55 +00:00
function startTest () {
2008-05-30 11:40:08 +00:00
$this -> Html =& new HtmlHelper ();
$view =& new View ( new TheHtmlTestController ());
ClassRegistry :: addObject ( 'view' , $view );
2009-03-21 23:55:39 +00:00
$this -> _appEncoding = Configure :: read ( 'App.encoding' );
2009-07-04 22:04:40 +00:00
$this -> _asset = Configure :: read ( 'Asset' );
$this -> _debug = Configure :: read ( 'debug' );
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2009-03-19 21:10:13 +00:00
/**
2009-08-27 02:46:49 +00:00
* endTest method
2009-03-19 21:10:13 +00:00
*
* @ access public
* @ return void
*/
2009-08-27 02:46:49 +00:00
function endTest () {
2009-03-21 23:55:39 +00:00
Configure :: write ( 'App.encoding' , $this -> _appEncoding );
2009-07-04 22:04:40 +00:00
Configure :: write ( 'Asset' , $this -> _asset );
Configure :: write ( 'debug' , $this -> _debug );
2009-03-21 23:55:39 +00:00
ClassRegistry :: flush ();
2009-08-27 02:46:49 +00:00
unset ( $this -> Html );
2009-03-19 21:10:13 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testDocType method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +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 );
$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 );
$this -> assertNull ( $this -> Html -> docType ( 'non-existing-doctype' ));
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testLink method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +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 (
'a' => array ( 'href' => '/home' , 'onclick' => 'return confirm('Are you sure you want to do this?');' ),
'Home' ,
'/a'
);
$this -> assertTags ( $result , $expected , true );
$result = $this -> Html -> link ( 'Home' , '/home' , array ( 'default' => false ));
$expected = array (
'a' => array ( 'href' => '/home' , 'onclick' => 'event.returnValue = false; return false;' ),
'Home' ,
'/a'
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> link ( 'Next >' , '#' );
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
$this -> assertTags ( $result , $expected );
$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 );
$result = $this -> Html -> link ( 'Next >' , '#' , array ( 'escape' => false ));
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2009-02-23 15:19:33 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' , array (
'title' => 'to escape … or not escape?' ,
'escape' => false
));
$expected = array (
'a' => array ( 'href' => '#' , 'title' => 'to escape … or not escape?' ),
'Next >' ,
'/a'
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> link ( 'Next >' , '#' , array (
'title' => 'to escape … or not escape?' ,
'escape' => true
), false , false );
$expected = array (
'a' => array ( 'href' => '#' , 'title' => 'to escape &#8230; or not escape?' ),
'Next >' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2009-01-14 22:41:47 +00:00
$result = $this -> Html -> link ( 'Original size' , array (
'controller' => 'images' , 'action' => 'view' , 3 , '?' => array ( 'height' => 100 , 'width' => 200 )
));
$expected = array (
'a' => array ( 'href' => '/images/view/3?height=100&width=200' ),
'Original size' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2009-01-14 22:19:11 +00:00
Configure :: write ( 'Asset.timestamp' , false );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> link ( $this -> Html -> image ( 'test.gif' ), '#' , array (), false , false , false );
$expected = array (
'a' => array ( 'href' => '#' ),
'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' ),
'/a'
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> image ( 'test.gif' , array ( 'url' => '#' ));
$expected = array (
'a' => array ( 'href' => '#' ),
'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' ),
'/a'
);
$this -> assertTags ( $result , $expected );
2009-01-14 22:19:11 +00:00
2009-07-25 19:43:26 +00:00
Configure :: write ( 'Asset.timestamp' , 'force' );
2009-01-14 22:19:11 +00:00
$result = $this -> Html -> link ( $this -> Html -> image ( 'test.gif' ), '#' , array (), false , false , false );
$expected = array (
'a' => array ( 'href' => '#' ),
'img' => array ( 'src' => 'preg:/img\/test\.gif\?\d*/' , 'alt' => '' ),
'/a'
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> image ( 'test.gif' , array ( 'url' => '#' ));
$expected = array (
'a' => array ( 'href' => '#' ),
'img' => array ( 'src' => 'preg:/img\/test\.gif\?\d*/' , 'alt' => '' ),
'/a'
);
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testImageTag method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testImageTag () {
2009-01-14 22:19:11 +00:00
Configure :: write ( 'Asset.timestamp' , false );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> image ( 'test.gif' );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' )));
$result = $this -> Html -> image ( 'http://google.com/logo.gif' );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'http://google.com/logo.gif' , 'alt' => '' )));
$result = $this -> Html -> image ( array ( 'controller' => 'test' , 'action' => 'view' , 1 , 'ext' => 'gif' ));
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '/test/view/1.gif' , 'alt' => '' )));
$result = $this -> Html -> image ( '/test/view/1.gif' );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '/test/view/1.gif' , 'alt' => '' )));
2009-09-24 04:28:27 +00:00
}
2008-05-30 11:40:08 +00:00
2009-09-24 04:28:27 +00:00
/**
* test image () with Asset . timestamp
*
* @ return void
**/
function testImageTagWithTimestampping () {
2009-07-25 19:43:26 +00:00
Configure :: write ( 'Asset.timestamp' , 'force' );
2009-01-14 22:19:11 +00:00
2009-03-06 04:40:50 +00:00
$result = $this -> Html -> image ( 'cake.icon.gif' );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'preg:/img\/cake\.icon\.gif\?\d+/' , 'alt' => '' )));
2009-03-19 21:10:13 +00:00
2009-03-06 04:40:50 +00:00
Configure :: write ( 'debug' , 0 );
Configure :: write ( 'Asset.timestamp' , 'force' );
$result = $this -> Html -> image ( 'cake.icon.gif' );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'preg:/img\/cake\.icon\.gif\?\d+/' , 'alt' => '' )));
2009-09-22 23:04:40 +00:00
$webroot = $this -> Html -> webroot ;
$this -> Html -> webroot = '/testing/longer/' ;
$result = $this -> Html -> image ( 'cake.icon.gif' );
$expected = array (
'img' => array ( 'src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.gif\?[0-9]+/' , 'alt' => '' )
);
$this -> assertTags ( $result , $expected );
$this -> Html -> webroot = $webroot ;
2009-07-04 22:04:40 +00:00
}
2009-07-24 19:18:37 +00:00
2009-07-04 22:04:40 +00:00
/**
* Tests creation of an image tag using a theme and asset timestamping
*
* @ access public
* @ return void
* @ link https :// trac . cakephp . org / ticket / 6490
*/
function testImageTagWithTheme () {
$file = WWW_ROOT . 'themed' . DS . 'default' . DS . 'img' . DS . 'cake.power.gif' ;
$message = " File ' { $file } ' not present. %s " ;
$this -> skipUnless ( file_exists ( $file ), $message );
2009-03-06 04:40:50 +00:00
2009-07-04 22:04:40 +00:00
Configure :: write ( 'Asset.timestamp' , true );
Configure :: write ( 'debug' , 1 );
$this -> Html -> themeWeb = 'themed/default/' ;
$result = $this -> Html -> image ( 'cake.power.gif' );
$this -> assertTags ( $result , array (
'img' => array (
'src' => 'preg:/themed\/default\/img\/cake\.power\.gif\?\d+/' ,
'alt' => ''
)));
2009-09-21 21:00:52 +00:00
$webroot = $this -> Html -> webroot ;
$this -> Html -> webroot = '/testing/' ;
$result = $this -> Html -> image ( 'cake.power.gif' );
$this -> assertTags ( $result , array (
'img' => array (
'src' => 'preg:/\/testing\/themed\/default\/img\/cake\.power\.gif\?\d+/' ,
'alt' => ''
)));
$this -> Html -> webroot = $webroot ;
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testStyle method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testStyle () {
$result = $this -> Html -> style ( array ( 'display' => 'none' , 'margin' => '10px' ));
$expected = 'display:none; margin:10px;' ;
$this -> assertPattern ( '/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/' , $expected );
$result = $this -> Html -> style ( array ( 'display' => 'none' , 'margin' => '10px' ), false );
$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 ]);
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testCssLink method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testCssLink () {
2009-01-14 22:19:11 +00:00
Configure :: write ( 'Asset.timestamp' , false );
Configure :: write ( 'Asset.filter.css' , false );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> css ( 'screen' );
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => 'preg:/.*css\/screen\.css/' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> css ( 'screen.css' );
$this -> assertTags ( $result , $expected );
2009-10-02 16:53:20 +00:00
$result = $this -> Html -> css ( 'my.css.library' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/my\.css\.library\.css/' ;
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> css ( 'screen.css?1234' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/screen\.css\?1234/' ;
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> css ( 'http://whatever.com/screen.css?1234' );
$expected [ 'link' ][ 'href' ] = 'preg:/http:\/\/.*\/screen\.css\?1234/' ;
$this -> assertTags ( $result , $expected );
2009-01-14 22:19:11 +00:00
Configure :: write ( 'Asset.filter.css' , 'css.php' );
$result = $this -> Html -> css ( 'cake.generic' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*ccss\/cake\.generic\.css/' ;
$this -> assertTags ( $result , $expected );
2009-07-25 19:43:26 +00:00
2009-01-14 22:19:11 +00:00
Configure :: write ( 'Asset.filter.css' , false );
$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 );
2009-09-24 04:28:27 +00:00
}
2009-09-03 17:50:53 +00:00
2009-09-24 04:28:27 +00:00
/**
* test use of css () and timestamping
*
* @ return void
**/
function testCssTimestamping () {
2009-07-25 19:43:26 +00:00
Configure :: write ( 'debug' , 2 );
2008-05-30 11:40:08 +00:00
Configure :: write ( 'Asset.timestamp' , true );
2009-01-14 22:19:11 +00:00
2009-09-24 04:28:27 +00:00
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => '' )
);
2009-01-14 22:19:11 +00:00
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> css ( 'cake.generic' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/' ;
$this -> assertTags ( $result , $expected );
Configure :: write ( 'debug' , 0 );
2008-11-08 00:24:51 +00:00
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> css ( 'cake.generic' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/cake\.generic\.css/' ;
$this -> assertTags ( $result , $expected );
Configure :: write ( 'Asset.timestamp' , 'force' );
2008-11-08 00:24:51 +00:00
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> css ( 'cake.generic' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/' ;
$this -> assertTags ( $result , $expected );
2008-11-08 00:24:51 +00:00
$webroot = $this -> Html -> webroot ;
$this -> Html -> webroot = '/testing/' ;
$result = $this -> Html -> css ( 'cake.generic' );
2009-09-21 21:00:52 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/' ;
2008-11-08 00:24:51 +00:00
$this -> assertTags ( $result , $expected );
$this -> Html -> webroot = $webroot ;
$webroot = $this -> Html -> webroot ;
$this -> Html -> webroot = '/testing/longer/' ;
$result = $this -> Html -> css ( 'cake.generic' );
2009-09-21 21:00:52 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/' ;
2008-11-08 00:24:51 +00:00
$this -> assertTags ( $result , $expected );
$this -> Html -> webroot = $webroot ;
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2009-03-12 23:51:30 +00:00
/**
* test timestamp enforcement for script tags .
*
* @ return void
**/
function testScriptTimestamping () {
2009-07-25 19:43:26 +00:00
$skip = $this -> skipIf ( ! is_writable ( JS ), 'webroot/js is not Writable, timestamp testing has been skipped' );
if ( $skip ) {
2009-03-12 23:51:30 +00:00
return ;
}
2009-07-25 19:43:26 +00:00
Configure :: write ( 'debug' , 2 );
2009-03-12 23:51:30 +00:00
Configure :: write ( 'Asset.timestamp' , true );
2009-07-25 19:43:26 +00:00
2009-03-12 23:51:30 +00:00
touch ( WWW_ROOT . 'js' . DS . '__cake_js_test.js' );
$timestamp = substr ( strtotime ( 'now' ), 0 , 8 );
2009-09-03 17:45:39 +00:00
$result = $this -> Html -> script ( '__cake_js_test' , array ( 'inline' => true , 'once' => false ));
2009-03-12 23:51:30 +00:00
$this -> assertPattern ( '/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/' , $result , 'Timestamp value not found %s' );
Configure :: write ( 'debug' , 0 );
Configure :: write ( 'Asset.timestamp' , 'force' );
2009-09-03 17:45:39 +00:00
$result = $this -> Html -> script ( '__cake_js_test' , array ( 'inline' => true , 'once' => false ));
2009-03-12 23:51:30 +00:00
$this -> assertPattern ( '/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/' , $result , 'Timestamp value not found %s' );
unlink ( WWW_ROOT . 'js' . DS . '__cake_js_test.js' );
Configure :: write ( 'Asset.timestamp' , false );
}
2009-09-03 17:45:39 +00:00
2009-03-12 23:51:30 +00:00
/**
* test that scripts added with uses () are only ever included once .
* test script tag generation
*
* @ return void
**/
function testScript () {
$result = $this -> Html -> script ( 'foo' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/foo.js' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( array ( 'foobar' , 'bar' ));
$expected = array (
array ( 'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/foobar.js' )),
'/script' ,
array ( 'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/bar.js' )),
'/script' ,
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( 'jquery-1.3' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/jquery-1.3.js' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( '/plugin/js/jquery-1.3.2.js?someparam=foo' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo' )
);
$this -> assertTags ( $result , $expected );
2009-09-03 17:50:53 +00:00
2009-03-12 23:51:30 +00:00
$result = $this -> Html -> script ( 'foo' );
$this -> assertNull ( $result , 'Script returned upon duplicate inclusion %s' );
$result = $this -> Html -> script ( array ( 'foo' , 'bar' , 'baz' ));
$this -> assertNoPattern ( '/foo.js/' , $result );
2009-09-03 17:45:39 +00:00
$result = $this -> Html -> script ( 'foo' , array ( 'inline' => true , 'once' => false ));
2009-03-12 23:51:30 +00:00
$this -> assertNotNull ( $result );
2009-09-03 17:45:39 +00:00
$result = $this -> Html -> script ( 'jquery-1.3.2' , array ( 'defer' => true , 'encoding' => 'utf-8' ));
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/jquery-1.3.2.js' , 'defer' => 'defer' , 'encoding' => 'utf-8' )
);
$this -> assertTags ( $result , $expected );
2009-03-12 23:51:30 +00:00
}
2009-09-24 04:28:27 +00:00
2009-03-13 02:59:55 +00:00
/**
* test Script block generation
*
* @ return void
**/
function testScriptBlock () {
$result = $this -> Html -> scriptBlock ( 'window.foo = 2;' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' ),
$this -> cDataStart ,
'window.foo = 2;' ,
$this -> cDataEnd ,
'/script' ,
);
$this -> assertTags ( $result , $expected );
2009-09-03 17:50:53 +00:00
2009-03-13 02:59:55 +00:00
$result = $this -> Html -> scriptBlock ( 'window.foo = 2;' , array ( 'safe' => false ));
$expected = array (
'script' => array ( 'type' => 'text/javascript' ),
'window.foo = 2;' ,
'/script' ,
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> scriptBlock ( 'window.foo = 2;' , array ( 'safe' => true ));
$expected = array (
'script' => array ( 'type' => 'text/javascript' ),
$this -> cDataStart ,
'window.foo = 2;' ,
$this -> cDataEnd ,
'/script' ,
);
$this -> assertTags ( $result , $expected );
2009-09-03 17:50:53 +00:00
2009-03-13 02:59:55 +00:00
$view =& ClassRegistry :: getObject ( 'view' );
$view =& new HtmlHelperMockView ();
$view -> expectAt ( 0 , 'addScript' , array ( new PatternExpectation ( '/window\.foo\s\=\s2;/' )));
2009-09-03 17:50:53 +00:00
2009-03-13 02:59:55 +00:00
$result = $this -> Html -> scriptBlock ( 'window.foo = 2;' , array ( 'inline' => false ));
$this -> assertNull ( $result );
2009-09-03 17:50:53 +00:00
$result = $this -> Html -> scriptBlock ( 'window.foo = 2;' , array ( 'safe' => false , 'encoding' => 'utf-8' ));
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'encoding' => 'utf-8' ),
'window.foo = 2;' ,
'/script' ,
);
$this -> assertTags ( $result , $expected );
2009-03-13 02:59:55 +00:00
}
2009-09-24 04:28:27 +00:00
2009-07-25 19:43:26 +00:00
/**
* test script tag output buffering when using scriptStart () and scriptEnd ();
*
* @ return void
**/
function testScriptStartAndScriptEnd () {
$result = $this -> Html -> scriptStart ( array ( 'safe' => true ));
$this -> assertNull ( $result );
echo 'this is some javascript' ;
$result = $this -> Html -> scriptEnd ();
$expected = array (
'script' => array ( 'type' => 'text/javascript' ),
$this -> cDataStart ,
'this is some javascript' ,
$this -> cDataEnd ,
'/script'
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> scriptStart ( array ( 'safe' => false ));
$this -> assertNull ( $result );
echo 'this is some javascript' ;
$result = $this -> Html -> scriptEnd ();
$expected = array (
'script' => array ( 'type' => 'text/javascript' ),
'this is some javascript' ,
'/script'
);
$this -> assertTags ( $result , $expected );
ClassRegistry :: removeObject ( 'view' );
$View =& new HtmlHelperMockView ();
$View -> expectOnce ( 'addScript' );
ClassRegistry :: addObject ( 'view' , $View );
$result = $this -> Html -> scriptStart ( array ( 'safe' => false , 'inline' => false ));
$this -> assertNull ( $result );
echo 'this is some javascript' ;
$result = $this -> Html -> scriptEnd ();
$this -> assertNull ( $result );
}
2009-09-24 04:28:27 +00:00
2008-06-02 19:22:55 +00:00
/**
* testCharsetTag method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testCharsetTag () {
Configure :: write ( 'App.encoding' , null );
$result = $this -> Html -> charset ();
$this -> assertTags ( $result , array ( 'meta' => array ( 'http-equiv' => 'Content-Type' , 'content' => 'text/html; charset=utf-8' )));
Configure :: write ( 'App.encoding' , 'ISO-8859-1' );
$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' )));
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testBreadcrumb method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testBreadcrumb () {
$this -> Html -> addCrumb ( 'First' , '#first' );
$this -> Html -> addCrumb ( 'Second' , '#second' );
$this -> Html -> addCrumb ( 'Third' , '#third' );
$result = $this -> Html -> getCrumbs ();
$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 );
$result = $this -> Html -> getCrumbs ( ' > ' );
$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 );
$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 );
$result = $this -> Html -> getCrumbs ();
$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 );
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testNestedList method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +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 );
$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 );
$result = $this -> Html -> nestedList ( $list , null );
$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 );
$result = $this -> Html -> nestedList ( $list , array (), array (), 'ol' );
$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 );
$result = $this -> Html -> nestedList ( $list , 'ol' );
$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 );
$result = $this -> Html -> nestedList ( $list , array ( 'class' => 'list' ));
$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 );
$result = $this -> Html -> nestedList ( $list , array (), array ( 'class' => 'item' ));
$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 );
$result = $this -> Html -> nestedList ( $list , array (), array ( 'even' => 'even' , 'odd' => 'odd' ));
$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 );
$result = $this -> Html -> nestedList ( $list , array ( 'class' => 'list' ), array ( 'class' => 'item' ));
$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 );
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testMeta method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testMeta () {
$result = $this -> Html -> meta ( 'this is an rss feed' , array ( 'controller' => 'posts' , 'ext' => 'rss' ));
$this -> assertTags ( $result , array ( 'link' => array ( 'href' => 'preg:/.*\/posts\.rss/' , 'type' => 'application/rss+xml' , 'rel' => 'alternate' , 'title' => 'this is an rss feed' )));
$result = $this -> Html -> meta ( 'rss' , array ( 'controller' => 'posts' , 'ext' => 'rss' ), array ( 'title' => 'this is an rss feed' ));
$this -> assertTags ( $result , array ( 'link' => array ( 'href' => 'preg:/.*\/posts\.rss/' , 'type' => 'application/rss+xml' , 'rel' => 'alternate' , 'title' => 'this is an rss feed' )));
$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' )));
2008-11-08 00:24:51 +00:00
2008-05-30 11:40:08 +00:00
$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 );
$result = $this -> Html -> meta ( 'icon' , 'favicon.ico' );
$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 );
$result = $this -> Html -> meta ( 'keywords' , 'these, are, some, meta, keywords' );
$this -> assertTags ( $result , array ( 'meta' => array ( 'name' => 'keywords' , 'content' => 'these, are, some, meta, keywords' )));
$result = $this -> Html -> meta ( 'description' , 'this is the meta description' );
$this -> assertTags ( $result , array ( 'meta' => array ( 'name' => 'description' , 'content' => 'this is the meta description' )));
$result = $this -> Html -> meta ( array ( 'name' => 'ROBOTS' , 'content' => 'ALL' ));
$this -> assertTags ( $result , array ( 'meta' => array ( 'name' => 'ROBOTS' , 'content' => 'ALL' )));
$this -> assertNull ( $this -> Html -> meta ( array ( 'name' => 'ROBOTS' , 'content' => 'ALL' ), null , array (), false ));
$view =& ClassRegistry :: getObject ( 'view' );
$result = $view -> __scripts [ 0 ];
$this -> assertTags ( $result , array ( 'meta' => array ( 'name' => 'ROBOTS' , 'content' => 'ALL' )));
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testTableHeaders method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +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 );
}
2009-07-24 19:18:37 +00:00
2008-06-02 19:22:55 +00:00
/**
* testTableCells method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testTableCells () {
$tr = array (
'td content 1' ,
array ( 'td content 2' , array ( " width " => " 100px " )),
2008-06-20 20:17:23 +00:00
array ( 'td content 3' , " width=100px " )
2008-05-30 11:40:08 +00:00
);
$result = $this -> Html -> tableCells ( $tr );
$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 );
$tr = array ( 'td content 1' , 'td content 2' , 'td content 3' );
$result = $this -> Html -> tableCells ( $tr , null , null , true );
$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 );
$tr = array ( 'td content 1' , 'td content 2' , 'td content 3' );
$result = $this -> Html -> tableCells ( $tr , true );
$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-11-08 00:24:51 +00:00
2008-05-30 11:40:08 +00:00
$tr = array (
2008-06-20 20:17:23 +00:00
array ( 'td content 1' , 'td content 2' , 'td content 3' ),
array ( 'td content 1' , 'td content 2' , 'td content 3' ),
array ( 'td content 1' , 'td content 2' , 'td content 3' )
2008-05-30 11:40:08 +00:00
);
$result = $this -> Html -> tableCells ( $tr , array ( 'class' => 'odd' ), array ( 'class' => 'even' ));
$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> " ;
$this -> assertEqual ( $result , $expected );
2008-11-08 00:24:51 +00:00
2008-05-30 11:40:08 +00:00
$tr = array (
2008-06-20 20:17:23 +00:00
array ( 'td content 1' , 'td content 2' , 'td content 3' ),
array ( 'td content 1' , 'td content 2' , 'td content 3' ),
array ( 'td content 1' , 'td content 2' , 'td content 3' ),
array ( 'td content 1' , 'td content 2' , 'td content 3' )
2008-05-30 11:40:08 +00:00
);
$result = $this -> Html -> tableCells ( $tr , array ( 'class' => 'odd' ), array ( 'class' => 'even' ));
$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> " ;
$this -> assertEqual ( $result , $expected );
2008-11-08 00:24:51 +00:00
2008-05-30 11:40:08 +00:00
$tr = array (
2008-06-20 20:17:23 +00:00
array ( 'td content 1' , 'td content 2' , 'td content 3' ),
array ( 'td content 1' , 'td content 2' , 'td content 3' ),
array ( 'td content 1' , 'td content 2' , 'td content 3' )
2008-05-30 11:40:08 +00:00
);
2008-06-20 20:17:23 +00:00
$this -> Html -> tableCells ( $tr , array ( 'class' => 'odd' ), array ( 'class' => 'even' ));
$result = $this -> Html -> tableCells ( $tr , array ( 'class' => 'odd' ), array ( 'class' => 'even' ), false , false );
2008-05-30 11:40:08 +00:00
$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> " ;
$this -> assertEqual ( $result , $expected );
}
2009-07-24 19:18:37 +00:00
2008-06-05 15:20:45 +00:00
/**
* testTag method
2008-11-08 00:24:51 +00:00
*
2008-06-05 15:20:45 +00:00
* @ access public
* @ return void
*/
2008-06-20 20:17:23 +00:00
function testTag () {
$result = $this -> Html -> tag ( 'div' );
$this -> assertTags ( $result , '<div' );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> tag ( 'div' , 'text' );
$this -> assertTags ( $result , '<div' , 'text' , '/div' );
$result = $this -> Html -> tag ( 'div' , '<text>' , array ( 'class' => 'class-name' ), true );
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), '<text>' , '/div' ));
2008-06-20 20:17:23 +00:00
2009-08-27 02:46:49 +00:00
$result = $this -> Html -> tag ( 'div' , '<text>' , array ( 'class' => 'class-name' , 'escape' => true ));
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), '<text>' , '/div' ));
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> tag ( 'div' , '<text>' , 'class-name' , true );
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), '<text>' , '/div' ));
2008-06-20 20:17:23 +00:00
}
2009-07-24 19:18:37 +00:00
2008-06-05 15:20:45 +00:00
/**
* testDiv method
2008-11-08 00:24:51 +00:00
*
2008-06-05 15:20:45 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testDiv () {
$result = $this -> Html -> div ( 'class-name' );
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' )));
$result = $this -> Html -> div ( 'class-name' , 'text' );
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), 'text' , '/div' ));
$result = $this -> Html -> div ( 'class-name' , '<text>' , array (), true );
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'class-name' ), '<text>' , '/div' ));
}
2009-07-24 19:18:37 +00:00
2008-06-05 15:20:45 +00:00
/**
* testPara method
2008-11-08 00:24:51 +00:00
*
2008-06-05 15:20:45 +00:00
* @ access public
* @ return void
*/
2008-05-30 11:40:08 +00:00
function testPara () {
2008-06-19 14:31:00 +00:00
$result = $this -> Html -> para ( 'class-name' , '' );
2008-05-30 11:40:08 +00:00
$this -> assertTags ( $result , array ( 'p' => array ( 'class' => 'class-name' )));
$result = $this -> Html -> para ( 'class-name' , 'text' );
$this -> assertTags ( $result , array ( 'p' => array ( 'class' => 'class-name' ), 'text' , '/p' ));
$result = $this -> Html -> para ( 'class-name' , '<text>' , array (), true );
$this -> assertTags ( $result , array ( 'p' => array ( 'class' => 'class-name' ), '<text>' , '/p' ));
}
}
2008-06-27 08:17:02 +00:00
?>