Skip to content

Commit

Permalink
Adding tests for HtmlHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelle Henkens committed Sep 7, 2011
1 parent 9587892 commit e6826fe
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -211,6 +211,14 @@ public function testLink() {
);
$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' => '#'),
Expand Down Expand Up @@ -435,6 +443,9 @@ public function testThemeAssetsInMainWebrootPath() {
* @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);
Expand Down Expand Up @@ -786,6 +797,8 @@ public function testCharsetTag() {
* @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');
Expand Down Expand Up @@ -847,6 +860,28 @@ public function testBreadcrumb() {
'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);
}

/**
Expand Down Expand Up @@ -1156,6 +1191,12 @@ public function testMeta() {
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')));
Expand Down Expand Up @@ -1285,6 +1326,9 @@ public function testTag() {
* @return void
*/
public function testUseTag() {
$result = $this->Html->useTag('unknowntag');
$this->assertEqual($result, '');

$result = $this->Html->useTag('formend');
$this->assertTags($result, '/form');

Expand Down Expand Up @@ -1334,6 +1378,8 @@ public function testPara() {
* @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');
Expand Down

0 comments on commit e6826fe

Please sign in to comment.