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
*
2017-06-10 22:15:34 +00:00
* CakePHP ( tm ) Tests < https :// book . cakephp . org / 2.0 / en / development / testing . html >
2017-06-10 22:10:52 +00:00
* Copyright ( c ) Cake Software Foundation , Inc . ( https :// cakefoundation . org )
2008-05-30 11:40:08 +00:00
*
2010-10-03 16:31:21 +00:00
* Licensed under The MIT License
2013-02-08 12:22:51 +00:00
* For full copyright and license information , please see the LICENSE . txt
2010-10-03 16:31:21 +00:00
* Redistributions of files must retain the above copyright notice
2008-05-30 11:40:08 +00:00
*
2017-06-10 22:10:52 +00:00
* @ copyright Copyright ( c ) Cake Software Foundation , Inc . ( https :// cakefoundation . org )
2017-06-10 22:15:34 +00:00
* @ link https :// book . cakephp . org / 2.0 / en / development / testing . html CakePHP ( tm ) Tests
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . View . Helper
2008-10-30 17:30:26 +00:00
* @ since CakePHP ( tm ) v 1.2 . 0.4206
2017-06-10 22:23:14 +00:00
* @ license https :// opensource . org / licenses / mit - license . php MIT License
2008-05-30 11:40:08 +00:00
*/
2010-12-10 06:23:27 +00:00
2011-04-17 16:03:43 +00:00
App :: uses ( 'Controller' , 'Controller' );
2010-12-10 06:23:27 +00:00
App :: uses ( 'Helper' , 'View' );
App :: uses ( 'AppHelper' , 'View/Helper' );
App :: uses ( 'HtmlHelper' , 'View/Helper' );
2011-06-05 02:23:55 +00:00
App :: uses ( 'FormHelper' , 'View/Helper' );
2011-04-17 16:03:43 +00:00
App :: uses ( 'ClassRegistry' , 'Utility' );
App :: uses ( 'Folder' , 'Utility' );
2014-06-24 09:52:29 +00:00
App :: uses ( 'CakePlugin' , 'Core' );
2009-07-24 19:18:37 +00:00
2010-04-26 18:47:19 +00:00
if ( ! defined ( 'FULL_BASE_URL' )) {
2017-06-10 21:33:55 +00:00
define ( 'FULL_BASE_URL' , 'https://cakephp.org' );
2010-04-26 18:47:19 +00:00
}
2008-06-02 19:22:55 +00:00
/**
* TheHtmlTestController class
2008-11-08 00:24:51 +00:00
*
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . View . Helper
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
*
2013-06-08 02:29:08 +00:00
* @ var string
2008-06-02 19:22:55 +00:00
*/
2010-04-04 07:14:00 +00:00
public $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
*
2014-07-03 13:36:42 +00:00
* @ var mixed
2008-06-02 19:22:55 +00:00
*/
2010-04-04 07:14:00 +00:00
public $uses = null ;
2008-05-30 11:40:08 +00:00
}
2009-03-13 02:59:55 +00:00
2011-01-23 14:36:14 +00:00
class TestHtmlHelper extends HtmlHelper {
2012-03-16 02:50:05 +00:00
2011-01-23 14:36:14 +00:00
/**
* expose a method as public
*
2011-04-17 16:03:43 +00:00
* @ param string $options
* @ param string $exclude
* @ param string $insertBefore
* @ param string $insertAfter
2011-01-23 14:36:14 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function parseAttributes ( $options , $exclude = null , $insertBefore = ' ' , $insertAfter = null ) {
2011-01-23 14:36:14 +00:00
return $this -> _parseAttributes ( $options , $exclude , $insertBefore , $insertAfter );
}
2011-01-23 21:27:50 +00:00
/**
* Get a protected attribute value
*
* @ param string $attribute
* @ return mixed
*/
public function getAttribute ( $attribute ) {
if ( ! isset ( $this -> { $attribute })) {
return null ;
}
return $this -> { $attribute };
}
2011-01-23 14:36:14 +00:00
}
/**
* Html5TestHelper class
*
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . View . Helper
2011-01-23 14:36:14 +00:00
*/
class Html5TestHelper extends TestHtmlHelper {
/**
* Minimized
*
* @ var array
*/
protected $_minimizedAttributes = array ( 'require' , 'checked' );
/**
* Allow compact use in HTML
*
* @ var string
*/
protected $_minimizedAttributeFormat = '%s' ;
/**
* Test to attribute format
*
* @ var string
*/
protected $_attributeFormat = 'data-%s="%s"' ;
}
2008-06-02 19:22:55 +00:00
/**
* HtmlHelperTest class
2008-11-08 00:24:51 +00:00
*
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . View . Helper
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
*/
2010-04-04 07:14:00 +00:00
public $cDataStart = 'preg:/^\/\/<!\[CDATA\[[\n\r]*/' ;
2010-09-26 01:36:49 +00:00
2009-03-13 02:59:55 +00:00
/**
* Regexp for CDATA end block
*
* @ var string
*/
2010-04-04 07:14:00 +00:00
public $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/' ;
2010-09-26 01:36:49 +00:00
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
*/
2010-04-04 07:14:00 +00:00
public $Html = null ;
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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function setUp () {
2010-09-26 01:36:49 +00:00
parent :: setUp ();
2011-08-17 01:23:41 +00:00
$this -> View = $this -> getMock ( 'View' , array ( 'append' ), array ( new TheHtmlTestController ()));
2011-01-23 21:27:50 +00:00
$this -> Html = new TestHtmlHelper ( $this -> View );
2010-05-15 03:11:38 +00:00
$this -> Html -> request = new CakeRequest ( null , false );
$this -> Html -> request -> webroot = '' ;
2010-11-17 03:52:49 +00:00
2012-02-08 04:14:56 +00:00
App :: build ( array (
2012-03-16 02:50:05 +00:00
'Plugin' => array ( CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS )
2012-02-08 04:14:56 +00:00
));
2010-11-17 03:52:49 +00:00
Configure :: write ( 'Asset.timestamp' , false );
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2009-03-19 21:10:13 +00:00
/**
2010-09-26 01:36:49 +00:00
* tearDown method
2009-03-19 21:10:13 +00:00
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function tearDown () {
2010-09-26 01:36:49 +00:00
parent :: tearDown ();
2010-07-15 02:26:42 +00:00
unset ( $this -> Html , $this -> View );
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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testDocType () {
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> docType ();
2011-12-05 01:25:58 +00:00
$expected = '<!DOCTYPE html>' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2008-05-30 11:40:08 +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">' ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2008-05-30 11:40:08 +00:00
$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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testLink () {
2011-12-20 01:49:01 +00:00
Router :: connect ( '/:controller/:action/*' );
2010-05-15 03:11:38 +00:00
$this -> Html -> request -> webroot = '' ;
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> link ( '/home' );
$expected = array ( 'a' => array ( 'href' => '/home' ), 'preg:/\/home/' , '/a' );
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2011-12-20 01:49:01 +00:00
$result = $this -> Html -> link ( array ( 'action' => 'login' , '<[You]>' ));
$expected = array (
'a' => array ( 'href' => '/login/%3C%5BYou%5D%3E' ),
'preg:/\/login\/<\[You\]>/' ,
'/a'
);
$this -> assertTags ( $result , $expected );
Router :: reload ();
2010-04-26 18:47:19 +00:00
$result = $this -> Html -> link ( 'Posts' , array ( 'controller' => 'posts' , 'action' => 'index' , 'full_base' => true ));
2013-07-31 14:36:57 +00:00
$expected = array ( 'a' => array ( 'href' => Router :: fullBaseUrl () . '/posts' ), 'Posts' , '/a' );
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2010-04-26 18:47:19 +00:00
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> link ( 'Home' , '/home' , array ( 'confirm' => 'Are you sure you want to do this?' ));
$expected = array (
2013-08-05 14:20:53 +00:00
'a' => array ( 'href' => '/home' , 'onclick' => 'if (confirm("Are you sure you want to do this?")) { return true; } return false;' ),
2008-05-30 11:40:08 +00:00
'Home' ,
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2013-08-13 08:11:22 +00:00
$result = $this -> Html -> link ( 'Home' , '/home' , array ( 'escape' => false , 'confirm' => 'Confirm\'s "nightmares"' ));
$expected = array (
'a' => array ( 'href' => '/home' , 'onclick' => 'if (confirm("Confirm's \"nightmares\"")) { return true; } return false;' ),
'Home' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> link ( 'Home' , '/home' , array ( 'default' => false ));
$expected = array (
'a' => array ( 'href' => '/home' , 'onclick' => 'event.returnValue = false; return false;' ),
'Home' ,
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2011-09-07 23:59:39 +00:00
$result = $this -> Html -> link ( 'Home' , '/home' , array ( 'default' => false , 'onclick' => 'someFunction();' ));
$expected = array (
'a' => array ( 'href' => '/home' , 'onclick' => 'someFunction(); event.returnValue = false; return false;' ),
'Home' ,
'/a'
);
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' );
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' , array ( 'escape' => true ));
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' , array ( 'escape' => 'utf-8' ));
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' , array ( 'escape' => false ));
$expected = array (
'a' => array ( 'href' => '#' ),
'Next >' ,
'/a'
);
2011-05-17 04:36:22 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$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' => true
2009-10-17 02:49:44 +00:00
));
2009-02-23 15:19:33 +00:00
$expected = array (
'a' => array ( 'href' => '#' , 'title' => 'to escape &#8230; or not escape?' ),
2009-10-17 02:49:44 +00:00
'Next >' ,
2009-02-23 15:19:33 +00:00
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-02-23 15:19:33 +00:00
2013-06-29 12:36:55 +00:00
$result = $this -> Html -> link ( 'Next >' , '#' , array (
'title' => 'Next >' ,
'escapeTitle' => false
));
$expected = array (
'a' => array ( 'href' => '#' , 'title' => 'Next >' ),
'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'
);
2011-05-17 04:36:22 +00:00
$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 );
2009-10-17 02:49:44 +00:00
$result = $this -> Html -> link ( $this -> Html -> image ( 'test.gif' ), '#' , array ( 'escape' => false ));
2008-05-30 11:40:08 +00:00
$expected = array (
'a' => array ( 'href' => '#' ),
'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' ),
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2013-06-29 12:36:55 +00:00
$result = $this -> Html -> link ( $this -> Html -> image ( 'test.gif' ), '#' , array (
'title' => 'hey "howdy"' ,
'escapeTitle' => false
));
$expected = array (
'a' => array ( 'href' => '#' , 'title' => 'hey "howdy"' ),
'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' ),
'/a'
);
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> image ( 'test.gif' , array ( 'url' => '#' ));
$expected = array (
'a' => array ( 'href' => '#' ),
'img' => array ( 'src' => 'img/test.gif' , 'alt' => '' ),
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-01-14 22:19:11 +00:00
2012-01-18 02:15:11 +00:00
$result = $this -> Html -> link ( $this -> Html -> image ( '../favicon.ico' ), '#' , array ( 'escape' => false ));
2012-11-21 14:39:03 +00:00
$expected = array (
'a' => array ( 'href' => '#' ),
2012-01-18 02:15:11 +00:00
'img' => array ( 'src' => 'img/../favicon.ico' , 'alt' => '' ),
2009-01-14 22:19:11 +00:00
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-01-14 22:19:11 +00:00
2011-05-10 04:03:58 +00:00
$result = $this -> Html -> image ( '../favicon.ico' , array ( 'url' => '#' ));
2009-01-14 22:19:11 +00:00
$expected = array (
'a' => array ( 'href' => '#' ),
2012-01-18 02:15:11 +00:00
'img' => array ( 'src' => 'img/../favicon.ico' , 'alt' => '' ),
2009-01-14 22:19:11 +00:00
'/a'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2012-06-12 14:59:16 +00:00
2012-06-12 14:30:37 +00:00
$result = $this -> Html -> link ( 'http://www.example.org?param1=value1¶m2=value2' );
$expected = array ( 'a' => array ( 'href' => 'http://www.example.org?param1=value1&param2=value2' ), 'http://www.example.org?param1=value1&param2=value2' , '/a' );
$this -> assertTags ( $result , $expected );
2012-08-01 10:11:05 +00:00
2012-08-01 10:14:46 +00:00
$result = $this -> Html -> link ( 'alert' , 'javascript:alert(\'cakephp\');' );
$expected = array ( 'a' => array ( 'href' => 'javascript:alert('cakephp');' ), 'alert' , '/a' );
$this -> assertTags ( $result , $expected );
2012-08-01 10:11:05 +00:00
$result = $this -> Html -> link ( 'write me' , 'mailto:example@cakephp.org' );
$expected = array ( 'a' => array ( 'href' => 'mailto:example@cakephp.org' ), 'write me' , '/a' );
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> link ( 'call me on 0123465-798' , 'tel:0123465-798' );
$expected = array ( 'a' => array ( 'href' => 'tel:0123465-798' ), 'call me on 0123465-798' , '/a' );
$this -> assertTags ( $result , $expected );
2012-08-01 10:38:06 +00:00
$result = $this -> Html -> link ( 'text me on 0123465-798' , 'sms:0123465-798' );
$expected = array ( 'a' => array ( 'href' => 'sms:0123465-798' ), 'text me on 0123465-798' , '/a' );
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> link ( 'say hello to 0123465-798' , 'sms:0123465-798?body=hello there' );
$expected = array ( 'a' => array ( 'href' => 'sms:0123465-798?body=hello there' ), 'say hello to 0123465-798' , '/a' );
$this -> assertTags ( $result , $expected );
2012-08-01 10:48:21 +00:00
$result = $this -> Html -> link ( 'say hello to 0123465-798' , 'sms:0123465-798?body=hello "cakephp"' );
$expected = array ( 'a' => array ( 'href' => 'sms:0123465-798?body=hello "cakephp"' ), 'say hello to 0123465-798' , '/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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testImageTag () {
2010-05-15 03:11:38 +00:00
$this -> Html -> request -> webroot = '' ;
2009-01-14 22:19:11 +00:00
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' => '' )));
2013-08-03 15:04:52 +00:00
$result = $this -> Html -> image ( '//google.com/logo.gif' );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '//google.com/logo.gif' , 'alt' => '' )));
2008-05-30 11:40:08 +00:00
$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' => '' )));
2013-11-09 17:00:56 +00:00
}
2012-02-01 13:37:46 +00:00
2013-11-09 17:00:56 +00:00
/**
* Test image () with query strings .
*
* @ return void
*/
public function testImageQueryString () {
2012-04-10 01:20:03 +00:00
$result = $this -> Html -> image ( 'test.gif?one=two&three=four' );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'img/test.gif?one=two&three=four' , 'alt' => '' )));
2013-05-28 02:48:59 +00:00
2013-11-09 17:00:56 +00:00
$result = $this -> Html -> image ( array (
'controller' => 'images' ,
'action' => 'display' ,
'test' ,
'?' => array ( 'one' => 'two' , 'three' => 'four' )
));
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '/images/display/test?one=two&three=four' , 'alt' => '' )));
}
/**
* Test that image works with pathPrefix .
*
* @ return void
*/
public function testImagePathPrefix () {
2013-05-28 02:48:59 +00:00
$result = $this -> Html -> image ( 'test.gif' , array ( 'pathPrefix' => '/my/custom/path/' ));
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '/my/custom/path/test.gif' , 'alt' => '' )));
2017-06-10 21:33:55 +00:00
$result = $this -> Html -> image ( 'test.gif' , array ( 'pathPrefix' => 'https://cakephp.org/assets/img/' ));
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'https://cakephp.org/assets/img/test.gif' , 'alt' => '' )));
2013-05-28 04:02:49 +00:00
$result = $this -> Html -> image ( 'test.gif' , array ( 'pathPrefix' => '//cakephp.org/assets/img/' ));
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '//cakephp.org/assets/img/test.gif' , 'alt' => '' )));
2013-08-03 15:04:52 +00:00
$previousConfig = Configure :: read ( 'App.imageBaseUrl' );
Configure :: write ( 'App.imageBaseUrl' , '//cdn.cakephp.org/img/' );
$result = $this -> Html -> image ( 'test.gif' );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => '//cdn.cakephp.org/img/test.gif' , 'alt' => '' )));
Configure :: write ( 'App.imageBaseUrl' , $previousConfig );
2012-07-04 00:48:10 +00:00
}
2012-04-10 01:20:03 +00:00
2012-07-04 00:48:10 +00:00
/**
* Test that image () works with fullBase and a webroot not equal to /
*
* @ return void
*/
public function testImageWithFullBase () {
2012-01-18 11:32:40 +00:00
$result = $this -> Html -> image ( 'test.gif' , array ( 'fullBase' => true ));
2012-01-18 01:55:24 +00:00
$here = $this -> Html -> url ( '/' , true );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => $here . 'img/test.gif' , 'alt' => '' )));
2012-02-01 13:37:46 +00:00
$result = $this -> Html -> image ( 'sub/test.gif' , array ( 'fullBase' => true ));
$here = $this -> Html -> url ( '/' , true );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => $here . 'img/sub/test.gif' , 'alt' => '' )));
2012-07-04 00:48:10 +00:00
$request = $this -> Html -> request ;
$request -> webroot = '/myproject/' ;
$request -> base = '/myproject' ;
Router :: setRequestInfo ( $request );
$result = $this -> Html -> image ( 'sub/test.gif' , array ( 'fullBase' => true ));
$here = $this -> Html -> url ( '/' , true );
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => $here . 'img/sub/test.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
2009-11-14 12:19:25 +00:00
*/
2011-05-30 20:02:32 +00:00
public function testImageWithTimestampping () {
2009-07-25 19:43:26 +00:00
Configure :: write ( 'Asset.timestamp' , 'force' );
2009-01-14 22:19:11 +00:00
2010-05-15 03:11:38 +00:00
$this -> Html -> request -> webroot = '/' ;
2010-01-14 04:47:31 +00:00
$result = $this -> Html -> image ( 'cake.icon.png' );
2010-04-09 03:36:04 +00:00
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'preg:/\/img\/cake\.icon\.png\?\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' );
2010-01-14 04:47:31 +00:00
$result = $this -> Html -> image ( 'cake.icon.png' );
2010-04-09 03:36:04 +00:00
$this -> assertTags ( $result , array ( 'img' => array ( 'src' => 'preg:/\/img\/cake\.icon\.png\?\d+/' , 'alt' => '' )));
2009-09-22 23:04:40 +00:00
2010-05-15 03:11:38 +00:00
$this -> Html -> request -> webroot = '/testing/longer/' ;
2010-01-14 04:47:31 +00:00
$result = $this -> Html -> image ( 'cake.icon.png' );
2009-09-22 23:04:40 +00:00
$expected = array (
2010-01-14 04:47:31 +00:00
'img' => array ( 'src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/' , 'alt' => '' )
2009-09-22 23:04:40 +00:00
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
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
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testImageTagWithTheme () {
2011-12-03 20:00:06 +00:00
$this -> skipIf ( ! is_writable ( WWW_ROOT ), 'Cannot write to webroot.' );
$themeExists = is_dir ( WWW_ROOT . 'theme' );
2011-05-31 00:49:46 +00:00
2010-12-10 06:23:27 +00:00
App :: uses ( 'File' , 'Utility' );
2010-04-09 03:36:04 +00:00
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif' ;
2013-01-23 12:45:50 +00:00
new File ( $testfile , true );
2010-04-09 03:36:04 +00:00
2009-11-25 07:51:25 +00:00
App :: build ( array (
2012-03-16 02:50:05 +00:00
'View' => array ( CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS )
2009-11-25 07:51:25 +00:00
));
2009-07-04 22:04:40 +00:00
Configure :: write ( 'Asset.timestamp' , true );
Configure :: write ( 'debug' , 1 );
2010-04-09 03:36:04 +00:00
2010-05-15 03:11:38 +00:00
$this -> Html -> request -> webroot = '/' ;
2009-11-25 07:51:25 +00:00
$this -> Html -> theme = 'test_theme' ;
2010-04-09 03:36:04 +00:00
$result = $this -> Html -> image ( '__cake_test_image.gif' );
2009-07-04 22:04:40 +00:00
$this -> assertTags ( $result , array (
'img' => array (
2010-04-09 03:36:04 +00:00
'src' => 'preg:/\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/' ,
2009-07-04 22:04:40 +00:00
'alt' => ''
)));
2009-09-21 21:00:52 +00:00
2010-05-15 03:11:38 +00:00
$this -> Html -> request -> webroot = '/testing/' ;
2010-04-09 03:36:04 +00:00
$result = $this -> Html -> image ( '__cake_test_image.gif' );
2010-04-26 18:47:19 +00:00
2009-09-21 21:00:52 +00:00
$this -> assertTags ( $result , array (
'img' => array (
2010-04-09 03:36:04 +00:00
'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/' ,
2009-09-21 21:00:52 +00:00
'alt' => ''
)));
2010-04-26 18:47:19 +00:00
2010-05-15 03:11:38 +00:00
$dir = new Folder ( WWW_ROOT . 'theme' . DS . 'test_theme' );
2010-04-09 03:36:04 +00:00
$dir -> delete ();
2011-12-03 20:00:06 +00:00
if ( ! $themeExists ) {
$dir = new Folder ( WWW_ROOT . 'theme' );
$dir -> delete ();
}
2008-05-30 11:40:08 +00:00
}
2010-04-26 18:47:19 +00:00
2009-11-27 16:27:15 +00:00
/**
* test theme assets in main webroot path
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testThemeAssetsInMainWebrootPath () {
2009-11-27 16:27:15 +00:00
App :: build ( array (
2012-03-16 02:50:05 +00:00
'View' => array ( CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS )
2009-11-27 16:27:15 +00:00
));
$webRoot = Configure :: read ( 'App.www_root' );
2011-04-17 10:35:21 +00:00
Configure :: write ( 'App.www_root' , CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS );
2010-04-26 18:47:19 +00:00
2009-11-27 16:27:15 +00:00
$this -> Html -> theme = 'test_theme' ;
$result = $this -> Html -> css ( 'webroot_test' );
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => 'preg:/.*theme\/test_theme\/css\/webroot_test\.css/' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-11-27 16:27:15 +00:00
$this -> Html -> theme = 'test_theme' ;
$result = $this -> Html -> css ( 'theme_webroot' );
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => 'preg:/.*theme\/test_theme\/css\/theme_webroot\.css/' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2010-04-26 18:47:19 +00:00
2009-11-27 16:27:15 +00:00
Configure :: write ( 'App.www_root' , $webRoot );
}
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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testStyle () {
2011-09-07 23:59:39 +00:00
$result = $this -> Html -> style ( 'display: none;' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'display: none;' , $result );
2011-09-07 23:59:39 +00:00
2011-12-01 07:21:31 +00:00
$result = $this -> Html -> style ( array ( 'display' => 'none' , 'margin' => '10px' ));
2008-05-30 11:40:08 +00:00
$expected = 'display:none; margin:10px;' ;
2011-11-16 00:07:56 +00:00
$this -> assertRegExp ( '/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/' , $expected );
2008-05-30 11:40:08 +00:00
2011-12-01 07:21:31 +00:00
$result = $this -> Html -> style ( array ( 'display' => 'none' , 'margin' => '10px' ), false );
2008-05-30 11:40:08 +00:00
$lines = explode ( " \n " , $result );
2011-11-16 00:07:56 +00:00
$this -> assertRegExp ( '/^\s*display\s*:\s*none\s*;\s*$/' , $lines [ 0 ]);
$this -> assertRegExp ( '/^\s*margin\s*:\s*10px\s*;?$/' , $lines [ 1 ]);
2008-05-30 11:40:08 +00:00
}
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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testCssLink () {
2009-01-14 22:19:11 +00:00
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/' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> css ( 'screen.css' );
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2012-02-08 04:14:56 +00:00
CakePlugin :: load ( 'TestPlugin' );
2013-02-02 06:05:48 +00:00
$result = $this -> Html -> css ( 'TestPlugin.style' , array ( 'plugin' => false ));
2012-02-08 04:14:56 +00:00
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/TestPlugin\.style\.css/' ;
$this -> assertTags ( $result , $expected );
CakePlugin :: unload ( 'TestPlugin' );
2009-10-02 16:53:20 +00:00
$result = $this -> Html -> css ( 'my.css.library' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/my\.css\.library\.css/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-10-02 16:53:20 +00:00
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> css ( 'screen.css?1234' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*css\/screen\.css\?1234/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2012-04-10 01:20:03 +00:00
$result = $this -> Html -> css ( 'screen.css?with=param&other=param' );
$expected [ 'link' ][ 'href' ] = 'css/screen.css?with=param&other=param' ;
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> css ( 'http://whatever.com/screen.css?1234' );
$expected [ 'link' ][ 'href' ] = 'preg:/http:\/\/.*\/screen\.css\?1234/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2013-05-28 02:48:59 +00:00
$result = $this -> Html -> css ( 'cake.generic' , array ( 'pathPrefix' => '/my/custom/path/' ));
$expected [ 'link' ][ 'href' ] = '/my/custom/path/cake.generic.css' ;
$this -> assertTags ( $result , $expected );
2017-06-10 21:33:55 +00:00
$result = $this -> Html -> css ( 'cake.generic' , array ( 'pathPrefix' => 'https://cakephp.org/assets/css/' ));
$expected [ 'link' ][ 'href' ] = 'https://cakephp.org/assets/css/cake.generic.css' ;
2013-05-28 02:48:59 +00:00
$this -> assertTags ( $result , $expected );
2013-08-03 15:04:52 +00:00
$previousConfig = Configure :: read ( 'App.cssBaseUrl' );
Configure :: write ( 'App.cssBaseUrl' , '//cdn.cakephp.org/css/' );
$result = $this -> Html -> css ( 'cake.generic' );
$expected [ 'link' ][ 'href' ] = '//cdn.cakephp.org/css/cake.generic.css' ;
$this -> assertTags ( $result , $expected );
Configure :: write ( 'App.cssBaseUrl' , $previousConfig );
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/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-07-25 19:43:26 +00:00
2011-11-25 02:01:53 +00:00
$result = $this -> Html -> css ( '//example.com/css/cake.generic.css' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*example\.com\/css\/cake\.generic\.css/' ;
$this -> assertTags ( $result , $expected );
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 );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , count ( $result ));
2009-11-06 04:32:39 +00:00
2011-08-17 01:23:41 +00:00
$this -> View -> expects ( $this -> at ( 0 ))
-> method ( 'append' )
-> with ( 'css' , $this -> matchesRegularExpression ( '/css_in_head.css/' ));
2009-11-06 04:32:39 +00:00
2010-07-15 02:26:42 +00:00
$this -> View -> expects ( $this -> at ( 1 ))
2011-08-17 01:23:41 +00:00
-> method ( 'append' )
-> with ( 'css' , $this -> matchesRegularExpression ( '/more_css_in_head.css/' ));
2010-07-15 02:26:42 +00:00
2013-02-02 06:05:48 +00:00
$result = $this -> Html -> css ( 'css_in_head' , array ( 'inline' => false ));
$this -> assertNull ( $result );
$result = $this -> Html -> css ( 'more_css_in_head' , array ( 'inline' => false ));
$this -> assertNull ( $result );
$result = $this -> Html -> css ( 'screen' , array ( 'rel' => 'import' ));
$expected = array (
'style' => array ( 'type' => 'text/css' ),
'preg:/@import url\(.*css\/screen\.css\);/' ,
'/style'
);
$this -> assertTags ( $result , $expected );
}
2014-06-05 02:15:56 +00:00
/**
* Test css () with once option .
*
* @ return void
*/
public function testCssLinkOnce () {
Configure :: write ( 'Asset.filter.css' , false );
$result = $this -> Html -> css ( 'screen' , array ( 'once' => true ));
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => 'preg:/.*css\/screen\.css/' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> css ( 'screen' , array ( 'once' => true ));
$this -> assertEquals ( '' , $result );
// Default is once=false
$result = $this -> Html -> css ( 'screen' );
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => 'preg:/.*css\/screen\.css/' )
);
$this -> assertTags ( $result , $expected );
}
2013-02-02 06:05:48 +00:00
/**
* Test css link BC usage
*
* @ return void
*/
public function testCssLinkBC () {
Configure :: write ( 'Asset.filter.css' , false );
CakePlugin :: load ( 'TestPlugin' );
$result = $this -> Html -> css ( 'TestPlugin.style' , null , array ( 'plugin' => false ));
$expected = array (
'link' => array (
'rel' => 'stylesheet' ,
'type' => 'text/css' ,
'href' => 'preg:/.*css\/TestPlugin\.style\.css/'
)
);
$this -> assertTags ( $result , $expected );
CakePlugin :: unload ( 'TestPlugin' );
$result = $this -> Html -> css ( 'screen' , 'import' );
$expected = array (
'style' => array ( 'type' => 'text/css' ),
'preg:/@import url\(.*css\/screen\.css\);/' ,
'/style'
);
$this -> assertTags ( $result , $expected );
2010-07-15 02:26:42 +00:00
$result = $this -> Html -> css ( 'css_in_head' , null , array ( 'inline' => false ));
$this -> assertNull ( $result );
2009-11-06 04:32:39 +00:00
$result = $this -> Html -> css ( 'more_css_in_head' , null , array ( 'inline' => false ));
$this -> assertNull ( $result );
2009-09-24 04:28:27 +00:00
}
2009-09-03 17:50:53 +00:00
2013-03-29 14:24:08 +00:00
/**
* testCssWithFullBase method
*
* @ return void
*/
public function testCssWithFullBase () {
Configure :: write ( 'Asset.filter.css' , false );
$here = $this -> Html -> url ( '/' , true );
$result = $this -> Html -> css ( 'screen' , null , array ( 'fullBase' => true ));
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => $here . 'css/screen.css' )
);
$this -> assertTags ( $result , $expected );
}
2012-02-08 04:14:56 +00:00
/**
* testPluginCssLink method
*
* @ return void
*/
public function testPluginCssLink () {
Configure :: write ( 'Asset.filter.css' , false );
CakePlugin :: load ( 'TestPlugin' );
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset' );
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset.css' );
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> css ( 'TestPlugin.my.css.library' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*test_plugin\/css\/my\.css\.library\.css/' ;
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset.css?1234' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?1234/' ;
$this -> assertTags ( $result , $expected );
Configure :: write ( 'Asset.filter.css' , 'css.php' );
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*test_plugin\/ccss\/test_plugin_asset\.css/' ;
$this -> assertTags ( $result , $expected );
Configure :: write ( 'Asset.filter.css' , false );
$result = explode ( " \n " , trim ( $this -> Html -> css ( array ( 'TestPlugin.test_plugin_asset' , 'TestPlugin.vendor.generic' ))));
$expected [ 'link' ][ 'href' ] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/' ;
$this -> assertTags ( $result [ 0 ], $expected );
$expected [ 'link' ][ 'href' ] = 'preg:/.*test_plugin\/css\/vendor\.generic\.css/' ;
$this -> assertTags ( $result [ 1 ], $expected );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , count ( $result ));
2012-02-08 04:14:56 +00:00
CakePlugin :: unload ( 'TestPlugin' );
}
2009-09-24 04:28:27 +00:00
/**
* test use of css () and timestamping
*
* @ return void
2009-11-14 12:19:25 +00:00
*/
2011-05-30 20:02:32 +00:00
public 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]+/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
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/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
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]+/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2010-05-15 03:11:38 +00:00
$this -> Html -> request -> webroot = '/testing/' ;
2008-11-08 00:24:51 +00:00
$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]+/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-11-08 00:24:51 +00:00
2010-05-15 03:11:38 +00:00
$this -> Html -> request -> webroot = '/testing/longer/' ;
2008-11-08 00:24:51 +00:00
$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]+/' ;
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2012-02-08 04:14:56 +00:00
/**
* test use of css () and timestamping with plugin syntax
*
* @ return void
*/
public function testPluginCssTimestamping () {
CakePlugin :: load ( 'TestPlugin' );
Configure :: write ( 'debug' , 2 );
Configure :: write ( 'Asset.timestamp' , true );
$expected = array (
'link' => array ( 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => '' )
);
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/' ;
$this -> assertTags ( $result , $expected );
Configure :: write ( 'debug' , 0 );
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/' ;
$this -> assertTags ( $result , $expected );
Configure :: write ( 'Asset.timestamp' , 'force' );
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset' );
$expected [ 'link' ][ 'href' ] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/' ;
$this -> assertTags ( $result , $expected );
$this -> Html -> request -> webroot = '/testing/' ;
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset' );
$expected [ 'link' ][ 'href' ] = 'preg:/\/testing\/test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/' ;
$this -> assertTags ( $result , $expected );
$this -> Html -> request -> webroot = '/testing/longer/' ;
$result = $this -> Html -> css ( 'TestPlugin.test_plugin_asset' );
$expected [ 'link' ][ 'href' ] = 'preg:/\/testing\/longer\/test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/' ;
$this -> assertTags ( $result , $expected );
CakePlugin :: unload ( 'TestPlugin' );
}
2014-11-19 03:54:56 +00:00
/**
* Resource names must be treated differently for css () and script ()
*
* @ return void
*/
public function testBufferedCssAndScriptWithIdenticalResourceName () {
$this -> View -> expects ( $this -> at ( 0 ))
-> method ( 'append' )
-> with ( 'css' , $this -> stringContains ( 'test.min.css' ));
$this -> View -> expects ( $this -> at ( 1 ))
-> method ( 'append' )
-> with ( 'script' , $this -> stringContains ( 'test.min.js' ));
$this -> Html -> css ( 'test.min' , array ( 'inline' => false ));
$this -> Html -> script ( 'test.min' , array ( 'inline' => false ));
}
2009-03-12 23:51:30 +00:00
/**
* test timestamp enforcement for script tags .
*
* @ return void
2009-11-14 12:19:25 +00:00
*/
2011-05-30 20:02:32 +00:00
public function testScriptTimestamping () {
2013-08-31 06:15:59 +00:00
$this -> skipIf ( ! is_writable ( WWW_ROOT . 'js' ), 'webroot/js is not Writable, timestamp testing has been skipped.' );
2011-05-31 00:49:46 +00:00
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
2011-12-16 06:52:07 +00:00
touch ( WWW_ROOT . 'js' . DS . '__cake_js_test.js' );
2009-03-12 23:51:30 +00:00
$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 ));
2011-11-16 00:07:56 +00:00
$this -> assertRegExp ( '/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/' , $result , 'Timestamp value not found %s' );
2009-03-12 23:51:30 +00:00
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 ));
2011-11-16 00:07:56 +00:00
$this -> assertRegExp ( '/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/' , $result , 'Timestamp value not found %s' );
2011-12-16 06:52:07 +00:00
unlink ( WWW_ROOT . 'js' . DS . '__cake_js_test.js' );
2009-03-12 23:51:30 +00:00
Configure :: write ( 'Asset.timestamp' , false );
}
2009-09-03 17:45:39 +00:00
2012-02-08 04:14:56 +00:00
/**
* test timestamp enforcement for script tags with plugin syntax .
*
* @ return void
*/
public function testPluginScriptTimestamping () {
CakePlugin :: load ( 'TestPlugin' );
2014-06-24 09:52:29 +00:00
$pluginPath = CakePlugin :: path ( 'TestPlugin' );
2012-02-08 04:14:56 +00:00
$pluginJsPath = $pluginPath . 'webroot/js' ;
$this -> skipIf ( ! is_writable ( $pluginJsPath ), $pluginJsPath . ' is not Writable, timestamp testing has been skipped.' );
Configure :: write ( 'debug' , 2 );
Configure :: write ( 'Asset.timestamp' , true );
touch ( $pluginJsPath . DS . '__cake_js_test.js' );
$timestamp = substr ( strtotime ( 'now' ), 0 , 8 );
$result = $this -> Html -> script ( 'TestPlugin.__cake_js_test' , array ( 'inline' => true , 'once' => false ));
$this -> assertRegExp ( '/test_plugin\/js\/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/' , $result , 'Timestamp value not found %s' );
Configure :: write ( 'debug' , 0 );
Configure :: write ( 'Asset.timestamp' , 'force' );
$result = $this -> Html -> script ( 'TestPlugin.__cake_js_test' , array ( 'inline' => true , 'once' => false ));
$this -> assertRegExp ( '/test_plugin\/js\/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/' , $result , 'Timestamp value not found %s' );
unlink ( $pluginJsPath . DS . '__cake_js_test.js' );
Configure :: write ( 'Asset.timestamp' , false );
CakePlugin :: unload ( 'TestPlugin' );
}
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
2009-11-14 12:19:25 +00:00
*/
2011-05-30 20:02:32 +00:00
public function testScript () {
2009-03-12 23:51:30 +00:00
$result = $this -> Html -> script ( 'foo' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/foo.js' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-03-12 23:51:30 +00:00
$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' ,
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-03-12 23:51:30 +00:00
$result = $this -> Html -> script ( 'jquery-1.3' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/jquery-1.3.js' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-03-12 23:51:30 +00:00
2010-07-28 20:41:00 +00:00
$result = $this -> Html -> script ( 'test.json' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/test.json.js' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2010-07-28 20:41:00 +00:00
2011-07-26 02:14:29 +00:00
$result = $this -> Html -> script ( 'http://example.com/test.json' );
$expected = array (
2011-08-14 18:49:56 +00:00
'script' => array ( 'type' => 'text/javascript' , 'src' => 'http://example.com/test.json' )
2011-07-26 02:14:29 +00:00
);
$this -> assertTags ( $result , $expected );
2009-03-12 23:51:30 +00:00
$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' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-09-03 17:50:53 +00:00
2010-07-28 20:41:00 +00:00
$result = $this -> Html -> script ( 'test.json.js?foo=bar' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/test.json.js?foo=bar' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2010-07-28 20:41:00 +00:00
2012-04-10 01:20:03 +00:00
$result = $this -> Html -> script ( 'test.json.js?foo=bar&other=test' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'js/test.json.js?foo=bar&other=test' )
);
$this -> assertTags ( $result , $expected );
2013-05-28 02:48:59 +00:00
$result = $this -> Html -> script ( 'foo2' , array ( 'pathPrefix' => '/my/custom/path/' ));
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => '/my/custom/path/foo2.js' )
);
$this -> assertTags ( $result , $expected );
2017-06-10 21:33:55 +00:00
$result = $this -> Html -> script ( 'foo3' , array ( 'pathPrefix' => 'https://cakephp.org/assets/js/' ));
2013-05-28 02:48:59 +00:00
$expected = array (
2017-06-10 21:33:55 +00:00
'script' => array ( 'type' => 'text/javascript' , 'src' => 'https://cakephp.org/assets/js/foo3.js' )
2013-05-28 02:48:59 +00:00
);
$this -> assertTags ( $result , $expected );
2013-08-03 15:04:52 +00:00
$previousConfig = Configure :: read ( 'App.jsBaseUrl' );
Configure :: write ( 'App.jsBaseUrl' , '//cdn.cakephp.org/js/' );
$result = $this -> Html -> script ( 'foo4' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => '//cdn.cakephp.org/js/foo4.js' )
);
$this -> assertTags ( $result , $expected );
Configure :: write ( 'App.jsBaseUrl' , $previousConfig );
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' ));
2011-11-16 00:07:56 +00:00
$this -> assertNotRegExp ( '/foo.js/' , $result );
2009-03-12 23:51:30 +00:00
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' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2011-09-16 01:10:22 +00:00
}
2012-03-16 02:50:05 +00:00
/**
2012-02-08 04:14:56 +00:00
* test that plugin scripts added with uses () are only ever included once .
* test script tag generation with plugin syntax
*
* @ return void
*/
public function testPluginScript () {
CakePlugin :: load ( 'TestPlugin' );
$result = $this -> Html -> script ( 'TestPlugin.foo' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'test_plugin/js/foo.js' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( array ( 'TestPlugin.foobar' , 'TestPlugin.bar' ));
$expected = array (
array ( 'script' => array ( 'type' => 'text/javascript' , 'src' => 'test_plugin/js/foobar.js' )),
'/script' ,
array ( 'script' => array ( 'type' => 'text/javascript' , 'src' => 'test_plugin/js/bar.js' )),
'/script' ,
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( 'TestPlugin.jquery-1.3' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'test_plugin/js/jquery-1.3.js' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( 'TestPlugin.test.json' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'test_plugin/js/test.json.js' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( 'TestPlugin./jquery-1.3.2.js?someparam=foo' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'test_plugin/jquery-1.3.2.js?someparam=foo' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( 'TestPlugin.test.json.js?foo=bar' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'test_plugin/js/test.json.js?foo=bar' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( 'TestPlugin.foo' );
$this -> assertNull ( $result , 'Script returned upon duplicate inclusion %s' );
$result = $this -> Html -> script ( array ( 'TestPlugin.foo' , 'TestPlugin.bar' , 'TestPlugin.baz' ));
$this -> assertNotRegExp ( '/test_plugin\/js\/foo.js/' , $result );
$result = $this -> Html -> script ( 'TestPlugin.foo' , array ( 'inline' => true , 'once' => false ));
$this -> assertNotNull ( $result );
$result = $this -> Html -> script ( 'TestPlugin.jquery-1.3.2' , array ( 'defer' => true , 'encoding' => 'utf-8' ));
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'test_plugin/js/jquery-1.3.2.js' , 'defer' => 'defer' , 'encoding' => 'utf-8' )
);
$this -> assertTags ( $result , $expected );
CakePlugin :: unload ( 'TestPlugin' );
}
2011-09-16 01:10:22 +00:00
/**
* test that script () works with blocks .
*
* @ return void
*/
public function testScriptWithBlocks () {
$this -> View -> expects ( $this -> at ( 0 ))
2011-08-17 01:23:41 +00:00
-> method ( 'append' )
-> with ( 'script' , $this -> matchesRegularExpression ( '/script_in_head.js/' ));
2011-09-16 01:10:22 +00:00
$this -> View -> expects ( $this -> at ( 1 ))
-> method ( 'append' )
-> with ( 'script' , $this -> matchesRegularExpression ( '/bool_false.js/' ));
2012-02-01 13:37:46 +00:00
2011-09-16 01:10:22 +00:00
$this -> View -> expects ( $this -> at ( 2 ))
-> method ( 'append' )
-> with ( 'headScripts' , $this -> matchesRegularExpression ( '/second_script.js/' ));
2009-10-17 03:00:31 +00:00
$result = $this -> Html -> script ( 'script_in_head' , array ( 'inline' => false ));
$this -> assertNull ( $result );
2011-09-16 01:10:22 +00:00
$result = $this -> Html -> script ( 'bool_false' , false );
$this -> assertNull ( $result );
$result = $this -> Html -> script ( 'second_script' , array ( 'block' => 'headScripts' ));
$this -> assertNull ( $result );
2009-03-12 23:51:30 +00:00
}
2009-09-24 04:28:27 +00:00
2011-11-25 02:01:53 +00:00
/**
* Test that Asset . filter . js works .
*
* @ return void
*/
2012-02-17 07:13:12 +00:00
public function testScriptAssetFilter () {
2011-11-25 02:01:53 +00:00
Configure :: write ( 'Asset.filter.js' , 'js.php' );
2011-12-05 01:25:58 +00:00
2011-11-25 02:01:53 +00:00
$result = $this -> Html -> script ( 'jquery-1.3' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => 'cjs/jquery-1.3.js' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( '//example.com/js/jquery-1.3.js' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => '//example.com/js/jquery-1.3.js' )
);
$this -> assertTags ( $result , $expected );
}
2013-03-29 14:24:08 +00:00
/**
* testScriptWithFullBase method
*
* @ return void
*/
public function testScriptWithFullBase () {
$here = $this -> Html -> url ( '/' , true );
$result = $this -> Html -> script ( 'foo' , array ( 'fullBase' => true ));
$expected = array (
'script' => array ( 'type' => 'text/javascript' , 'src' => $here . 'js/foo.js' )
);
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> script ( array ( 'foobar' , 'bar' ), array ( 'fullBase' => true ));
$expected = array (
array ( 'script' => array ( 'type' => 'text/javascript' , 'src' => $here . 'js/foobar.js' )),
'/script' ,
array ( 'script' => array ( 'type' => 'text/javascript' , 'src' => $here . 'js/bar.js' )),
'/script' ,
);
$this -> assertTags ( $result , $expected );
}
2010-09-01 01:21:05 +00:00
/**
* test a script file in the webroot / theme dir .
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testScriptInTheme () {
2011-12-03 20:00:06 +00:00
$this -> skipIf ( ! is_writable ( WWW_ROOT ), 'Cannot write to webroot.' );
$themeExists = is_dir ( WWW_ROOT . 'theme' );
2011-05-31 00:49:46 +00:00
2010-12-10 06:23:27 +00:00
App :: uses ( 'File' , 'Utility' );
2010-09-01 01:21:05 +00:00
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'js' . DS . '__test_js.js' ;
2013-01-23 12:45:50 +00:00
new File ( $testfile , true );
2010-09-01 01:21:05 +00:00
App :: build ( array (
2012-03-16 02:50:05 +00:00
'View' => array ( CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS )
2010-09-01 01:21:05 +00:00
));
$this -> Html -> webroot = '/' ;
$this -> Html -> theme = 'test_theme' ;
$result = $this -> Html -> script ( '__test_js.js' );
$expected = array (
'script' => array ( 'src' => '/theme/test_theme/js/__test_js.js' , 'type' => 'text/javascript' )
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2010-09-19 04:43:56 +00:00
2011-10-20 23:10:09 +00:00
$Folder = new Folder ( WWW_ROOT . 'theme' . DS . 'test_theme' );
$Folder -> delete ();
2011-12-03 20:00:06 +00:00
if ( ! $themeExists ) {
$dir = new Folder ( WWW_ROOT . 'theme' );
$dir -> delete ();
}
2010-09-01 01:21:05 +00:00
}
2009-03-13 02:59:55 +00:00
/**
* test Script block generation
*
* @ return void
2009-11-14 12:19:25 +00:00
*/
2011-05-30 20:02:32 +00:00
public function testScriptBlock () {
2009-03-13 02:59:55 +00:00
$result = $this -> Html -> scriptBlock ( 'window.foo = 2;' );
$expected = array (
'script' => array ( 'type' => 'text/javascript' ),
$this -> cDataStart ,
'window.foo = 2;' ,
$this -> cDataEnd ,
'/script' ,
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-09-03 17:50:53 +00:00
2013-05-18 18:25:19 +00:00
$result = $this -> Html -> scriptBlock ( 'window.foo = 2;' , array ( 'type' => 'text/x-handlebars-template' ));
$expected = array (
'script' => array ( 'type' => 'text/x-handlebars-template' ),
$this -> cDataStart ,
'window.foo = 2;' ,
$this -> cDataEnd ,
'/script' ,
);
$this -> assertTags ( $result , $expected );
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' ,
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-03-13 02:59:55 +00:00
$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' ,
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-09-03 17:50:53 +00:00
2012-02-01 03:20:21 +00:00
$this -> View -> expects ( $this -> at ( 0 ))
2011-08-17 01:23:41 +00:00
-> method ( 'append' )
-> with ( 'script' , $this -> matchesRegularExpression ( '/window\.foo\s\=\s2;/' ));
2009-09-03 17:50:53 +00:00
2012-02-01 03:20:21 +00:00
$this -> View -> expects ( $this -> at ( 1 ))
-> method ( 'append' )
-> with ( 'scriptTop' , $this -> stringContains ( 'alert(' ));
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
2012-02-01 03:20:21 +00:00
$result = $this -> Html -> scriptBlock ( 'alert("hi")' , array ( 'block' => 'scriptTop' ));
$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' ,
);
2011-05-17 04:36:22 +00:00
$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
2009-11-14 12:19:25 +00:00
*/
2011-05-30 20:02:32 +00:00
public function testScriptStartAndScriptEnd () {
2009-07-25 19:43:26 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-07-25 19:43:26 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2009-07-25 19:43:26 +00:00
2013-05-18 18:37:26 +00:00
$result = $this -> Html -> scriptStart ( array ( 'safe' => true , 'type' => 'text/x-handlebars-template' ));
$this -> assertNull ( $result );
echo 'this is some template' ;
$result = $this -> Html -> scriptEnd ();
$expected = array (
'script' => array ( 'type' => 'text/x-handlebars-template' ),
$this -> cDataStart ,
'this is some template' ,
$this -> cDataEnd ,
'/script'
);
$this -> assertTags ( $result , $expected );
2011-08-17 01:23:41 +00:00
$this -> View -> expects ( $this -> once ())
-> method ( 'append' );
2009-07-25 19:43:26 +00:00
$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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testCharsetTag () {
2008-05-30 11:40:08 +00:00
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
/**
2012-01-14 18:14:26 +00:00
* testGetCrumb and addCrumb method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testBreadcrumb () {
2011-09-07 23:59:39 +00:00
$this -> assertNull ( $this -> Html -> getCrumbs ());
2011-10-28 05:01:17 +00:00
2008-05-30 11:40:08 +00:00
$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' ,
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$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' ,
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2011-09-07 23:59:39 +00:00
$result = $this -> Html -> getCrumbs ( '-' , 'Start' );
$expected = array (
array ( 'a' => array ( 'href' => '/' )),
'Start' ,
'/a' ,
'-' ,
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 );
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2012-01-14 18:14:26 +00:00
/**
* Test the array form of $startText
2014-04-02 01:02:37 +00:00
*
* @ return void
2012-01-14 18:14:26 +00:00
*/
public function testGetCrumbFirstLink () {
2012-03-18 03:23:42 +00:00
$result = $this -> Html -> getCrumbList ( null , 'Home' );
$this -> assertTags (
$result ,
array (
'<ul' ,
array ( 'li' => array ( 'class' => 'first' )),
array ( 'a' => array ( 'href' => '/' )), 'Home' , '/a' ,
'/li' ,
'/ul'
)
);
2012-01-14 18:14:26 +00:00
$this -> Html -> addCrumb ( 'First' , '#first' );
$this -> Html -> addCrumb ( 'Second' , '#second' );
$result = $this -> Html -> getCrumbs ( ' - ' , array ( 'url' => '/home' , 'text' => '<img src="/home.png" />' , 'escape' => false ));
$expected = array (
array ( 'a' => array ( 'href' => '/home' )),
'img' => array ( 'src' => '/home.png' ),
'/a' ,
' - ' ,
array ( 'a' => array ( 'href' => '#first' )),
'First' ,
'/a' ,
' - ' ,
array ( 'a' => array ( 'href' => '#second' )),
'Second' ,
'/a' ,
);
$this -> assertTags ( $result , $expected );
}
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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testNestedList () {
2008-05-30 11:40:08 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> nestedList ( $list , null );
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> nestedList ( $list , 'ol' );
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2011-12-01 07:21:31 +00:00
$result = $this -> Html -> nestedList ( $list , array ( 'class' => 'list' ));
2008-05-30 11:40:08 +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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2011-12-01 07:21:31 +00:00
$result = $this -> Html -> nestedList ( $list , array ( 'class' => 'list' ), array ( 'class' => 'item' ));
2008-05-30 11:40:08 +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'
);
2011-05-17 04:36:22 +00:00
$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
/**
* testMeta method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testMeta () {
2008-05-30 11:40:08 +00:00
$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' ))
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
2013-11-09 19:30:19 +00:00
$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' )));
}
/**
* Test generating favicon ' s with meta ()
*
* @ return void
*/
public function testMetaIcon () {
2008-05-30 11:40:08 +00:00
$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' ))
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2013-11-09 19:30:19 +00:00
2011-09-07 23:59:39 +00:00
$result = $this -> Html -> meta ( 'icon' );
$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 );
2008-05-30 11:40:08 +00:00
2013-11-09 19:30:19 +00:00
$result = $this -> Html -> meta ( 'icon' , '/favicon.png?one=two&three=four' );
$url = '/favicon.png?one=two&three=four' ;
$expected = array (
'link' => array (
'href' => $url ,
'type' => 'image/x-icon' ,
'rel' => 'icon'
),
array (
'link' => array (
'href' => $url ,
'type' => 'image/x-icon' ,
'rel' => 'shortcut icon'
)
)
);
$this -> assertTags ( $result , $expected );
2013-11-19 01:38:01 +00:00
$this -> Html -> request -> webroot = '/testing/' ;
$result = $this -> Html -> meta ( 'icon' );
$expected = array (
'link' => array ( 'href' => '/testing/favicon.ico' , 'type' => 'image/x-icon' , 'rel' => 'icon' ),
array ( 'link' => array ( 'href' => '/testing/favicon.ico' , 'type' => 'image/x-icon' , 'rel' => 'shortcut icon' ))
);
$this -> assertTags ( $result , $expected );
2011-09-16 01:10:22 +00:00
}
/**
* Test the inline and block options for meta ()
2014-04-02 01:02:37 +00:00
*
* @ return void
2011-09-16 01:10:22 +00:00
*/
public function testMetaWithBlocks () {
$this -> View -> expects ( $this -> at ( 0 ))
2011-08-17 01:23:41 +00:00
-> method ( 'append' )
2011-09-16 01:10:22 +00:00
-> with ( 'meta' , $this -> stringContains ( 'ROBOTS' ));
$this -> View -> expects ( $this -> at ( 1 ))
-> method ( 'append' )
-> with ( 'metaTags' , $this -> stringContains ( 'favicon.ico' ));
2010-07-15 03:03:30 +00:00
$result = $this -> Html -> meta ( array ( 'name' => 'ROBOTS' , 'content' => 'ALL' ), null , array ( 'inline' => false ));
$this -> assertNull ( $result );
2011-09-16 01:10:22 +00:00
$result = $this -> Html -> meta ( 'icon' , 'favicon.ico' , array ( 'block' => 'metaTags' ));
$this -> assertNull ( $result );
2008-05-30 11:40:08 +00:00
}
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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testTableHeaders () {
2008-05-30 11:40:08 +00:00
$result = $this -> Html -> tableHeaders ( array ( 'ID' , 'Name' , 'Date' ));
$expected = array ( '<tr' , '<th' , 'ID' , '/th' , '<th' , 'Name' , '/th' , '<th' , 'Date' , '/th' , '/tr' );
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2012-05-30 02:30:06 +00:00
$result = $this -> Html -> tableHeaders ( array ( 'ID' , array ( 'Name' => array ( 'class' => 'highlight' )), 'Date' ));
$expected = array ( '<tr' , '<th' , 'ID' , '/th' , '<th class="highlight"' , 'Name' , '/th' , '<th' , 'Date' , '/th' , '/tr' );
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> tableHeaders ( array ( 'ID' , array ( 'Name' => array ( 'class' => 'highlight' , 'width' => '120px' )), 'Date' ));
$expected = array ( '<tr' , '<th' , 'ID' , '/th' , '<th class="highlight" width="120px"' , 'Name' , '/th' , '<th' , 'Date' , '/th' , '/tr' );
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> tableHeaders ( array ( 'ID' , array ( 'Name' => array ()), 'Date' ));
$expected = array ( '<tr' , '<th' , 'ID' , '/th' , '<th' , 'Name' , '/th' , '<th' , 'Date' , '/th' , '/tr' );
$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
/**
* testTableCells method
2008-11-08 00:24:51 +00:00
*
2008-06-02 19:22:55 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testTableCells () {
2008-05-30 11:40:08 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
$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'
);
2011-05-17 04:36:22 +00:00
$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> " ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
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> " ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
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> " ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2015-05-02 14:52:51 +00:00
$tr = array (
'td content 1' ,
'td content 2' ,
array ( 'td content 3' , array ( 'class' => 'foo' ))
);
$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' => 'foo column-3' )), 'td content 3' , '/td' ,
'/tr'
);
$this -> assertTags ( $result , $expected );
2008-05-30 11:40:08 +00:00
}
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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testTag () {
2008-06-20 20:17:23 +00:00
$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' );
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' ));
2013-05-20 04:00:27 +00:00
$result = $this -> Html -> tag ( false , '<em>stuff</em>' );
2013-09-25 20:07:52 +00:00
$this -> assertEquals ( '<em>stuff</em>' , $result );
2013-05-20 23:36:51 +00:00
$result = $this -> Html -> tag ( null , '<em>stuff</em>' );
2013-09-25 20:07:52 +00:00
$this -> assertEquals ( '<em>stuff</em>' , $result );
2013-05-20 23:36:51 +00:00
$result = $this -> Html -> tag ( '' , '<em>stuff</em>' );
2013-09-25 20:07:52 +00:00
$this -> assertEquals ( '<em>stuff</em>' , $result );
2008-06-20 20:17:23 +00:00
}
2009-07-24 19:18:37 +00:00
2011-01-23 14:25:52 +00:00
/**
* testUseTag method
*
* @ return void
*/
public function testUseTag () {
2011-09-07 23:59:39 +00:00
$result = $this -> Html -> useTag ( 'unknowntag' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( '' , $result );
2011-09-07 23:59:39 +00:00
2011-01-23 14:25:52 +00:00
$result = $this -> Html -> useTag ( 'formend' );
$this -> assertTags ( $result , '/form' );
2011-06-26 00:00:39 +00:00
$result = $this -> Html -> useTag ( 'form' , 'url' , ' test' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( '<form action="url" test>' , $result );
2011-01-23 14:25:52 +00:00
2011-06-26 00:00:39 +00:00
$result = $this -> Html -> useTag ( 'form' , 'example.com' , array ( 'test' => 'ok' ));
$this -> assertTags ( $result , array ( 'form' => array ( 'test' => 'ok' , 'action' => 'example.com' )));
2011-01-23 14:25:52 +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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testDiv () {
2008-05-30 11:40:08 +00:00
$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' ));
2009-10-17 03:11:13 +00:00
$result = $this -> Html -> div ( 'class-name' , '<text>' , array ( 'escape' => true ));
2008-05-30 11:40:08 +00:00
$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
* @ return void
*/
2011-05-30 20:02:32 +00:00
public 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' ));
2009-10-17 03:14:42 +00:00
$result = $this -> Html -> para ( 'class-name' , '<text>' , array ( 'escape' => true ));
2008-05-30 11:40:08 +00:00
$this -> assertTags ( $result , array ( 'p' => array ( 'class' => 'class-name' ), '<text>' , '/p' ));
}
2011-04-17 16:03:43 +00:00
2012-02-05 14:49:12 +00:00
/**
2012-02-06 13:27:16 +00:00
* testMedia method
2012-02-05 14:49:12 +00:00
*
* @ return void
*/
2012-02-06 13:27:16 +00:00
public function testMedia () {
$result = $this -> Html -> media ( 'video.webm' );
$expected = array ( 'video' => array ( 'src' => 'files/video.webm' ), '/video' );
2012-02-05 14:49:12 +00:00
$this -> assertTags ( $result , $expected );
2012-02-06 13:27:16 +00:00
$result = $this -> Html -> media ( 'video.webm' , array (
2012-02-05 14:49:12 +00:00
'text' => 'Your browser does not support the HTML5 Video element.'
));
$expected = array ( 'video' => array ( 'src' => 'files/video.webm' ), 'Your browser does not support the HTML5 Video element.' , '/video' );
$this -> assertTags ( $result , $expected );
2012-02-06 13:27:16 +00:00
$result = $this -> Html -> media ( 'video.webm' , array ( 'autoload' , 'muted' => 'muted' ));
$expected = array (
'video' => array (
'src' => 'files/video.webm' ,
'autoload' => 'autoload' ,
'muted' => 'muted'
),
'/video'
);
2012-02-05 14:49:12 +00:00
$this -> assertTags ( $result , $expected );
2012-02-06 13:27:16 +00:00
$result = $this -> Html -> media (
2012-02-05 14:49:12 +00:00
array ( 'video.webm' , array ( 'src' => 'video.ogv' , 'type' => " video/ogg; codecs='theora, vorbis' " )),
array ( 'pathPrefix' => 'videos/' , 'poster' => 'poster.jpg' , 'text' => 'Your browser does not support the HTML5 Video element.' )
);
$expected = array (
2013-07-31 14:36:57 +00:00
'video' => array ( 'poster' => Configure :: read ( 'App.imageBaseUrl' ) . 'poster.jpg' ),
2012-02-05 14:49:12 +00:00
array ( 'source' => array ( 'src' => 'videos/video.webm' , 'type' => 'video/webm' )),
array ( 'source' => array ( 'src' => 'videos/video.ogv' , 'type' => 'video/ogg; codecs='theora, vorbis'' )),
'Your browser does not support the HTML5 Video element.' ,
'/video'
);
$this -> assertTags ( $result , $expected );
2012-02-06 13:27:16 +00:00
2012-02-10 14:14:55 +00:00
$result = $this -> Html -> media ( 'video.ogv' , array ( 'tag' => 'video' ));
2012-02-06 13:27:16 +00:00
$expected = array ( 'video' => array ( 'src' => 'files/video.ogv' ), '/video' );
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> media ( 'audio.mp3' );
$expected = array ( 'audio' => array ( 'src' => 'files/audio.mp3' ), '/audio' );
$this -> assertTags ( $result , $expected );
$result = $this -> Html -> media (
array ( array ( 'src' => 'video.mov' , 'type' => 'video/mp4' ), 'video.webm' )
);
$expected = array (
'<video' ,
array ( 'source' => array ( 'src' => 'files/video.mov' , 'type' => 'video/mp4' )),
array ( 'source' => array ( 'src' => 'files/video.webm' , 'type' => 'video/webm' )),
'/video'
);
$this -> assertTags ( $result , $expected );
2012-02-10 07:36:55 +00:00
$result = $this -> Html -> media ( null , array ( 'src' => 'video.webm' ));
$expected = array (
'video' => array ( 'src' => 'files/video.webm' ),
'/video'
);
$this -> assertTags ( $result , $expected );
2012-02-05 14:49:12 +00:00
}
2010-06-27 16:07:19 +00:00
/**
* testCrumbList method
2011-04-17 16:03:43 +00:00
*
2010-06-27 16:07:19 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testCrumbList () {
2011-09-07 23:59:39 +00:00
$this -> assertNull ( $this -> Html -> getCrumbList ());
2010-06-29 02:53:33 +00:00
$this -> Html -> addCrumb ( 'Home' , '/' , array ( 'class' => 'home' ));
$this -> Html -> addCrumb ( 'Some page' , '/some_page' );
$this -> Html -> addCrumb ( 'Another page' );
$result = $this -> Html -> getCrumbList (
array ( 'class' => 'breadcrumbs' )
);
$this -> assertTags (
$result ,
array (
array ( 'ul' => array ( 'class' => 'breadcrumbs' )),
array ( 'li' => array ( 'class' => 'first' )),
array ( 'a' => array ( 'class' => 'home' , 'href' => '/' )), 'Home' , '/a' ,
'/li' ,
'<li' ,
array ( 'a' => array ( 'href' => '/some_page' )), 'Some page' , '/a' ,
'/li' ,
array ( 'li' => array ( 'class' => 'last' )),
'Another page' ,
'/li' ,
'/ul'
)
);
2010-06-27 16:07:19 +00:00
}
2011-01-23 14:36:14 +00:00
2012-02-17 02:27:41 +00:00
/**
* Test getCrumbList startText
2014-04-02 01:02:37 +00:00
*
* @ return void
2012-02-17 02:27:41 +00:00
*/
2012-03-16 02:50:05 +00:00
public function testCrumbListFirstLink () {
$this -> Html -> addCrumb ( 'First' , '#first' );
$this -> Html -> addCrumb ( 'Second' , '#second' );
$result = $this -> Html -> getCrumbList ( null , 'Home' );
$this -> assertTags (
$result ,
array (
'<ul' ,
array ( 'li' => array ( 'class' => 'first' )),
array ( 'a' => array ( 'href' => '/' )), 'Home' , '/a' ,
'/li' ,
'<li' ,
array ( 'a' => array ( 'href' => '#first' )), 'First' , '/a' ,
'/li' ,
array ( 'li' => array ( 'class' => 'last' )),
array ( 'a' => array ( 'href' => '#second' )), 'Second' , '/a' ,
'/li' ,
'/ul'
)
);
$result = $this -> Html -> getCrumbList ( null , array ( 'url' => '/home' , 'text' => '<img src="/home.png" />' , 'escape' => false ));
$this -> assertTags (
$result ,
array (
'<ul' ,
array ( 'li' => array ( 'class' => 'first' )),
array ( 'a' => array ( 'href' => '/home' )), 'img' => array ( 'src' => '/home.png' ), '/a' ,
'/li' ,
'<li' ,
array ( 'a' => array ( 'href' => '#first' )), 'First' , '/a' ,
'/li' ,
array ( 'li' => array ( 'class' => 'last' )),
array ( 'a' => array ( 'href' => '#second' )), 'Second' , '/a' ,
'/li' ,
'/ul'
)
);
}
2012-02-17 02:27:41 +00:00
2012-11-14 01:19:29 +00:00
/**
* test getCrumbList () in Twitter Bootstrap style .
*
* @ return void
*/
public function testCrumbListBootstrapStyle () {
2012-11-17 19:51:57 +00:00
$this -> Html -> addCrumb ( 'Home' , '/' , array ( 'class' => 'home' ));
2012-11-14 01:19:29 +00:00
$this -> Html -> addCrumb ( 'Library' , '/lib' );
$this -> Html -> addCrumb ( 'Data' );
2012-11-17 19:51:57 +00:00
$result = $this -> Html -> getCrumbList ( array (
'class' => 'breadcrumb' ,
'separator' => '<span class="divider">-</span>' ,
'firstClass' => false ,
'lastClass' => 'active'
));
2012-11-14 01:19:29 +00:00
$this -> assertTags (
$result ,
array (
array ( 'ul' => array ( 'class' => 'breadcrumb' )),
'<li' ,
2012-11-17 19:51:57 +00:00
array ( 'a' => array ( 'class' => 'home' , 'href' => '/' )), 'Home' , '/a' ,
2012-11-21 14:39:03 +00:00
array ( 'span' => array ( 'class' => 'divider' )), '-' , '/span' ,
2012-11-14 01:19:29 +00:00
'/li' ,
'<li' ,
array ( 'a' => array ( 'href' => '/lib' )), 'Library' , '/a' ,
2012-11-17 19:51:57 +00:00
array ( 'span' => array ( 'class' => 'divider' )), '-' , '/span' ,
2012-11-14 01:19:29 +00:00
'/li' ,
2012-11-16 01:15:49 +00:00
array ( 'li' => array ( 'class' => 'active' )), 'Data' , '/li' ,
2012-11-14 01:19:29 +00:00
'/ul'
2012-11-17 19:51:57 +00:00
)
2012-11-14 01:19:29 +00:00
);
}
/**
* Test GetCrumbList using style of Zurb Foundation .
2012-11-21 14:39:03 +00:00
*
2012-11-14 01:19:29 +00:00
* @ return void
*/
public function testCrumbListZurbStyle () {
$this -> Html -> addCrumb ( 'Home' , '#' );
$this -> Html -> addCrumb ( 'Features' , '#' );
2012-11-21 14:39:03 +00:00
$this -> Html -> addCrumb ( 'Gene Splicing' , '#' );
$this -> Html -> addCrumb ( 'Home' , '#' );
2012-11-14 01:19:29 +00:00
$result = $this -> Html -> getCrumbList (
2012-11-16 11:39:13 +00:00
array ( 'class' => 'breadcrumbs' , 'firstClass' => false , 'lastClass' => 'current' )
2012-11-14 01:19:29 +00:00
);
$this -> assertTags (
$result ,
array (
array ( 'ul' => array ( 'class' => 'breadcrumbs' )),
'<li' ,
array ( 'a' => array ( 'href' => '#' )), 'Home' , '/a' ,
'/li' ,
'<li' ,
array ( 'a' => array ( 'href' => '#' )), 'Features' , '/a' ,
'/li' ,
'<li' ,
array ( 'a' => array ( 'href' => '#' )), 'Gene Splicing' , '/a' ,
'/li' ,
array ( 'li' => array ( 'class' => 'current' )),
array ( 'a' => array ( 'href' => '#' )), 'Home' , '/a' ,
'/li' ,
'/ul'
), true
);
}
2011-01-23 21:27:50 +00:00
/**
* testLoadConfig method
*
* @ return void
*/
public function testLoadConfig () {
2012-03-16 02:50:05 +00:00
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS ;
2011-01-23 21:27:50 +00:00
$result = $this -> Html -> loadConfig ( 'htmlhelper_tags' , $path );
$expected = array (
'tags' => array (
'form' => 'start form' ,
2012-09-03 14:04:19 +00:00
'formend' => 'finish form' ,
'hiddenblock' => '<div class="hidden">%s</div>'
2011-01-23 21:27:50 +00:00
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2011-01-23 21:27:50 +00:00
$tags = $this -> Html -> getAttribute ( '_tags' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'start form' , $tags [ 'form' ]);
$this -> assertEquals ( 'finish form' , $tags [ 'formend' ]);
$this -> assertEquals ( '</select>' , $tags [ 'selectend' ]);
2011-01-23 21:27:50 +00:00
$result = $this -> Html -> loadConfig ( array ( 'htmlhelper_minimized.ini' , 'ini' ), $path );
$expected = array (
'minimizedAttributeFormat' => 'format'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'format' , $this -> Html -> getAttribute ( '_minimizedAttributeFormat' ));
2011-01-25 03:18:39 +00:00
}
2011-01-23 21:27:50 +00:00
2011-01-25 03:18:39 +00:00
/**
* testLoadConfigWrongFile method
*
* @ return void
* @ expectedException ConfigureException
*/
public function testLoadConfigWrongFile () {
2013-01-23 12:45:50 +00:00
$this -> Html -> loadConfig ( 'wrong_file' );
2011-01-25 03:18:39 +00:00
}
2011-01-23 21:27:50 +00:00
2011-01-25 03:18:39 +00:00
/**
* testLoadConfigWrongReader method
*
* @ return void
* @ expectedException ConfigureException
*/
public function testLoadConfigWrongReader () {
2012-03-16 02:50:05 +00:00
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS ;
2013-01-23 12:45:50 +00:00
$this -> Html -> loadConfig ( array ( 'htmlhelper_tags' , 'wrong_reader' ), $path );
2011-01-23 21:27:50 +00:00
}
2011-01-23 14:36:14 +00:00
/**
* test parsing attributes .
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testParseAttributeCompact () {
2011-01-23 14:36:14 +00:00
$helper = new TestHtmlHelper ( $this -> View );
$compact = array ( 'compact' , 'checked' , 'declare' , 'readonly' , 'disabled' ,
'selected' , 'defer' , 'ismap' , 'nohref' , 'noshade' , 'nowrap' , 'multiple' , 'noresize' );
2011-04-17 16:03:43 +00:00
2011-01-23 14:36:14 +00:00
foreach ( $compact as $attribute ) {
foreach ( array ( 'true' , true , 1 , '1' , $attribute ) as $value ) {
$attrs = array ( $attribute => $value );
$expected = ' ' . $attribute . '="' . $attribute . '"' ;
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $helper -> parseAttributes ( $attrs ), '%s Failed on ' . $value );
2011-01-23 14:36:14 +00:00
}
}
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( ' compact="compact"' , $helper -> parseAttributes ( array ( 'compact' )));
2011-01-23 14:36:14 +00:00
2012-01-04 02:07:22 +00:00
$attrs = array ( 'class' => array ( 'foo' , 'bar' ));
$expected = ' class="foo bar"' ;
$this -> assertEquals ( ' class="foo bar"' , $helper -> parseAttributes ( $attrs ));
2011-01-23 14:36:14 +00:00
$helper = new Html5TestHelper ( $this -> View );
$expected = ' require' ;
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $helper -> parseAttributes ( array ( 'require' )));
$this -> assertEquals ( $expected , $helper -> parseAttributes ( array ( 'require' => true )));
$this -> assertEquals ( '' , $helper -> parseAttributes ( array ( 'require' => false )));
2011-01-23 14:36:14 +00:00
}
2012-11-17 19:51:57 +00:00
}