| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019 |
- <?php
- /**
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @since 1.2.0
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\View\Helper;
- use Cake\Controller\Controller;
- use Cake\Core\App;
- use Cake\Core\Configure;
- use Cake\Core\Plugin;
- use Cake\Model\Model;
- use Cake\Network\Request;
- use Cake\Routing\Router;
- use Cake\TestSuite\TestCase;
- use Cake\Utility\ClassRegistry;
- use Cake\Utility\File;
- use Cake\Utility\Folder;
- use Cake\View\Helper\FormHelper;
- use Cake\View\Helper\HtmlHelper;
- use Cake\View\View;
- /**
- * HtmlHelperTest class
- *
- */
- class HtmlHelperTest extends TestCase {
- /**
- * Regexp for CDATA start block
- *
- * @var string
- */
- public $cDataStart = 'preg:/^\/\/<!\[CDATA\[[\n\r]*/';
- /**
- * Regexp for CDATA end block
- *
- * @var string
- */
- public $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/';
- /**
- * html property
- *
- * @var object
- */
- public $Html = null;
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- $controller = $this->getMock('Cake\Controller\Controller');
- $this->View = $this->getMock('Cake\View\View', array('append'));
- $this->Html = new HtmlHelper($this->View);
- $this->Html->request = new Request();
- $this->Html->request->webroot = '';
- $this->Html->Url->request = $this->Html->request;
- Configure::write('App.namespace', 'TestApp');
- Plugin::load(['TestTheme']);
- Configure::write('Asset.timestamp', false);
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- Plugin::unload('TestTheme');
- unset($this->Html, $this->View);
- }
- /**
- * testDocType method
- *
- * @return void
- */
- public function testDocType() {
- $result = $this->Html->docType();
- $expected = '<!DOCTYPE html>';
- $this->assertEquals($expected, $result);
- $result = $this->Html->docType('html4-strict');
- $expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
- $this->assertEquals($expected, $result);
- $this->assertNull($this->Html->docType('non-existing-doctype'));
- }
- /**
- * testLink method
- *
- * @return void
- */
- public function testLink() {
- Router::connect('/:controller/:action/*');
- $this->Html->request->webroot = '';
- $result = $this->Html->link('/home');
- $expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
- $this->assertHtml($expected, $result);
- $result = $this->Html->link(array('action' => 'login', '<[You]>'));
- $expected = array(
- 'a' => array('href' => '/login/%3C%5BYou%5D%3E'),
- 'preg:/\/login\/<\[You\]>/',
- '/a'
- );
- $this->assertHtml($expected, $result);
- Router::reload();
- Router::connect('/:controller', array('action' => 'index'));
- Router::connect('/:controller/:action/*');
- $result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', '_full' => true));
- $expected = array('a' => array('href' => Router::fullBaseUrl() . '/posts'), 'Posts', '/a');
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
- $expected = array(
- 'a' => array('href' => '/home', 'onclick' => 'if (confirm("Are you sure you want to do this?")) { return true; } return false;'),
- 'Home',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $result = $this->Html->link('Home', '/home', array('onclick' => 'someFunction();'));
- $expected = array(
- 'a' => array('href' => '/home', 'onclick' => 'someFunction();'),
- 'Home',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Next >', '#');
- $expected = array(
- 'a' => array('href' => '#'),
- 'Next >',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Next >', '#', array('escape' => true));
- $expected = array(
- 'a' => array('href' => '#'),
- 'Next >',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Next >', '#', array('escape' => 'utf-8'));
- $expected = array(
- 'a' => array('href' => '#'),
- 'Next >',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Next >', '#', array('escape' => false));
- $expected = array(
- 'a' => array('href' => '#'),
- 'Next >',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Next >', '#', array(
- 'title' => 'to escape … or not escape?',
- 'escape' => false
- ));
- $expected = array(
- 'a' => array('href' => '#', 'title' => 'to escape … or not escape?'),
- 'Next >',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Next >', '#', array(
- 'title' => 'to escape … or not escape?',
- 'escape' => true
- ));
- $expected = array(
- 'a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'),
- 'Next >',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Next >', '#', array(
- 'title' => 'Next >',
- 'escapeTitle' => false
- ));
- $expected = array(
- 'a' => array('href' => '#', 'title' => 'Next >'),
- 'Next >',
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('Original size', array(
- 'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
- ));
- $expected = array(
- 'a' => array('href' => '/images/view/3?height=100&width=200'),
- 'Original size',
- '/a'
- );
- $this->assertHtml($expected, $result);
- Configure::write('Asset.timestamp', false);
- $result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false));
- $expected = array(
- 'a' => array('href' => '#'),
- 'img' => array('src' => 'img/test.gif', 'alt' => ''),
- '/a'
- );
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $result = $this->Html->image('test.gif', array('url' => '#'));
- $expected = array(
- 'a' => array('href' => '#'),
- 'img' => array('src' => 'img/test.gif', 'alt' => ''),
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->link($this->Html->image('../favicon.ico'), '#', array('escape' => false));
- $expected = array(
- 'a' => array('href' => '#'),
- 'img' => array('src' => 'img/../favicon.ico', 'alt' => ''),
- '/a'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->image('../favicon.ico', array('url' => '#'));
- $expected = array(
- 'a' => array('href' => '#'),
- 'img' => array('src' => 'img/../favicon.ico', 'alt' => ''),
- '/a'
- );
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $result = $this->Html->link('alert', 'javascript:alert(\'cakephp\');');
- $expected = array('a' => array('href' => 'javascript:alert('cakephp');'), 'alert', '/a');
- $this->assertHtml($expected, $result);
- $result = $this->Html->link('write me', 'mailto:example@cakephp.org');
- $expected = array('a' => array('href' => 'mailto:example@cakephp.org'), 'write me', '/a');
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- }
- /**
- * testImageTag method
- *
- * @return void
- */
- public function testImageTag() {
- Router::connect('/:controller', array('action' => 'index'));
- Router::connect('/:controller/:action/*');
- $this->Html->request->webroot = '';
- $result = $this->Html->image('test.gif');
- $expected = array('img' => array('src' => 'img/test.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $result = $this->Html->image('http://google.com/logo.gif');
- $expected = array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $result = $this->Html->image('//google.com/logo.gif');
- $expected = array('img' => array('src' => '//google.com/logo.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, '_ext' => 'gif'));
- $expected = array('img' => array('src' => '/test/view/1.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $result = $this->Html->image('/test/view/1.gif');
- $expected = array('img' => array('src' => '/test/view/1.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- }
- /**
- * Test image() with query strings.
- *
- * @return void
- */
- public function testImageQueryString() {
- $result = $this->Html->image('test.gif?one=two&three=four');
- $expected = array('img' => array('src' => 'img/test.gif?one=two&three=four', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $result = $this->Html->image(array(
- 'controller' => 'images',
- 'action' => 'display',
- 'test',
- '?' => array('one' => 'two', 'three' => 'four')
- ));
- $expected = array('img' => array('src' => '/images/display/test?one=two&three=four', 'alt' => ''));
- $this->assertHtml($expected, $result);
- }
- /**
- * Test that image works with pathPrefix.
- *
- * @return void
- */
- public function testImagePathPrefix() {
- $result = $this->Html->image('test.gif', array('pathPrefix' => '/my/custom/path/'));
- $expected = array('img' => array('src' => '/my/custom/path/test.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $result = $this->Html->image('test.gif', array('pathPrefix' => 'http://cakephp.org/assets/img/'));
- $expected = array('img' => array('src' => 'http://cakephp.org/assets/img/test.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $result = $this->Html->image('test.gif', array('pathPrefix' => '//cakephp.org/assets/img/'));
- $expected = array('img' => array('src' => '//cakephp.org/assets/img/test.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $previousConfig = Configure::read('App.imageBaseUrl');
- Configure::write('App.imageBaseUrl', '//cdn.cakephp.org/img/');
- $result = $this->Html->image('test.gif');
- $expected = array('img' => array('src' => '//cdn.cakephp.org/img/test.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- Configure::write('App.imageBaseUrl', $previousConfig);
- }
- /**
- * Test that image() works with fullBase and a webroot not equal to /
- *
- * @return void
- */
- public function testImageWithFullBase() {
- $result = $this->Html->image('test.gif', array('fullBase' => true));
- $here = $this->Html->Url->build('/', true);
- $expected = array('img' => array('src' => $here . 'img/test.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $result = $this->Html->image('sub/test.gif', array('fullBase' => true));
- $here = $this->Html->Url->build('/', true);
- $expected = array('img' => array('src' => $here . 'img/sub/test.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $request = $this->Html->request;
- $request->webroot = '/myproject/';
- $request->base = '/myproject';
- Router::pushRequest($request);
- $result = $this->Html->image('sub/test.gif', array('fullBase' => true));
- $here = $this->Html->Url->build('/', true);
- $expected = array('img' => array('src' => $here . 'img/sub/test.gif', 'alt' => ''));
- $this->assertHtml($expected, $result);
- }
- /**
- * test image() with Asset.timestamp
- *
- * @return void
- */
- public function testImageWithTimestampping() {
- Configure::write('Asset.timestamp', 'force');
- $this->Html->request->webroot = '/';
- $result = $this->Html->image('cake.icon.png');
- $expected = array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => ''));
- $this->assertHtml($expected, $result);
- Configure::write('debug', false);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->image('cake.icon.png');
- $expected = array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => ''));
- $this->assertHtml($expected, $result);
- $this->Html->request->webroot = '/testing/longer/';
- $result = $this->Html->image('cake.icon.png');
- $expected = array(
- 'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/', 'alt' => '')
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * Tests creation of an image tag using a theme and asset timestamping
- *
- * @return void
- */
- public function testImageTagWithTheme() {
- $this->skipIf(!is_writable(WWW_ROOT), 'Cannot write to webroot.');
- $testfile = WWW_ROOT . 'test_theme/img/__cake_test_image.gif';
- new File($testfile, true);
- Configure::write('Asset.timestamp', true);
- Configure::write('debug', true);
- $this->Html->Url->request->webroot = '/';
- $this->Html->Url->theme = 'TestTheme';
- $result = $this->Html->image('__cake_test_image.gif');
- $expected = array(
- 'img' => array(
- 'src' => 'preg:/\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
- 'alt' => ''
- ));
- $this->assertHtml($expected, $result);
- $this->Html->Url->request->webroot = '/testing/';
- $result = $this->Html->image('__cake_test_image.gif');
- $expected = array(
- 'img' => array(
- 'src' => 'preg:/\/testing\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
- 'alt' => ''
- ));
- $this->assertHtml($expected, $result);
- }
- /**
- * test theme assets in main webroot path
- *
- * @return void
- */
- public function testThemeAssetsInMainWebrootPath() {
- $webRoot = Configure::read('App.www_root');
- Configure::write('App.www_root', TEST_APP . 'webroot/');
- $this->Html->Url->theme = 'TestTheme';
- $result = $this->Html->css('webroot_test');
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => 'preg:/.*test_theme\/css\/webroot_test\.css/')
- );
- $this->assertHtml($expected, $result);
- $this->Html->theme = 'TestTheme';
- $result = $this->Html->css('theme_webroot');
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => 'preg:/.*test_theme\/css\/theme_webroot\.css/')
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * testStyle method
- *
- * @return void
- */
- public function testStyle() {
- $result = $this->Html->style(array('display' => 'none', 'margin' => '10px'));
- $expected = 'display:none; margin:10px;';
- $this->assertRegExp('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected);
- $result = $this->Html->style(array('display' => 'none', 'margin' => '10px'), false);
- $lines = explode("\n", $result);
- $this->assertRegExp('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]);
- $this->assertRegExp('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]);
- }
- /**
- * testCssLink method
- *
- * @return void
- */
- public function testCssLink() {
- $result = $this->Html->css('screen');
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => 'preg:/.*css\/screen\.css/')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->css('screen.css', array('once' => false));
- $this->assertHtml($expected, $result);
- Plugin::load('TestPlugin');
- $result = $this->Html->css('TestPlugin.style', array('plugin' => false));
- $expected['link']['href'] = 'preg:/.*css\/TestPlugin\.style\.css/';
- $this->assertHtml($expected, $result);
- Plugin::unload('TestPlugin');
- $result = $this->Html->css('my.css.library');
- $expected['link']['href'] = 'preg:/.*css\/my\.css\.library\.css/';
- $this->assertHtml($expected, $result);
- $result = $this->Html->css('screen.css?1234');
- $expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/';
- $this->assertHtml($expected, $result);
- $result = $this->Html->css('screen.css?with=param&other=param');
- $expected['link']['href'] = 'css/screen.css?with=param&other=param';
- $this->assertHtml($expected, $result);
- $result = $this->Html->css('http://whatever.com/screen.css?1234');
- $expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
- $this->assertHtml($expected, $result);
- 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->assertHtml($expected, $result);
- $result = $this->Html->css('//example.com/css/cake.generic.css');
- $expected['link']['href'] = 'preg:/.*example\.com\/css\/cake\.generic\.css/';
- $this->assertHtml($expected, $result);
- $result = explode("\n", trim($this->Html->css(array('cake', 'vendor.generic'))));
- $expected['link']['href'] = 'preg:/.*css\/cake\.css/';
- $this->assertHtml($expected, $result[0]);
- $expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
- $this->assertHtml($expected, $result[1]);
- $this->assertEquals(2, count($result));
- $this->View->expects($this->at(0))
- ->method('append')
- ->with('css', $this->matchesRegularExpression('/css_in_head.css/'));
- $this->View->expects($this->at(1))
- ->method('append')
- ->with('css', $this->matchesRegularExpression('/more_css_in_head.css/'));
- $result = $this->Html->css('css_in_head', array('block' => true));
- $this->assertNull($result);
- $result = $this->Html->css('more_css_in_head', array('block' => true));
- $this->assertNull($result);
- $result = $this->Html->css('import-screen', array('rel' => 'import'));
- $expected = array(
- '<style',
- 'preg:/@import url\(.*css\/import-screen\.css\);/',
- '/style'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * Test css() with once option.
- *
- * @return void
- */
- public function testCssLinkOnce() {
- $result = $this->Html->css('screen', array('once' => true));
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => 'preg:/.*css\/screen\.css/')
- );
- $this->assertHtml($expected, $result);
- // Default is once=true
- $result = $this->Html->css('screen');
- $this->assertEquals('', $result);
- $result = $this->Html->css('screen', ['once' => false]);
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => 'preg:/.*css\/screen\.css/')
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * testCssWithFullBase method
- *
- * @return void
- */
- public function testCssWithFullBase() {
- Configure::write('Asset.filter.css', false);
- $here = $this->Html->Url->build('/', true);
- $result = $this->Html->css('screen', array('fullBase' => true));
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => $here . 'css/screen.css')
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * testPluginCssLink method
- *
- * @return void
- */
- public function testPluginCssLink() {
- Plugin::load('TestPlugin');
- $result = $this->Html->css('TestPlugin.test_plugin_asset');
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->css('TestPlugin.test_plugin_asset.css', ['once' => false]);
- $this->assertHtml($expected, $result);
- $result = $this->Html->css('TestPlugin.my.css.library');
- $expected['link']['href'] = 'preg:/.*test_plugin\/css\/my\.css\.library\.css/';
- $this->assertHtml($expected, $result);
- $result = $this->Html->css('TestPlugin.test_plugin_asset.css?1234');
- $expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?1234/';
- $this->assertHtml($expected, $result);
- $result = explode("\n", trim($this->Html->css(
- ['TestPlugin.test_plugin_asset', 'TestPlugin.vendor.generic'],
- ['once' => false]
- )));
- $expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/';
- $this->assertHtml($expected, $result[0]);
- $expected['link']['href'] = 'preg:/.*test_plugin\/css\/vendor\.generic\.css/';
- $this->assertHtml($expected, $result[1]);
- $this->assertEquals(2, count($result));
- Plugin::unload('TestPlugin');
- }
- /**
- * test use of css() and timestamping
- *
- * @return void
- */
- public function testCssTimestamping() {
- Configure::write('debug', true);
- Configure::write('Asset.timestamp', true);
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => '')
- );
- $result = $this->Html->css('cake.generic', ['once' => false]);
- $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
- $this->assertHtml($expected, $result);
- Configure::write('debug', false);
- $result = $this->Html->css('cake.generic', ['once' => false]);
- $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
- $this->assertHtml($expected, $result);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->css('cake.generic', ['once' => false]);
- $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
- $this->assertHtml($expected, $result);
- $this->Html->request->webroot = '/testing/';
- $result = $this->Html->css('cake.generic', ['once' => false]);
- $expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
- $this->assertHtml($expected, $result);
- $this->Html->request->webroot = '/testing/longer/';
- $result = $this->Html->css('cake.generic', ['once' => false]);
- $expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
- $this->assertHtml($expected, $result);
- }
- /**
- * test use of css() and timestamping with plugin syntax
- *
- * @return void
- */
- public function testPluginCssTimestamping() {
- Plugin::load('TestPlugin');
- Configure::write('debug', true);
- Configure::write('Asset.timestamp', true);
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => '')
- );
- $result = $this->Html->css('TestPlugin.test_plugin_asset', ['once' => false]);
- $expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
- $this->assertHtml($expected, $result);
- Configure::write('debug', false);
- $result = $this->Html->css('TestPlugin.test_plugin_asset', ['once' => false]);
- $expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/';
- $this->assertHtml($expected, $result);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->css('TestPlugin.test_plugin_asset', ['once' => false]);
- $expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
- $this->assertHtml($expected, $result);
- $this->Html->request->webroot = '/testing/';
- $result = $this->Html->css('TestPlugin.test_plugin_asset', ['once' => false]);
- $expected['link']['href'] = 'preg:/\/testing\/test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
- $this->assertHtml($expected, $result);
- $this->Html->request->webroot = '/testing/longer/';
- $result = $this->Html->css('TestPlugin.test_plugin_asset', ['once' => false]);
- $expected['link']['href'] = 'preg:/\/testing\/longer\/test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
- $this->assertHtml($expected, $result);
- Plugin::unload('TestPlugin');
- }
- /**
- * test timestamp enforcement for script tags.
- *
- * @return void
- */
- public function testScriptTimestamping() {
- $this->skipIf(!is_writable(WWW_ROOT . 'js'), 'webroot/js is not Writable, timestamp testing has been skipped.');
- Configure::write('debug', true);
- Configure::write('Asset.timestamp', true);
- touch(WWW_ROOT . 'js/__cake_js_test.js');
- $timestamp = substr(strtotime('now'), 0, 8);
- $result = $this->Html->script('__cake_js_test', array('once' => false));
- $this->assertRegExp('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
- Configure::write('debug', false);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->script('__cake_js_test', array('once' => false));
- $this->assertRegExp('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
- unlink(WWW_ROOT . 'js/__cake_js_test.js');
- Configure::write('Asset.timestamp', false);
- }
- /**
- * test timestamp enforcement for script tags with plugin syntax.
- *
- * @return void
- */
- public function testPluginScriptTimestamping() {
- Plugin::load('TestPlugin');
- $pluginPath = Plugin::path('TestPlugin');
- $pluginJsPath = $pluginPath . 'webroot/js';
- $this->skipIf(!is_writable($pluginJsPath), $pluginJsPath . ' is not Writable, timestamp testing has been skipped.');
- Configure::write('debug', true);
- 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('once' => false));
- $this->assertRegExp('/test_plugin\/js\/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
- Configure::write('debug', false);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->script('TestPlugin.__cake_js_test', array('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);
- Plugin::unload('TestPlugin');
- }
- /**
- * test that scripts added with uses() are only ever included once.
- * test script tag generation
- *
- * @return void
- */
- public function testScript() {
- $result = $this->Html->script('foo');
- $expected = array(
- 'script' => array('src' => 'js/foo.js')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script(array('foobar', 'bar'));
- $expected = array(
- array('script' => array('src' => 'js/foobar.js')),
- '/script',
- array('script' => array('src' => 'js/bar.js')),
- '/script',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('jquery-1.3');
- $expected = array(
- 'script' => array('src' => 'js/jquery-1.3.js')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('test.json');
- $expected = array(
- 'script' => array('src' => 'js/test.json.js')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('http://example.com/test.json');
- $expected = array(
- 'script' => array('src' => 'http://example.com/test.json')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo');
- $expected = array(
- 'script' => array('src' => '/plugin/js/jquery-1.3.2.js?someparam=foo')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('test.json.js?foo=bar');
- $expected = array(
- 'script' => array('src' => 'js/test.json.js?foo=bar')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('test.json.js?foo=bar&other=test');
- $expected = array(
- 'script' => array('src' => 'js/test.json.js?foo=bar&other=test')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('foo2', array('pathPrefix' => '/my/custom/path/'));
- $expected = array(
- 'script' => array('src' => '/my/custom/path/foo2.js')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('foo3', array('pathPrefix' => 'http://cakephp.org/assets/js/'));
- $expected = array(
- 'script' => array('src' => 'http://cakephp.org/assets/js/foo3.js')
- );
- $this->assertHtml($expected, $result);
- $previousConfig = Configure::read('App.jsBaseUrl');
- Configure::write('App.jsBaseUrl', '//cdn.cakephp.org/js/');
- $result = $this->Html->script('foo4');
- $expected = array(
- 'script' => array('src' => '//cdn.cakephp.org/js/foo4.js')
- );
- $this->assertHtml($expected, $result);
- Configure::write('App.jsBaseUrl', $previousConfig);
- $result = $this->Html->script('foo');
- $this->assertNull($result, 'Script returned upon duplicate inclusion %s');
- $result = $this->Html->script(array('foo', 'bar', 'baz'));
- $this->assertNotRegExp('/foo.js/', $result);
- $result = $this->Html->script('foo', array('once' => false));
- $this->assertNotNull($result);
- $result = $this->Html->script('jquery-1.3.2', array('defer' => true, 'encoding' => 'utf-8'));
- $expected = array(
- 'script' => array('src' => 'js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8')
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * test that plugin scripts added with uses() are only ever included once.
- * test script tag generation with plugin syntax
- *
- * @return void
- */
- public function testPluginScript() {
- Plugin::load('TestPlugin');
- $result = $this->Html->script('TestPlugin.foo');
- $expected = array(
- 'script' => array('src' => 'test_plugin/js/foo.js')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script(array('TestPlugin.foobar', 'TestPlugin.bar'));
- $expected = array(
- array('script' => array('src' => 'test_plugin/js/foobar.js')),
- '/script',
- array('script' => array('src' => 'test_plugin/js/bar.js')),
- '/script',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('TestPlugin.jquery-1.3');
- $expected = array(
- 'script' => array('src' => 'test_plugin/js/jquery-1.3.js')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('TestPlugin.test.json');
- $expected = array(
- 'script' => array('src' => 'test_plugin/js/test.json.js')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('TestPlugin./jquery-1.3.2.js?someparam=foo');
- $expected = array(
- 'script' => array('src' => 'test_plugin/jquery-1.3.2.js?someparam=foo')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('TestPlugin.test.json.js?foo=bar');
- $expected = array(
- 'script' => array('src' => 'test_plugin/js/test.json.js?foo=bar')
- );
- $this->assertHtml($expected, $result);
- $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('once' => false));
- $this->assertNotNull($result);
- $result = $this->Html->script('TestPlugin.jquery-1.3.2', array('defer' => true, 'encoding' => 'utf-8'));
- $expected = array(
- 'script' => array('src' => 'test_plugin/js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8')
- );
- $this->assertHtml($expected, $result);
- Plugin::unload('TestPlugin');
- }
- /**
- * test that script() works with blocks.
- *
- * @return void
- */
- public function testScriptWithBlocks() {
- $this->View->expects($this->at(0))
- ->method('append')
- ->with('script', $this->matchesRegularExpression('/script_in_head.js/'));
- $this->View->expects($this->at(1))
- ->method('append')
- ->with('headScripts', $this->matchesRegularExpression('/second_script.js/'));
- $result = $this->Html->script('script_in_head', array('block' => true));
- $this->assertNull($result);
- $result = $this->Html->script('second_script', array('block' => 'headScripts'));
- $this->assertNull($result);
- }
- /**
- * testScriptWithFullBase method
- *
- * @return void
- */
- public function testScriptWithFullBase() {
- $here = $this->Html->Url->build('/', true);
- $result = $this->Html->script('foo', array('fullBase' => true));
- $expected = array(
- 'script' => array('src' => $here . 'js/foo.js')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script(array('foobar', 'bar'), array('fullBase' => true));
- $expected = array(
- array('script' => array('src' => $here . 'js/foobar.js')),
- '/script',
- array('script' => array('src' => $here . 'js/bar.js')),
- '/script',
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * test a script file in the webroot/theme dir.
- *
- * @return void
- */
- public function testScriptInTheme() {
- $this->skipIf(!is_writable(WWW_ROOT), 'Cannot write to webroot.');
- $testfile = WWW_ROOT . '/test_theme/js/__test_js.js';
- new File($testfile, true);
- $this->Html->Url->request->webroot = '/';
- $this->Html->Url->theme = 'TestTheme';
- $result = $this->Html->script('__test_js.js');
- $expected = array(
- 'script' => array('src' => '/test_theme/js/__test_js.js')
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * test Script block generation
- *
- * @return void
- */
- public function testScriptBlock() {
- $result = $this->Html->scriptBlock('window.foo = 2;');
- $expected = array(
- '<script',
- $this->cDataStart,
- 'window.foo = 2;',
- $this->cDataEnd,
- '/script',
- );
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false));
- $expected = array(
- '<script',
- 'window.foo = 2;',
- '/script',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => true));
- $expected = array(
- '<script',
- $this->cDataStart,
- 'window.foo = 2;',
- $this->cDataEnd,
- '/script',
- );
- $this->assertHtml($expected, $result);
- $this->View->expects($this->at(0))
- ->method('append')
- ->with('script', $this->matchesRegularExpression('/window\.foo\s\=\s2;/'));
- $this->View->expects($this->at(1))
- ->method('append')
- ->with('scriptTop', $this->stringContains('alert('));
- $result = $this->Html->scriptBlock('window.foo = 2;', array('block' => true));
- $this->assertNull($result);
- $result = $this->Html->scriptBlock('alert("hi")', array('block' => 'scriptTop'));
- $this->assertNull($result);
- $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false, 'encoding' => 'utf-8'));
- $expected = array(
- 'script' => array('encoding' => 'utf-8'),
- 'window.foo = 2;',
- '/script',
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * test script tag output buffering when using scriptStart() and scriptEnd();
- *
- * @return void
- */
- public function testScriptStartAndScriptEnd() {
- $result = $this->Html->scriptStart(array('safe' => true));
- $this->assertNull($result);
- echo 'this is some javascript';
- $result = $this->Html->scriptEnd();
- $expected = array(
- '<script',
- $this->cDataStart,
- 'this is some javascript',
- $this->cDataEnd,
- '/script'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->scriptStart(array('safe' => false));
- $this->assertNull($result);
- echo 'this is some javascript';
- $result = $this->Html->scriptEnd();
- $expected = array(
- '<script',
- 'this is some javascript',
- '/script'
- );
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $this->View->expects($this->once())
- ->method('append');
- $result = $this->Html->scriptStart(array('safe' => false, 'block' => true));
- $this->assertNull($result);
- echo 'this is some javascript';
- $result = $this->Html->scriptEnd();
- $this->assertNull($result);
- }
- /**
- * testCharsetTag method
- *
- * @return void
- */
- public function testCharsetTag() {
- Configure::write('App.encoding', null);
- $result = $this->Html->charset();
- $expected = array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8'));
- $this->assertHtml($expected, $result);
- Configure::write('App.encoding', 'ISO-8859-1');
- $result = $this->Html->charset();
- $expected = array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=iso-8859-1'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->charset('UTF-7');
- $expected = array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-7'));
- $this->assertHtml($expected, $result);
- }
- /**
- * testGetCrumb and addCrumb method
- *
- * @return void
- */
- public function testBreadcrumb() {
- $this->assertNull($this->Html->getCrumbs());
- $this->Html->addCrumb('First', '#first');
- $this->Html->addCrumb('Second', '#second');
- $this->Html->addCrumb('Third', '#third');
- $result = $this->Html->getCrumbs();
- $expected = array(
- array('a' => array('href' => '#first')),
- 'First',
- '/a',
- '»',
- array('a' => array('href' => '#second')),
- 'Second',
- '/a',
- '»',
- array('a' => array('href' => '#third')),
- 'Third',
- '/a',
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->getCrumbs(' > ');
- $expected = array(
- array('a' => array('href' => '#first')),
- 'First',
- '/a',
- ' > ',
- array('a' => array('href' => '#second')),
- 'Second',
- '/a',
- ' > ',
- array('a' => array('href' => '#third')),
- 'Third',
- '/a',
- );
- $this->assertHtml($expected, $result);
- $this->Html->addCrumb('Fourth', null);
- $result = $this->Html->getCrumbs();
- $expected = array(
- array('a' => array('href' => '#first')),
- 'First',
- '/a',
- '»',
- array('a' => array('href' => '#second')),
- 'Second',
- '/a',
- '»',
- array('a' => array('href' => '#third')),
- 'Third',
- '/a',
- '»',
- 'Fourth'
- );
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- }
- /**
- * Test the array form of $startText
- *
- * @return void
- */
- public function testGetCrumbFirstLink() {
- $result = $this->Html->getCrumbList(array(), 'Home');
- $expected = array(
- '<ul',
- array('li' => array('class' => 'first')),
- array('a' => array('href' => '/')), 'Home', '/a',
- '/li',
- '/ul'
- );
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- }
- /**
- * testNestedList method
- *
- * @return void
- */
- public function testNestedList() {
- $list = array(
- 'Item 1',
- 'Item 2' => array(
- 'Item 2.1'
- ),
- 'Item 3',
- 'Item 4' => array(
- 'Item 4.1',
- 'Item 4.2',
- 'Item 4.3' => array(
- 'Item 4.3.1',
- 'Item 4.3.2'
- )
- ),
- 'Item 5' => array(
- 'Item 5.1',
- 'Item 5.2'
- )
- );
- $result = $this->Html->nestedList($list);
- $expected = array(
- '<ul',
- '<li', 'Item 1', '/li',
- '<li', 'Item 2',
- '<ul', '<li', 'Item 2.1', '/li', '/ul',
- '/li',
- '<li', 'Item 3', '/li',
- '<li', 'Item 4',
- '<ul',
- '<li', 'Item 4.1', '/li',
- '<li', 'Item 4.2', '/li',
- '<li', 'Item 4.3',
- '<ul',
- '<li', 'Item 4.3.1', '/li',
- '<li', 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- '<li', 'Item 5',
- '<ul',
- '<li', 'Item 5.1', '/li',
- '<li', 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->nestedList($list);
- $this->assertHtml($expected, $result);
- $result = $this->Html->nestedList($list, array('tag' => 'ol'));
- $expected = array(
- '<ol',
- '<li', 'Item 1', '/li',
- '<li', 'Item 2',
- '<ol', '<li', 'Item 2.1', '/li', '/ol',
- '/li',
- '<li', 'Item 3', '/li',
- '<li', 'Item 4',
- '<ol',
- '<li', 'Item 4.1', '/li',
- '<li', 'Item 4.2', '/li',
- '<li', 'Item 4.3',
- '<ol',
- '<li', 'Item 4.3.1', '/li',
- '<li', 'Item 4.3.2', '/li',
- '/ol',
- '/li',
- '/ol',
- '/li',
- '<li', 'Item 5',
- '<ol',
- '<li', 'Item 5.1', '/li',
- '<li', 'Item 5.2', '/li',
- '/ol',
- '/li',
- '/ol'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->nestedList($list, array('tag' => 'ol'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->nestedList($list, array('class' => 'list'));
- $expected = array(
- array('ul' => array('class' => 'list')),
- '<li', 'Item 1', '/li',
- '<li', 'Item 2',
- array('ul' => array('class' => 'list')), '<li', 'Item 2.1', '/li', '/ul',
- '/li',
- '<li', 'Item 3', '/li',
- '<li', 'Item 4',
- array('ul' => array('class' => 'list')),
- '<li', 'Item 4.1', '/li',
- '<li', 'Item 4.2', '/li',
- '<li', 'Item 4.3',
- array('ul' => array('class' => 'list')),
- '<li', 'Item 4.3.1', '/li',
- '<li', 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- '<li', 'Item 5',
- array('ul' => array('class' => 'list')),
- '<li', 'Item 5.1', '/li',
- '<li', 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->nestedList($list, array(), array('class' => 'item'));
- $expected = array(
- '<ul',
- array('li' => array('class' => 'item')), 'Item 1', '/li',
- array('li' => array('class' => 'item')), 'Item 2',
- '<ul', array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
- '/li',
- array('li' => array('class' => 'item')), 'Item 3', '/li',
- array('li' => array('class' => 'item')), 'Item 4',
- '<ul',
- array('li' => array('class' => 'item')), 'Item 4.1', '/li',
- array('li' => array('class' => 'item')), 'Item 4.2', '/li',
- array('li' => array('class' => 'item')), 'Item 4.3',
- '<ul',
- array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
- array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- array('li' => array('class' => 'item')), 'Item 5',
- '<ul',
- array('li' => array('class' => 'item')), 'Item 5.1', '/li',
- array('li' => array('class' => 'item')), 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->nestedList($list, array(), array('even' => 'even', 'odd' => 'odd'));
- $expected = array(
- '<ul',
- array('li' => array('class' => 'odd')), 'Item 1', '/li',
- array('li' => array('class' => 'even')), 'Item 2',
- '<ul', array('li' => array('class' => 'odd')), 'Item 2.1', '/li', '/ul',
- '/li',
- array('li' => array('class' => 'odd')), 'Item 3', '/li',
- array('li' => array('class' => 'even')), 'Item 4',
- '<ul',
- array('li' => array('class' => 'odd')), 'Item 4.1', '/li',
- array('li' => array('class' => 'even')), 'Item 4.2', '/li',
- array('li' => array('class' => 'odd')), 'Item 4.3',
- '<ul',
- array('li' => array('class' => 'odd')), 'Item 4.3.1', '/li',
- array('li' => array('class' => 'even')), 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- array('li' => array('class' => 'odd')), 'Item 5',
- '<ul',
- array('li' => array('class' => 'odd')), 'Item 5.1', '/li',
- array('li' => array('class' => 'even')), 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->nestedList($list, array('class' => 'list'), array('class' => 'item'));
- $expected = array(
- array('ul' => array('class' => 'list')),
- array('li' => array('class' => 'item')), 'Item 1', '/li',
- array('li' => array('class' => 'item')), 'Item 2',
- array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
- '/li',
- array('li' => array('class' => 'item')), 'Item 3', '/li',
- array('li' => array('class' => 'item')), 'Item 4',
- array('ul' => array('class' => 'list')),
- array('li' => array('class' => 'item')), 'Item 4.1', '/li',
- array('li' => array('class' => 'item')), 'Item 4.2', '/li',
- array('li' => array('class' => 'item')), 'Item 4.3',
- array('ul' => array('class' => 'list')),
- array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
- array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- array('li' => array('class' => 'item')), 'Item 5',
- array('ul' => array('class' => 'list')),
- array('li' => array('class' => 'item')), 'Item 5.1', '/li',
- array('li' => array('class' => 'item')), 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * testMeta method
- *
- * @return void
- */
- public function testMeta() {
- Router::connect('/:controller', array('action' => 'index'));
- $result = $this->Html->meta('this is an rss feed', array('controller' => 'posts', '_ext' => 'rss'));
- $expected = array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('rss', array('controller' => 'posts', '_ext' => 'rss'), array('title' => 'this is an rss feed'));
- $expected = array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('atom', array('controller' => 'posts', '_ext' => 'xml'));
- $expected = array('link' => array('href' => 'preg:/.*\/posts\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('non-existing');
- $expected = array('<meta');
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('non-existing', '/posts.xpp');
- $expected = array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'non-existing'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('non-existing', '/posts.xpp', array('type' => 'atom'));
- $expected = array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('atom', array('controller' => 'posts', '_ext' => 'xml'), array('link' => '/articles.rss'));
- $expected = array('link' => array('href' => 'preg:/.*\/articles\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
- $expected = array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('description', 'this is the meta description');
- $expected = array('meta' => array('name' => 'description', 'content' => 'this is the meta description'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('robots', 'ALL');
- $expected = array('meta' => array('name' => 'robots', 'content' => 'ALL'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->meta('viewport', 'width=device-width');
- $expected = [
- 'meta' => ['name' => 'viewport', 'content' => 'width=device-width']
- ];
- $this->assertHtml($expected, $result);
- }
- /**
- * Test generating favicon's with meta()
- *
- * @return void
- */
- public function testMetaIcon() {
- $result = $this->Html->meta('icon', 'favicon.ico');
- $expected = array(
- 'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
- array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
- );
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- }
- /**
- * Test the inline and block options for meta()
- *
- * @return void
- */
- public function testMetaWithBlocks() {
- $this->View->expects($this->at(0))
- ->method('append')
- ->with('meta', $this->stringContains('robots'));
- $this->View->expects($this->at(1))
- ->method('append')
- ->with('metaTags', $this->stringContains('favicon.ico'));
- $result = $this->Html->meta('robots', 'ALL', array('block' => true));
- $this->assertNull($result);
- $result = $this->Html->meta('icon', 'favicon.ico', array('block' => 'metaTags'));
- $this->assertNull($result);
- }
- /**
- * testTableHeaders method
- *
- * @return void
- */
- public function testTableHeaders() {
- $result = $this->Html->tableHeaders(array('ID', 'Name', 'Date'));
- $expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $result = $this->Html->tableHeaders(array('ID', array('Name' => array()), 'Date'));
- $expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
- $this->assertHtml($expected, $result);
- }
- /**
- * testTableCells method
- *
- * @return void
- */
- public function testTableCells() {
- $tr = array(
- 'td content 1',
- array('td content 2', array("width" => "100px")),
- array('td content 3', array('width' => '100px'))
- );
- $result = $this->Html->tableCells($tr);
- $expected = array(
- '<tr',
- '<td', 'td content 1', '/td',
- array('td' => array('width' => '100px')), 'td content 2', '/td',
- array('td' => array('width' => 'preg:/100px/')), 'td content 3', '/td',
- '/tr'
- );
- $this->assertHtml($expected, $result);
- $tr = array('td content 1', 'td content 2', 'td content 3');
- $result = $this->Html->tableCells($tr, null, null, true);
- $expected = array(
- '<tr',
- array('td' => array('class' => 'column-1')), 'td content 1', '/td',
- array('td' => array('class' => 'column-2')), 'td content 2', '/td',
- array('td' => array('class' => 'column-3')), 'td content 3', '/td',
- '/tr'
- );
- $this->assertHtml($expected, $result);
- $tr = array('td content 1', 'td content 2', 'td content 3');
- $result = $this->Html->tableCells($tr, true);
- $expected = array(
- '<tr',
- array('td' => array('class' => 'column-1')), 'td content 1', '/td',
- array('td' => array('class' => 'column-2')), 'td content 2', '/td',
- array('td' => array('class' => 'column-3')), 'td content 3', '/td',
- '/tr'
- );
- $this->assertHtml($expected, $result);
- $tr = array(
- 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')
- );
- $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
- $expected = "<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
- $this->assertEquals($expected, $result);
- $tr = array(
- 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')
- );
- $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
- $expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
- $this->assertEquals($expected, $result);
- $tr = array(
- 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')
- );
- $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
- $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false);
- $expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
- $this->assertEquals($expected, $result);
- }
- /**
- * testTag method
- *
- * @return void
- */
- public function testTag() {
- $result = $this->Html->tag('div');
- $this->assertHtml('<div', $result);
- $result = $this->Html->tag('div', 'text');
- $this->assertHtml(array('<div', 'text', '/div'), $result);
- $result = $this->Html->tag('div', '<text>', array('class' => 'class-name', 'escape' => true));
- $expected = array('div' => array('class' => 'class-name'), '<text>', '/div');
- $this->assertHtml($expected, $result);
- $result = $this->Html->tag(false, '<em>stuff</em>');
- $this->assertEquals('<em>stuff</em>', $result);
- $result = $this->Html->tag(null, '<em>stuff</em>');
- $this->assertEquals('<em>stuff</em>', $result);
- $result = $this->Html->tag('', '<em>stuff</em>');
- $this->assertEquals('<em>stuff</em>', $result);
- }
- /**
- * testDiv method
- *
- * @return void
- */
- public function testDiv() {
- $result = $this->Html->div('class-name');
- $expected = array('div' => array('class' => 'class-name'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->div('class-name', 'text');
- $expected = array('div' => array('class' => 'class-name'), 'text', '/div');
- $this->assertHtml($expected, $result);
- $result = $this->Html->div('class-name', '<text>', array('escape' => true));
- $expected = array('div' => array('class' => 'class-name'), '<text>', '/div');
- $this->assertHtml($expected, $result);
- }
- /**
- * testPara method
- *
- * @return void
- */
- public function testPara() {
- $result = $this->Html->para('class-name', '');
- $expected = array('p' => array('class' => 'class-name'));
- $this->assertHtml($expected, $result);
- $result = $this->Html->para('class-name', 'text');
- $expected = array('p' => array('class' => 'class-name'), 'text', '/p');
- $this->assertHtml($expected, $result);
- $result = $this->Html->para('class-name', '<text>', array('escape' => true));
- $expected = array('p' => array('class' => 'class-name'), '<text>', '/p');
- $this->assertHtml($expected, $result);
- }
- /**
- * testMedia method
- *
- * @return void
- */
- public function testMedia() {
- $result = $this->Html->media('video.webm');
- $expected = array('video' => array('src' => 'files/video.webm'), '/video');
- $this->assertHtml($expected, $result);
- $result = $this->Html->media('video.webm', array(
- '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->assertHtml($expected, $result);
- $result = $this->Html->media('video.webm', array('autoload', 'muted' => 'muted'));
- $expected = array(
- 'video' => array(
- 'src' => 'files/video.webm',
- 'autoload' => 'autoload',
- 'muted' => 'muted'
- ),
- '/video'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->media(
- 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(
- 'video' => array('poster' => Configure::read('App.imageBaseUrl') . 'poster.jpg'),
- 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->assertHtml($expected, $result);
- $result = $this->Html->media('video.ogv', array('tag' => 'video'));
- $expected = array('video' => array('src' => 'files/video.ogv'), '/video');
- $this->assertHtml($expected, $result);
- $result = $this->Html->media('audio.mp3');
- $expected = array('audio' => array('src' => 'files/audio.mp3'), '/audio');
- $this->assertHtml($expected, $result);
- $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->assertHtml($expected, $result);
- $result = $this->Html->media(null, array('src' => 'video.webm'));
- $expected = array(
- 'video' => array('src' => 'files/video.webm'),
- '/video'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * testCrumbList method
- *
- * @return void
- */
- public function testCrumbList() {
- $this->assertNull($this->Html->getCrumbList());
- $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')
- );
- $expected = 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'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * Test getCrumbList startText
- *
- * @return void
- */
- public function testCrumbListFirstLink() {
- $this->Html->addCrumb('First', '#first');
- $this->Html->addCrumb('Second', '#second');
- $result = $this->Html->getCrumbList(array(), 'Home');
- $expected = 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'
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->getCrumbList(array(), array('url' => '/home', 'text' => '<img src="/home.png" />', 'escape' => false));
- $expected = 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'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * test getCrumbList() in Twitter Bootstrap style.
- *
- * @return void
- */
- public function testCrumbListBootstrapStyle() {
- $this->Html->addCrumb('Home', '/', array('class' => 'home'));
- $this->Html->addCrumb('Library', '/lib');
- $this->Html->addCrumb('Data');
- $result = $this->Html->getCrumbList(array(
- 'class' => 'breadcrumb',
- 'separator' => '<span class="divider">-</span>',
- 'firstClass' => false,
- 'lastClass' => 'active'
- ));
- $expected = array(
- array('ul' => array('class' => 'breadcrumb')),
- '<li',
- array('a' => array('class' => 'home', 'href' => '/')), 'Home', '/a',
- array('span' => array('class' => 'divider')), '-', '/span',
- '/li',
- '<li',
- array('a' => array('href' => '/lib')), 'Library', '/a',
- array('span' => array('class' => 'divider')), '-', '/span',
- '/li',
- array('li' => array('class' => 'active')), 'Data', '/li',
- '/ul'
- );
- $this->assertHtml($expected, $result);
- }
- /**
- * Test GetCrumbList using style of Zurb Foundation.
- *
- * @return void
- */
- public function testCrumbListZurbStyle() {
- $this->Html->addCrumb('Home', '#');
- $this->Html->addCrumb('Features', '#');
- $this->Html->addCrumb('Gene Splicing', '#');
- $this->Html->addCrumb('Home', '#');
- $result = $this->Html->getCrumbList(
- array('class' => 'breadcrumbs', 'firstClass' => false, 'lastClass' => 'current')
- );
- $expected = 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'
- );
- $this->assertHtml($expected, $result, true);
- }
- /**
- * Tests that CSS and Javascript files of the same name don't conflict with the 'once' test
- *
- * @return void
- */
- public function testCssAndScriptWithSameName() {
- $result = $this->Html->css('foo');
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'href' => 'preg:/.*css\/foo\.css/')
- );
- $this->assertHtml($expected, $result);
- $result = $this->Html->script('foo');
- $expected = array(
- 'script' => array('src' => 'js/foo.js')
- );
- $this->assertHtml($expected, $result);
- }
- }
|