mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Refactoring tests and adding code coverage for HtmlHelper
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6775 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
5584420ac6
commit
a392e5e605
2 changed files with 127 additions and 57 deletions
|
@ -453,31 +453,6 @@ class HtmlHelper extends AppHelper {
|
|||
|
||||
return $this->output($image);
|
||||
}
|
||||
/**
|
||||
* Creates a set of radio widgets.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function radio($fieldName, $options, $inbetween = null, $htmlAttributes = array()) {
|
||||
trigger_error(__('(HtmlHelper::radio) Deprecated: Use FormHelper::radio instead', true), E_USER_WARNING);
|
||||
|
||||
$this->setEntity($fieldName);
|
||||
$value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->value($fieldName);
|
||||
$out = array();
|
||||
|
||||
foreach ($options as $optValue => $optTitle) {
|
||||
$optionsHere = array('value' => $optValue);
|
||||
if (!empty($value) && $optValue == $value) {
|
||||
$optionsHere['checked'] = 'checked';
|
||||
}
|
||||
$parsedOptions = $this->_parseAttributes(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
|
||||
$individualTagName = $this->field() . "_{$optValue}";
|
||||
$out[] = sprintf($this->tags['radio'], $this->model(), $this->field(), $individualTagName, $parsedOptions, $optTitle);
|
||||
}
|
||||
|
||||
$out = join($inbetween, $out);
|
||||
return $this->output($out ? $out : null);
|
||||
}
|
||||
/**
|
||||
* Returns a row of formatted and named TABLE headers.
|
||||
*
|
||||
|
@ -632,6 +607,7 @@ class HtmlHelper extends AppHelper {
|
|||
*
|
||||
* @deprecated 1.2.0.5147
|
||||
* @see FormHelper::input or FormHelper::password
|
||||
* @codeCoverageIgnoreStart
|
||||
*/
|
||||
function password($fieldName, $htmlAttributes = array()) {
|
||||
trigger_error(sprintf(__('Method password() is deprecated in %s: see FormHelper::input or FormHelper::password', true), get_class($this)), E_USER_NOTICE);
|
||||
|
@ -642,6 +618,31 @@ class HtmlHelper extends AppHelper {
|
|||
}
|
||||
return $this->output(sprintf($this->tags['password'], $this->model(), $this->field(), $this->_parseAttributes($htmlAttributes, null, ' ', ' ')));
|
||||
}
|
||||
/**
|
||||
* Creates a set of radio widgets.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function radio($fieldName, $options, $inbetween = null, $htmlAttributes = array()) {
|
||||
trigger_error(__('(HtmlHelper::radio) Deprecated: Use FormHelper::radio instead', true), E_USER_WARNING);
|
||||
|
||||
$this->setEntity($fieldName);
|
||||
$value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->value($fieldName);
|
||||
$out = array();
|
||||
|
||||
foreach ($options as $optValue => $optTitle) {
|
||||
$optionsHere = array('value' => $optValue);
|
||||
if (!empty($value) && $optValue == $value) {
|
||||
$optionsHere['checked'] = 'checked';
|
||||
}
|
||||
$parsedOptions = $this->_parseAttributes(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
|
||||
$individualTagName = $this->field() . "_{$optValue}";
|
||||
$out[] = sprintf($this->tags['radio'], $this->model(), $this->field(), $individualTagName, $parsedOptions, $optTitle);
|
||||
}
|
||||
|
||||
$out = join($inbetween, $out);
|
||||
return $this->output($out ? $out : null);
|
||||
}
|
||||
/**
|
||||
* Creates a textarea widget.
|
||||
*
|
||||
|
@ -800,5 +801,8 @@ class HtmlHelper extends AppHelper {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* @codeCoverageIgnoreEnd
|
||||
*/
|
||||
}
|
||||
?>
|
|
@ -26,15 +26,15 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
uses('view'.DS.'helpers'.DS.'app_helper', 'class_registry', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper',
|
||||
'view'.DS.'helpers'.DS.'html', 'view'.DS.'helpers'.DS.'form');
|
||||
App::import('Core', array('Helper', 'AppHelper', 'ClassRegistry', 'Controller', 'Model'));
|
||||
App::import('Helper', array('Html', 'Form'));
|
||||
|
||||
class TheHtmlTestController extends Controller {
|
||||
var $name = 'TheTest';
|
||||
var $uses = null;
|
||||
}
|
||||
|
||||
class HtmlHelperTest extends UnitTestCase {
|
||||
class HtmlHelperTest extends CakeTestCase {
|
||||
var $html = null;
|
||||
|
||||
function setUp() {
|
||||
|
@ -43,6 +43,38 @@ class HtmlHelperTest extends UnitTestCase {
|
|||
ClassRegistry::addObject('view', $view);
|
||||
}
|
||||
|
||||
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($result, $expected);
|
||||
|
||||
$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($result, $expected);
|
||||
}
|
||||
|
||||
function testLink() {
|
||||
$result = $this->Html->link('/home');
|
||||
$expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/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, true);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
function testLinkEscape() {
|
||||
$result = $this->Html->link('Next >', '#');
|
||||
$expected = '/^<a href="#">Next ><\/a>$/';
|
||||
|
@ -58,7 +90,6 @@ class HtmlHelperTest extends UnitTestCase {
|
|||
|
||||
$result = $this->Html->image('test.gif', array('url' => '#'));
|
||||
$this->assertPattern('/^<a href="#"><img\s+src="img\/test.gif"\s+alt=""\s+\/><\/a>$/', $result);
|
||||
|
||||
}
|
||||
|
||||
function testImageTag() {
|
||||
|
@ -92,53 +123,53 @@ class HtmlHelperTest extends UnitTestCase {
|
|||
|
||||
function testCssLink() {
|
||||
$result = $this->Html->css('screen');
|
||||
$this->assertPattern('/^<link[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+rel="stylesheet"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+type="text\/css"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+href=".*css\/screen\.css"[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<link[^<>]+[^rel|type|href]=[^<>]*>/', $result);
|
||||
$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->assertPattern('/^<link[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+rel="stylesheet"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+type="text\/css"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+href=".*css\/screen\.css"[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<link[^<>]+[^rel|type|href]=[^<>]*>/', $result);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Html->css('screen.css?1234');
|
||||
$this->assertPattern('/^<link[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+rel="stylesheet"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+type="text\/css"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+href=".*css\/screen\.css\?1234"[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<link[^<>]+[^rel|type|href]=[^<>]*>/', $result);
|
||||
$expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/';
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Html->css('http://whatever.com/screen.css?1234');
|
||||
$this->assertPattern('/^<link[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+rel="stylesheet"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+type="text\/css"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<link[^<>]+href="http:\/\/.*\/screen\.css\?1234"[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<link[^<>]+[^rel|type|href]=[^<>]*>/', $result);
|
||||
$expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
Configure::write('Asset.timestamp', true);
|
||||
$result = $this->Html->css('cake.generic');
|
||||
$this->assertPattern('/^<link[^<>]+href=".*css\/cake\.generic\.css\?[0-9]+"[^<>]+\/>$/', $result);
|
||||
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$debug = Configure::read('debug');
|
||||
Configure::write('debug', 0);
|
||||
$result = $this->Html->css('cake.generic');
|
||||
$this->assertPattern('/^<link[^<>]+href=".*css\/cake\.generic\.css"[^<>]+\/>$/', $result);
|
||||
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
Configure::write('Asset.timestamp', 'force');
|
||||
$result = $this->Html->css('cake.generic');
|
||||
$this->assertPattern('/^<link[^<>]+href=".*css\/cake\.generic\.css\?[0-9]+"[^<>]+\/>$/', $result);
|
||||
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
Configure::write('Asset.timestamp', false);
|
||||
Configure::write('debug', $debug);
|
||||
|
||||
Configure::write('Asset.filter.css', 'css.php');
|
||||
$result = $this->Html->css('cake.generic');
|
||||
$this->assertPattern('/^<link[^<>]+href=".*ccss\/cake\.generic\.css"[^<>]+\/>$/', $result);
|
||||
$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);
|
||||
}
|
||||
|
||||
function testCharsetTag() {
|
||||
|
@ -286,16 +317,29 @@ class HtmlHelperTest extends UnitTestCase {
|
|||
$this->assertPattern('/^<meta[^<>]+name="description"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<meta[^<>]+content="this is the meta description"\/>$/', $result);
|
||||
|
||||
|
||||
$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
|
||||
$this->assertPattern('/^<meta[^<>]+name="ROBOTS"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<meta[^<>]+content="ALL"\/>$/', $result);
|
||||
|
||||
$this->assertNull($this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array(), false));
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$result = $view->__scripts[0];
|
||||
|
||||
$this->assertPattern('/^<meta[^<>]+name="ROBOTS"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<meta[^<>]+content="ALL"\/>$/', $result);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function testTableCells() {
|
||||
$tr = array('td content 1',
|
||||
array('td content 2', array("width"=>"100px")),
|
||||
array('td content 3', "width=100px")
|
||||
$tr = array(
|
||||
'td content 1',
|
||||
array('td content 2', array("width" => "100px")),
|
||||
array('td content 3', "width=100px")
|
||||
);
|
||||
$result = $this->Html->tableCells($tr);
|
||||
$this->assertEqual('<tr><td>td content 1</td> <td width="100px">td content 2</td> <td width=100px>td content 3</td></tr>', $result);
|
||||
|
@ -309,7 +353,29 @@ class HtmlHelperTest extends UnitTestCase {
|
|||
$tr = array('td content 1', 'td content 2', 'td content 3');
|
||||
$result = $this->Html->tableCells($tr, true);
|
||||
$this->assertEqual('<tr><td class="column-1">td content 1</td> <td class="column-2">td content 2</td> <td class="column-3">td content 3</td></tr>', $result);
|
||||
}
|
||||
|
||||
function testDiv() {
|
||||
$result = $this->Html->div('class-name');
|
||||
$this->assertEqual($result, '<div class="class-name">');
|
||||
|
||||
$result = $this->Html->div('class-name', 'text');
|
||||
$this->assertEqual($result, '<div class="class-name">text</div>');
|
||||
|
||||
$result = $this->Html->div('class-name', '<text>', array(), true);
|
||||
$this->assertEqual($result, '<div class="class-name"><text></div>');
|
||||
}
|
||||
|
||||
|
||||
function testPara() {
|
||||
$result = $this->Html->para('class-name');
|
||||
$this->assertEqual($result, '<p class="class-name">');
|
||||
|
||||
$result = $this->Html->para('class-name', 'text');
|
||||
$this->assertEqual($result, '<p class="class-name">text</p>');
|
||||
|
||||
$result = $this->Html->para('class-name', '<text>', array(), true);
|
||||
$this->assertEqual($result, '<p class="class-name"><text></p>');
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
|
|
Loading…
Reference in a new issue