| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484 |
- <?php
- /**
- * HtmlHelperTest file
- *
- * PHP 5
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
- * Copyright 2005-2011, Cake Software Foundation, Inc.
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
- * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
- * @package Cake.Test.Case.View.Helper
- * @since CakePHP(tm) v 1.2.0.4206
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- App::uses('Controller', 'Controller');
- App::uses('Helper', 'View');
- App::uses('AppHelper', 'View/Helper');
- App::uses('HtmlHelper', 'View/Helper');
- App::uses('FormHelper', 'View/Helper');
- App::uses('ClassRegistry', 'Utility');
- App::uses('Folder', 'Utility');
- if (!defined('FULL_BASE_URL')) {
- define('FULL_BASE_URL', 'http://cakephp.org');
- }
- /**
- * TheHtmlTestController class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class TheHtmlTestController extends Controller {
- /**
- * name property
- *
- * @var string 'TheTest'
- */
- public $name = 'TheTest';
- /**
- * uses property
- *
- * @var mixed null
- */
- public $uses = null;
- }
- class TestHtmlHelper extends HtmlHelper {
- /**
- * expose a method as public
- *
- * @param string $options
- * @param string $exclude
- * @param string $insertBefore
- * @param string $insertAfter
- * @return void
- */
- public function parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
- return $this->_parseAttributes($options, $exclude, $insertBefore, $insertAfter);
- }
- /**
- * Get a protected attribute value
- *
- * @param string $attribute
- * @return mixed
- */
- public function getAttribute($attribute) {
- if (!isset($this->{$attribute})) {
- return null;
- }
- return $this->{$attribute};
- }
- }
- /**
- * Html5TestHelper class
- *
- * @package Cake.Test.Case.View.Helper
- */
- 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"';
- }
- /**
- * HtmlHelperTest class
- *
- * @package Cake.Test.Case.View.Helper
- */
- class HtmlHelperTest extends CakeTestCase {
- /**
- * 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();
- $this->View = $this->getMock('View', array('addScript'), array(new TheHtmlTestController()));
- $this->Html = new TestHtmlHelper($this->View);
- $this->Html->request = new CakeRequest(null, false);
- $this->Html->request->webroot = '';
- Configure::write('Asset.timestamp', false);
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->Html, $this->View);
- }
- /**
- * testDocType method
- *
- * @return void
- */
- public function testDocType() {
- $result = $this->Html->docType();
- $expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
- $this->assertEqual($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->assertEqual($expected, $result);
- $this->assertNull($this->Html->docType('non-existing-doctype'));
- }
- /**
- * testLink method
- *
- * @return void
- */
- public function testLink() {
- $this->Html->request->webroot = '';
- $result = $this->Html->link('/home');
- $expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', 'full_base' => true));
- $expected = array('a' => array('href' => FULL_BASE_URL . '/posts'), 'Posts', '/a');
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
- $expected = array(
- 'a' => array('href' => '/home', 'onclick' => 'return confirm('Are you sure you want to do this?');'),
- 'Home',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Home', '/home', array('default' => false));
- $expected = array(
- 'a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'),
- 'Home',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->link('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);
- $result = $this->Html->link('Next >', '#');
- $expected = array(
- 'a' => array('href' => '#'),
- 'Next >',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Next >', '#', array('escape' => true));
- $expected = array(
- 'a' => array('href' => '#'),
- 'Next >',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Next >', '#', array('escape' => 'utf-8'));
- $expected = array(
- 'a' => array('href' => '#'),
- 'Next >',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Next >', '#', array('escape' => false));
- $expected = array(
- 'a' => array('href' => '#'),
- 'Next >',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Next >', '#', array(
- 'title' => 'to escape … or not escape?',
- 'escape' => false
- ));
- $expected = array(
- 'a' => array('href' => '#', 'title' => 'to escape … or not escape?'),
- 'Next >',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Next >', '#', array(
- 'title' => 'to escape … or not escape?',
- 'escape' => true
- ));
- $expected = array(
- 'a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'),
- 'Next >',
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->link('Original size', array(
- 'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
- ));
- $expected = array(
- 'a' => array('href' => '/images/view/3?height=100&width=200'),
- 'Original size',
- '/a'
- );
- $this->assertTags($result, $expected);
- 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->assertTags($result, $expected);
- $result = $this->Html->image('test.gif', array('url' => '#'));
- $expected = array(
- 'a' => array('href' => '#'),
- 'img' => array('src' => 'img/test.gif', 'alt' => ''),
- '/a'
- );
- $this->assertTags($result, $expected);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->link($this->Html->image('../favicon.ico'), '#', array('escape' => false));
- $expected = array(
- 'a' => array('href' => '#'),
- 'img' => array('src' => 'preg:/img\/..\/favicon\.ico\?\d*/', 'alt' => ''),
- '/a'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->image('../favicon.ico', array('url' => '#'));
- $expected = array(
- 'a' => array('href' => '#'),
- 'img' => array('src' => 'preg:/img\/..\/favicon\.ico\?\d*/', 'alt' => ''),
- '/a'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testImageTag method
- *
- * @return void
- */
- public function testImageTag() {
- $this->Html->request->webroot = '';
- $result = $this->Html->image('test.gif');
- $this->assertTags($result, array('img' => array('src' => 'img/test.gif', 'alt' => '')));
- $result = $this->Html->image('http://google.com/logo.gif');
- $this->assertTags($result, array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => '')));
- $result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, 'ext' => 'gif'));
- $this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
- $result = $this->Html->image('/test/view/1.gif');
- $this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
- }
- /**
- * 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');
- $this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
- Configure::write('debug', 0);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->image('cake.icon.png');
- $this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
- $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->assertTags($result, $expected);
- }
- /**
- * Tests creation of an image tag using a theme and asset timestamping
- *
- * @return void
- */
- public function testImageTagWithTheme() {
- $this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme.');
- App::uses('File', 'Utility');
- $testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
- $File = new File($testfile, true);
- App::build(array(
- 'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
- ));
- Configure::write('Asset.timestamp', true);
- Configure::write('debug', 1);
- $this->Html->request->webroot = '/';
- $this->Html->theme = 'test_theme';
- $result = $this->Html->image('__cake_test_image.gif');
- $this->assertTags($result, array(
- 'img' => array(
- 'src' => 'preg:/\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
- 'alt' => ''
- )));
- $this->Html->request->webroot = '/testing/';
- $result = $this->Html->image('__cake_test_image.gif');
- $this->assertTags($result, array(
- 'img' => array(
- 'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
- 'alt' => ''
- )));
- $dir = new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
- $dir->delete();
- }
- /**
- * test theme assets in main webroot path
- *
- * @return void
- */
- public function testThemeAssetsInMainWebrootPath() {
- App::build(array(
- 'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
- ));
- $webRoot = Configure::read('App.www_root');
- Configure::write('App.www_root', CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS);
- $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/')
- );
- $this->assertTags($result, $expected);
- $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/')
- );
- $this->assertTags($result, $expected);
- Configure::write('App.www_root', $webRoot);
- }
- /**
- * testStyle method
- *
- * @return void
- */
- public function testStyle() {
- $result = $this->Html->style('display: none;');
- $this->assertEqual($result, 'display: none;');
- $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'));
- $expected = 'display:none; margin:10px;';
- $this->assertPattern('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected);
- $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'), false);
- $lines = explode("\n", $result);
- $this->assertPattern('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]);
- $this->assertPattern('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]);
- }
- /**
- * testCssLink method
- *
- * @return void
- */
- public function testCssLink() {
- Configure::write('Asset.filter.css', false);
- $result = $this->Html->css('screen');
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->css('screen.css');
- $this->assertTags($result, $expected);
- $result = $this->Html->css('my.css.library');
- $expected['link']['href'] = 'preg:/.*css\/my\.css\.library\.css/';
- $this->assertTags($result, $expected);
- $result = $this->Html->css('screen.css?1234');
- $expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/';
- $this->assertTags($result, $expected);
- $result = $this->Html->css('http://whatever.com/screen.css?1234');
- $expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
- $this->assertTags($result, $expected);
- Configure::write('Asset.filter.css', 'css.php');
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
- $this->assertTags($result, $expected);
- Configure::write('Asset.filter.css', false);
- $result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
- $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
- $this->assertTags($result[0], $expected);
- $expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
- $this->assertTags($result[1], $expected);
- $this->assertEqual(count($result), 2);
- $this->View->expects($this->at(0))->method('addScript')
- ->with($this->matchesRegularExpression('/css_in_head.css/'));
- $this->View->expects($this->at(1))
- ->method('addScript')
- ->with($this->matchesRegularExpression('/more_css_in_head.css/'));
- $result = $this->Html->css('css_in_head', null, array('inline' => false));
- $this->assertNull($result);
- $result = $this->Html->css('more_css_in_head', null, array('inline' => false));
- $this->assertNull($result);
- }
- /**
- * test use of css() and timestamping
- *
- * @return void
- */
- public function testCssTimestamping() {
- Configure::write('debug', 2);
- Configure::write('Asset.timestamp', true);
- $expected = array(
- 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => '')
- );
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
- $this->assertTags($result, $expected);
- Configure::write('debug', 0);
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
- $this->assertTags($result, $expected);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
- $this->assertTags($result, $expected);
- $this->Html->request->webroot = '/testing/';
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
- $this->assertTags($result, $expected);
- $this->Html->request->webroot = '/testing/longer/';
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
- $this->assertTags($result, $expected);
- }
- /**
- * test timestamp enforcement for script tags.
- *
- * @return void
- */
- public function testScriptTimestamping() {
- $this->skipIf(!is_writable(JS), 'webroot/js is not Writable, timestamp testing has been skipped.');
- Configure::write('debug', 2);
- Configure::write('Asset.timestamp', true);
- touch(WWW_ROOT . 'js' . DS. '__cake_js_test.js');
- $timestamp = substr(strtotime('now'), 0, 8);
- $result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false));
- $this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
- Configure::write('debug', 0);
- Configure::write('Asset.timestamp', 'force');
- $result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false));
- $this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
- unlink(WWW_ROOT . 'js' . DS. '__cake_js_test.js');
- Configure::write('Asset.timestamp', false);
- }
- /**
- * 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('type' => 'text/javascript', 'src' => 'js/foo.js')
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->script(array('foobar', 'bar'));
- $expected = array(
- array('script' => array('type' => 'text/javascript', 'src' => 'js/foobar.js')),
- '/script',
- array('script' => array('type' => 'text/javascript', 'src' => 'js/bar.js')),
- '/script',
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->script('jquery-1.3');
- $expected = array(
- 'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.js')
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->script('test.json');
- $expected = array(
- 'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js')
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->script('http://example.com/test.json');
- $expected = array(
- 'script' => array('type' => 'text/javascript', 'src' => 'http://example.com/test.json')
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo');
- $expected = array(
- 'script' => array('type' => 'text/javascript', 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo')
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->script('test.json.js?foo=bar');
- $expected = array(
- 'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js?foo=bar')
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->script('foo');
- $this->assertNull($result, 'Script returned upon duplicate inclusion %s');
- $result = $this->Html->script(array('foo', 'bar', 'baz'));
- $this->assertNoPattern('/foo.js/', $result);
- $result = $this->Html->script('foo', array('inline' => true, 'once' => false));
- $this->assertNotNull($result);
- $result = $this->Html->script('jquery-1.3.2', array('defer' => true, 'encoding' => 'utf-8'));
- $expected = array(
- 'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8')
- );
- $this->assertTags($result, $expected);
- $this->View->expects($this->any())->method('addScript')
- ->with($this->matchesRegularExpression('/script_in_head.js/'));
- $result = $this->Html->script('script_in_head', array('inline' => false));
- $this->assertNull($result);
- }
- /**
- * test a script file in the webroot/theme dir.
- *
- * @return void
- */
- public function testScriptInTheme() {
- $this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme.');
- App::uses('File', 'Utility');
- $testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'js' . DS . '__test_js.js';
- $File = new File($testfile, true);
- App::build(array(
- 'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
- ));
- $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')
- );
- $this->assertTags($result, $expected);
- $Folder = new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
- $Folder->delete();
- App::build();
- }
- /**
- * test Script block generation
- *
- * @return void
- */
- public function testScriptBlock() {
- $result = $this->Html->scriptBlock('window.foo = 2;');
- $expected = array(
- 'script' => array('type' => 'text/javascript'),
- $this->cDataStart,
- 'window.foo = 2;',
- $this->cDataEnd,
- '/script',
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false));
- $expected = array(
- 'script' => array('type' => 'text/javascript'),
- 'window.foo = 2;',
- '/script',
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => true));
- $expected = array(
- 'script' => array('type' => 'text/javascript'),
- $this->cDataStart,
- 'window.foo = 2;',
- $this->cDataEnd,
- '/script',
- );
- $this->assertTags($result, $expected);
- $this->View->expects($this->any())->method('addScript')
- ->with($this->matchesRegularExpression('/window\.foo\s\=\s2;/'));
- $result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false));
- $this->assertNull($result);
- $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false, 'encoding' => 'utf-8'));
- $expected = array(
- 'script' => array('type' => 'text/javascript', 'encoding' => 'utf-8'),
- 'window.foo = 2;',
- '/script',
- );
- $this->assertTags($result, $expected);
- }
- /**
- * 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' => array('type' => 'text/javascript'),
- $this->cDataStart,
- 'this is some javascript',
- $this->cDataEnd,
- '/script'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->scriptStart(array('safe' => false));
- $this->assertNull($result);
- echo 'this is some javascript';
- $result = $this->Html->scriptEnd();
- $expected = array(
- 'script' => array('type' => 'text/javascript'),
- 'this is some javascript',
- '/script'
- );
- $this->assertTags($result, $expected);
- $this->View->expects($this->once())->method('addScript');
- $result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
- $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();
- $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')));
- }
- /**
- * testBreadcrumb 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->assertTags($result, $expected);
- $result = $this->Html->getCrumbs(' > ');
- $expected = array(
- array('a' => array('href' => '#first')),
- 'First',
- '/a',
- ' > ',
- array('a' => array('href' => '#second')),
- 'Second',
- '/a',
- ' > ',
- array('a' => array('href' => '#third')),
- 'Third',
- '/a',
- );
- $this->assertTags($result, $expected);
- $this->assertPattern('/^<a[^<>]+>First<\/a> > <a[^<>]+>Second<\/a> > <a[^<>]+>Third<\/a>$/', $result);
- $this->assertPattern('/<a\s+href=["\']+\#first["\']+[^<>]*>First<\/a>/', $result);
- $this->assertPattern('/<a\s+href=["\']+\#second["\']+[^<>]*>Second<\/a>/', $result);
- $this->assertPattern('/<a\s+href=["\']+\#third["\']+[^<>]*>Third<\/a>/', $result);
- $this->assertNoPattern('/<a[^<>]+[^href]=[^<>]*>/', $result);
- $this->Html->addCrumb('Fourth', null);
- $result = $this->Html->getCrumbs();
- $expected = array(
- array('a' => array('href' => '#first')),
- 'First',
- '/a',
- '»',
- array('a' => array('href' => '#second')),
- 'Second',
- '/a',
- '»',
- array('a' => array('href' => '#third')),
- 'Third',
- '/a',
- '»',
- 'Fourth'
- );
- $this->assertTags($result, $expected);
- $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);
- }
- /**
- * 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->assertTags($result, $expected);
- $result = $this->Html->nestedList($list, null);
- $expected = array(
- '<ul',
- '<li', 'Item 1', '/li',
- '<li', 'Item 2',
- '<ul', '<li', 'Item 2.1', '/li', '/ul',
- '/li',
- '<li', 'Item 3', '/li',
- '<li', 'Item 4',
- '<ul',
- '<li', 'Item 4.1', '/li',
- '<li', 'Item 4.2', '/li',
- '<li', 'Item 4.3',
- '<ul',
- '<li', 'Item 4.3.1', '/li',
- '<li', 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- '<li', 'Item 5',
- '<ul',
- '<li', 'Item 5.1', '/li',
- '<li', 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->nestedList($list, array(), array(), 'ol');
- $expected = array(
- '<ol',
- '<li', 'Item 1', '/li',
- '<li', 'Item 2',
- '<ol', '<li', 'Item 2.1', '/li', '/ol',
- '/li',
- '<li', 'Item 3', '/li',
- '<li', 'Item 4',
- '<ol',
- '<li', 'Item 4.1', '/li',
- '<li', 'Item 4.2', '/li',
- '<li', 'Item 4.3',
- '<ol',
- '<li', 'Item 4.3.1', '/li',
- '<li', 'Item 4.3.2', '/li',
- '/ol',
- '/li',
- '/ol',
- '/li',
- '<li', 'Item 5',
- '<ol',
- '<li', 'Item 5.1', '/li',
- '<li', 'Item 5.2', '/li',
- '/ol',
- '/li',
- '/ol'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->nestedList($list, 'ol');
- $expected = array(
- '<ol',
- '<li', 'Item 1', '/li',
- '<li', 'Item 2',
- '<ol', '<li', 'Item 2.1', '/li', '/ol',
- '/li',
- '<li', 'Item 3', '/li',
- '<li', 'Item 4',
- '<ol',
- '<li', 'Item 4.1', '/li',
- '<li', 'Item 4.2', '/li',
- '<li', 'Item 4.3',
- '<ol',
- '<li', 'Item 4.3.1', '/li',
- '<li', 'Item 4.3.2', '/li',
- '/ol',
- '/li',
- '/ol',
- '/li',
- '<li', 'Item 5',
- '<ol',
- '<li', 'Item 5.1', '/li',
- '<li', 'Item 5.2', '/li',
- '/ol',
- '/li',
- '/ol'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->nestedList($list, array('class'=>'list'));
- $expected = array(
- array('ul' => array('class' => 'list')),
- '<li', 'Item 1', '/li',
- '<li', 'Item 2',
- array('ul' => array('class' => 'list')), '<li', 'Item 2.1', '/li', '/ul',
- '/li',
- '<li', 'Item 3', '/li',
- '<li', 'Item 4',
- array('ul' => array('class' => 'list')),
- '<li', 'Item 4.1', '/li',
- '<li', 'Item 4.2', '/li',
- '<li', 'Item 4.3',
- array('ul' => array('class' => 'list')),
- '<li', 'Item 4.3.1', '/li',
- '<li', 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- '<li', 'Item 5',
- array('ul' => array('class' => 'list')),
- '<li', 'Item 5.1', '/li',
- '<li', 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->nestedList($list, array(), array('class' => 'item'));
- $expected = array(
- '<ul',
- array('li' => array('class' => 'item')), 'Item 1', '/li',
- array('li' => array('class' => 'item')), 'Item 2',
- '<ul', array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
- '/li',
- array('li' => array('class' => 'item')), 'Item 3', '/li',
- array('li' => array('class' => 'item')), 'Item 4',
- '<ul',
- array('li' => array('class' => 'item')), 'Item 4.1', '/li',
- array('li' => array('class' => 'item')), 'Item 4.2', '/li',
- array('li' => array('class' => 'item')), 'Item 4.3',
- '<ul',
- array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
- array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- array('li' => array('class' => 'item')), 'Item 5',
- '<ul',
- array('li' => array('class' => 'item')), 'Item 5.1', '/li',
- array('li' => array('class' => 'item')), 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->nestedList($list, array(), array('even' => 'even', 'odd' => 'odd'));
- $expected = array(
- '<ul',
- array('li' => array('class' => 'odd')), 'Item 1', '/li',
- array('li' => array('class' => 'even')), 'Item 2',
- '<ul', array('li' => array('class' => 'odd')), 'Item 2.1', '/li', '/ul',
- '/li',
- array('li' => array('class' => 'odd')), 'Item 3', '/li',
- array('li' => array('class' => 'even')), 'Item 4',
- '<ul',
- array('li' => array('class' => 'odd')), 'Item 4.1', '/li',
- array('li' => array('class' => 'even')), 'Item 4.2', '/li',
- array('li' => array('class' => 'odd')), 'Item 4.3',
- '<ul',
- array('li' => array('class' => 'odd')), 'Item 4.3.1', '/li',
- array('li' => array('class' => 'even')), 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- array('li' => array('class' => 'odd')), 'Item 5',
- '<ul',
- array('li' => array('class' => 'odd')), 'Item 5.1', '/li',
- array('li' => array('class' => 'even')), 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->nestedList($list, array('class'=>'list'), array('class' => 'item'));
- $expected = array(
- array('ul' => array('class' => 'list')),
- array('li' => array('class' => 'item')), 'Item 1', '/li',
- array('li' => array('class' => 'item')), 'Item 2',
- array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
- '/li',
- array('li' => array('class' => 'item')), 'Item 3', '/li',
- array('li' => array('class' => 'item')), 'Item 4',
- array('ul' => array('class' => 'list')),
- array('li' => array('class' => 'item')), 'Item 4.1', '/li',
- array('li' => array('class' => 'item')), 'Item 4.2', '/li',
- array('li' => array('class' => 'item')), 'Item 4.3',
- array('ul' => array('class' => 'list')),
- array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
- array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
- '/ul',
- '/li',
- '/ul',
- '/li',
- array('li' => array('class' => 'item')), 'Item 5',
- array('ul' => array('class' => 'list')),
- array('li' => array('class' => 'item')), 'Item 5.1', '/li',
- array('li' => array('class' => 'item')), 'Item 5.2', '/li',
- '/ul',
- '/li',
- '/ul'
- );
- $this->assertTags($result, $expected);
- }
- /**
- * testMeta method
- *
- * @return void
- */
- public function testMeta() {
- $result = $this->Html->meta('this is an rss feed', array('controller' => 'posts', 'ext' => 'rss'));
- $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
- $result = $this->Html->meta('rss', array('controller' => 'posts', 'ext' => 'rss'), array('title' => 'this is an rss feed'));
- $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
- $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'));
- $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom')));
- $result = $this->Html->meta('non-existing');
- $this->assertTags($result, array('<meta'));
- $result = $this->Html->meta('non-existing', '/posts.xpp');
- $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'non-existing')));
- $result = $this->Html->meta('non-existing', '/posts.xpp', array('type' => 'atom'));
- $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing')));
- $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'), array('link' => '/articles.rss'));
- $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/articles\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom')));
- $result = $this->Html->meta(array('link' => 'favicon.ico', 'rel' => 'icon'));
- $expected = array(
- 'link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'icon'),
- array('link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'shortcut icon'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->meta('icon', 'favicon.ico');
- $expected = array(
- 'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
- array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
- );
- $this->assertTags($result, $expected);
- $result = $this->Html->meta('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);
- $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
- $this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
- $this->assertPattern('/\s+\/>$/', $result);
- $result = $this->Html->meta('description', 'this is the meta description');
- $this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));
- $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
- $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
- $this->View->expects($this->any())->method('addScript')
- ->with($this->matchesRegularExpression('/^<meta/'));
- $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false));
- $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->assertTags($result, $expected);
- }
- /**
- * testTableCells method
- *
- * @return void
- */
- public function testTableCells() {
- $tr = array(
- 'td content 1',
- array('td content 2', array("width" => "100px")),
- array('td content 3', "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->assertTags($result, $expected);
- $tr = array('td content 1', 'td content 2', 'td content 3');
- $result = $this->Html->tableCells($tr, null, null, true);
- $expected = array(
- '<tr',
- array('td' => array('class' => 'column-1')), 'td content 1', '/td',
- array('td' => array('class' => 'column-2')), 'td content 2', '/td',
- array('td' => array('class' => 'column-3')), 'td content 3', '/td',
- '/tr'
- );
- $this->assertTags($result, $expected);
- $tr = array('td content 1', 'td content 2', 'td content 3');
- $result = $this->Html->tableCells($tr, true);
- $expected = array(
- '<tr',
- array('td' => array('class' => 'column-1')), 'td content 1', '/td',
- array('td' => array('class' => 'column-2')), 'td content 2', '/td',
- array('td' => array('class' => 'column-3')), 'td content 3', '/td',
- '/tr'
- );
- $this->assertTags($result, $expected);
- $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->assertEqual($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->assertEqual($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->assertEqual($expected, $result);
- }
- /**
- * testTag method
- *
- * @return void
- */
- public function testTag() {
- $result = $this->Html->tag('div');
- $this->assertTags($result, '<div');
- $result = $this->Html->tag('div', 'text');
- $this->assertTags($result, '<div', 'text', '/div');
- $result = $this->Html->tag('div', '<text>', 'class-name');
- $this->assertTags($result, array('div' => array('class' => 'class-name'), 'preg:/<text>/', '/div'));
- $result = $this->Html->tag('div', '<text>', array('class' => 'class-name', 'escape' => true));
- $this->assertTags($result, array('div' => array('class' => 'class-name'), '<text>', '/div'));
- }
- /**
- * testUseTag method
- *
- * @return void
- */
- public function testUseTag() {
- $result = $this->Html->useTag('unknowntag');
- $this->assertEqual($result, '');
- $result = $this->Html->useTag('formend');
- $this->assertTags($result, '/form');
- $result = $this->Html->useTag('form', 'url', ' test');
- $this->assertEqual($result, '<form action="url" test>');
- $result = $this->Html->useTag('form', 'example.com', array('test' => 'ok'));
- $this->assertTags($result, array('form' => array('test' => 'ok', 'action' => 'example.com')));
- }
- /**
- * testDiv method
- *
- * @return void
- */
- public function testDiv() {
- $result = $this->Html->div('class-name');
- $this->assertTags($result, array('div' => array('class' => 'class-name')));
- $result = $this->Html->div('class-name', 'text');
- $this->assertTags($result, array('div' => array('class' => 'class-name'), 'text', '/div'));
- $result = $this->Html->div('class-name', '<text>', array('escape' => true));
- $this->assertTags($result, array('div' => array('class' => 'class-name'), '<text>', '/div'));
- }
- /**
- * testPara method
- *
- * @return void
- */
- public function testPara() {
- $result = $this->Html->para('class-name', '');
- $this->assertTags($result, array('p' => array('class' => 'class-name')));
- $result = $this->Html->para('class-name', 'text');
- $this->assertTags($result, array('p' => array('class' => 'class-name'), 'text', '/p'));
- $result = $this->Html->para('class-name', '<text>', array('escape' => true));
- $this->assertTags($result, array('p' => array('class' => 'class-name'), '<text>', '/p'));
- }
- /**
- * 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')
- );
- $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'
- )
- );
- }
- /**
- * testLoadConfig method
- *
- * @return void
- */
- public function testLoadConfig() {
- $path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS;
- $result = $this->Html->loadConfig('htmlhelper_tags', $path);
- $expected = array(
- 'tags' => array(
- 'form' => 'start form',
- 'formend' => 'finish form'
- )
- );
- $this->assertEqual($expected, $result);
- $tags = $this->Html->getAttribute('_tags');
- $this->assertEqual($tags['form'], 'start form');
- $this->assertEqual($tags['formend'], 'finish form');
- $this->assertEqual($tags['selectend'], '</select>');
- $result = $this->Html->loadConfig(array('htmlhelper_minimized.ini', 'ini'), $path);
- $expected = array(
- 'minimizedAttributeFormat' => 'format'
- );
- $this->assertEqual($expected, $result);
- $this->assertEqual($this->Html->getAttribute('_minimizedAttributeFormat'), 'format');
- }
- /**
- * testLoadConfigWrongFile method
- *
- * @return void
- * @expectedException ConfigureException
- */
- public function testLoadConfigWrongFile() {
- $result = $this->Html->loadConfig('wrong_file');
- }
- /**
- * testLoadConfigWrongReader method
- *
- * @return void
- * @expectedException ConfigureException
- */
- public function testLoadConfigWrongReader() {
- $path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS;
- $result = $this->Html->loadConfig(array('htmlhelper_tags', 'wrong_reader'), $path);
- }
- /**
- * test parsing attributes.
- *
- * @return void
- */
- public function testParseAttributeCompact() {
- $helper = new TestHtmlHelper($this->View);
- $compact = array('compact', 'checked', 'declare', 'readonly', 'disabled',
- 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
- foreach ($compact as $attribute) {
- foreach (array('true', true, 1, '1', $attribute) as $value) {
- $attrs = array($attribute => $value);
- $expected = ' ' . $attribute . '="' . $attribute . '"';
- $this->assertEqual($helper->parseAttributes($attrs), $expected, '%s Failed on ' . $value);
- }
- }
- $this->assertEqual($helper->parseAttributes(array('compact')), ' compact="compact"');
- $helper = new Html5TestHelper($this->View);
- $expected = ' require';
- $this->assertEqual($helper->parseAttributes(array('require')), $expected);
- $this->assertEqual($helper->parseAttributes(array('require' => true)), $expected);
- $this->assertEqual($helper->parseAttributes(array('require' => false)), '');
- }
- }
|