mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding more coverage for HtmlHelperTest and fixing issue where HtmlHelper::meta() was overriding the found type as specified in attribute
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6788 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
6eb4daccd2
commit
b32a196238
2 changed files with 51 additions and 15 deletions
|
@ -184,6 +184,7 @@ class HtmlHelper extends AppHelper {
|
||||||
if (isset($this->__docTypes[$type])) {
|
if (isset($this->__docTypes[$type])) {
|
||||||
return $this->output($this->__docTypes[$type]);
|
return $this->output($this->__docTypes[$type]);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Creates a link to an external resource and handles basic meta tags
|
* Creates a link to an external resource and handles basic meta tags
|
||||||
|
@ -210,7 +211,7 @@ class HtmlHelper extends AppHelper {
|
||||||
|
|
||||||
if (isset($types[$type])) {
|
if (isset($types[$type])) {
|
||||||
$type = $types[$type];
|
$type = $types[$type];
|
||||||
} elseif (!isset($types['type']) && !isset($attributes['type']) && $url !== null) {
|
} elseif (!isset($attributes['type']) && $url !== null) {
|
||||||
if (is_array($url) && isset($url['ext'])) {
|
if (is_array($url) && isset($url['ext'])) {
|
||||||
$type = $types[$url['ext']];
|
$type = $types[$url['ext']];
|
||||||
} else {
|
} else {
|
||||||
|
@ -218,6 +219,7 @@ class HtmlHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
} elseif (isset($attributes['type']) && isset($types[$attributes['type']])) {
|
} elseif (isset($attributes['type']) && isset($types[$attributes['type']])) {
|
||||||
$type = $types[$attributes['type']];
|
$type = $types[$attributes['type']];
|
||||||
|
unset($attributes['type']);
|
||||||
}
|
}
|
||||||
} elseif ($url !== null) {
|
} elseif ($url !== null) {
|
||||||
$inline = $url;
|
$inline = $url;
|
||||||
|
@ -297,15 +299,13 @@ class HtmlHelper extends AppHelper {
|
||||||
$confirmMessage = str_replace("'", "\'", $confirmMessage);
|
$confirmMessage = str_replace("'", "\'", $confirmMessage);
|
||||||
$confirmMessage = str_replace('"', '\"', $confirmMessage);
|
$confirmMessage = str_replace('"', '\"', $confirmMessage);
|
||||||
$htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');";
|
$htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');";
|
||||||
} elseif (isset($htmlAttributes['default'])) {
|
} elseif (isset($htmlAttributes['default']) && $htmlAttributes['default'] == false) {
|
||||||
if ($htmlAttributes['default'] == false) {
|
if (isset($htmlAttributes['onclick'])) {
|
||||||
if (isset($htmlAttributes['onclick'])) {
|
$htmlAttributes['onclick'] .= ' event.returnValue = false; return false;';
|
||||||
$htmlAttributes['onclick'] .= ' event.returnValue = false; return false;';
|
} else {
|
||||||
} else {
|
$htmlAttributes['onclick'] = 'event.returnValue = false; return false;';
|
||||||
$htmlAttributes['onclick'] = 'event.returnValue = false; return false;';
|
|
||||||
}
|
|
||||||
unset($htmlAttributes['default']);
|
|
||||||
}
|
}
|
||||||
|
unset($htmlAttributes['default']);
|
||||||
}
|
}
|
||||||
return $this->output(sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title));
|
return $this->output(sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title));
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
$result = $this->Html->docType('html4-strict');
|
$result = $this->Html->docType('html4-strict');
|
||||||
$expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
|
$expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$this->assertNull($this->Html->docType('non-existing-doctype'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLink() {
|
function testLink() {
|
||||||
|
@ -73,9 +75,7 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
'/a'
|
'/a'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
}
|
|
||||||
|
|
||||||
function testLinkEscape() {
|
|
||||||
$result = $this->Html->link('Next >', '#');
|
$result = $this->Html->link('Next >', '#');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'a' => array('href' => '#'),
|
'a' => array('href' => '#'),
|
||||||
|
@ -84,6 +84,22 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$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));
|
$result = $this->Html->link('Next >', '#', array('escape' => false));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'a' => array('href' => '#'),
|
'a' => array('href' => '#'),
|
||||||
|
@ -91,9 +107,7 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
'/a'
|
'/a'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
}
|
|
||||||
|
|
||||||
function testImageLink() {
|
|
||||||
$result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false);
|
$result = $this->Html->link($this->Html->image('test.gif'), '#', array(), false, false, false);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'a' => array('href' => '#'),
|
'a' => array('href' => '#'),
|
||||||
|
@ -532,12 +546,34 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMeta() {
|
function testMeta() {
|
||||||
$result = $this->Html->meta('this is an rss feed', array('controller'=> 'posts', 'ext' => 'rss'));
|
$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')));
|
$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'));
|
$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')));
|
$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');
|
$result = $this->Html->meta('icon', 'favicon.ico');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
|
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
|
||||||
|
|
Loading…
Add table
Reference in a new issue