Tests run properly now - need to add more of them into /libs/helpers/html.php!

Data validation should work - not tested (will do it tomorrow).



git-svn-id: https://svn.cakephp.org/repo/trunk/cake@265 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
brego 2005-06-22 01:20:19 +00:00
parent 38ddea527e
commit dd5f22418e
5 changed files with 385 additions and 336 deletions

View file

@ -186,81 +186,6 @@ class Controller extends Template
call_user_func_array(array(&$this, $action), $args);
}
/**
* Returns value of $tag_name. False is the tag does not exist.
*
* @param string $tag_name
* @return unknown Value of the named tag.
*/
function tagValue ($tag_name)
{
return isset($this->params['data'][$tag_name])? $this->params['data'][$tag_name]: false;
}
/**
* Returns number of errors in a submitted FORM.
*
* @return int Number of errors
*/
function validate ()
{
$args = func_get_args();
$errors = call_user_func_array(array(&$this, 'validateErrors'), $args);
return count($errors);
}
/**
* Validates a FORM according to the rules set up in the Model.
*
* @return int Number of errors
*/
function validateErrors ()
{
$objects = func_get_args();
if (!count($objects)) return false;
$errors = array();
foreach ($objects as $object)
{
$errors = array_merge($errors, $object->invalidFields($object->data));
}
return $this->validationErrors = (count($errors)? $errors: false);
}
/**
* Returns a formatted error message for given FORM field, NULL if no errors.
*
* @param string $field
* @param string $text
* @return string If there are errors this method returns an error message, else NULL.
*/
function tagErrorMsg ($field, $text)
{
$error = $this->tagIsInvalid($field);
if (0 == $error)
{
return sprintf(SHORT_ERROR_MESSAGE, is_array($text)? (empty($text[$error-1])? 'Error in field': $text[$error-1]): $text);
}
else
{
return null;
}
}
/**
* Returns false if given FORM field has no errors. Otherwise it returns the constant set in the array Model->validationErrors.
*
* @param unknown_type $field
* @return unknown
*/
function tagIsInvalid ($field)
{
return empty($this->validationErrors[$field])? 0: $this->validationErrors[$field];
}
/**
* Displays an error page to the user. Uses layouts/error.html to render the page.
*

View file

@ -22,7 +22,7 @@
* @copyright Copyright (c) 2005, Cake Authors/Developers
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
* @package cake
* @subpackage cake.libs
* @subpackage cake.libs.helpers
* @since Cake v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
@ -30,8 +30,31 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Html helper library.
*
* @package cake
* @subpackage cake.libs.helpers
* @since Cake v 0.9.1
*
*/
class HtmlHelper
{
/**
* Breadcrumbs.
*
* @var array
* @access private
*/
var $_crumbs = array();
var $base = null;
var $here = null;
var $params = array();
var $action = null;
var $data = null;
/**
* Returns given string trimmed to given length, adding an ending (default: "..") if necessary.
*
@ -51,21 +74,19 @@ class HtmlHelper
* @param string $url
* @return string Full constructed URL as a string.
*/
function url($url=null)
function urlFor($url=null)
{
global $controller;
if (empty($url))
{
return $controller->here;
return $this->here;
}
elseif ($url[0] == '/')
{
$out = $controller->base . $url;
$out = $this->base . $url;
}
else
{
$out = $controller->base . '/' . strtolower($controller->params['controller']) . '/' . $url;
$out = $this->base . '/' . strtolower($this->params['controller']) . '/' . $url;
}
return ereg_replace('&([^a])', '&\1', $out);
@ -101,7 +122,7 @@ class HtmlHelper
return $options? $insert_before.$options.$insert_after: null;
}
}
/**
* Returns an HTML link to $url for given $title, optionally using $html_options and $confirm_message (for "flash").
*
@ -114,7 +135,7 @@ class HtmlHelper
function linkTo($title, $url, $html_options=null, $confirm_message=false)
{
$confirm_message? $html_options['onClick'] = "return confirm('{$confirm_message}')": null;
return sprintf(TAG_LINK, $this->url($url), $this->parseHtmlOptions($html_options), $title);
return sprintf(TAG_LINK, $this->urlFor($url), $this->parseHtmlOptions($html_options), $title);
}
/**
@ -131,7 +152,7 @@ class HtmlHelper
$url = $url? $url: $title;
return sprintf(TAG_LINK, ereg_replace('&([^a])', '&\1', $url), $this->parseHtmlOptions($html_options), $title);
}
/**
* Returns an HTML FORM element.
*
@ -374,7 +395,7 @@ class HtmlHelper
if (empty($email)) $email = $title;
$match = array();
// does the address contain extra attributes?
preg_match('!^(.*)(\?.*)$!', $email, $match);
@ -408,7 +429,7 @@ class HtmlHelper
return sprintf(TAG_MAILTO, $email_encoded, $this->parseHtmlOptions($options, array('encode')), $title_encoded);
}
}
/**
* Returns a LINK element for CSS stylesheets.
*
@ -571,6 +592,80 @@ class HtmlHelper
}
}
/**
* Returns value of $tag_name. False is the tag does not exist.
*
* @param string $tag_name
* @return unknown Value of the named tag.
*/
function tagValue ($tag_name)
{
return isset($this->params['data'][$tag_name])? $this->params['data'][$tag_name]: false;
}
/**
* Returns false if given FORM field has no errors. Otherwise it returns the constant set in the array Model->validationErrors.
*
* @param unknown_type $field
* @return unknown
*/
function tagIsInvalid ($field)
{
return empty($this->validationErrors[$field])? 0: $this->validationErrors[$field];
}
/**
* Returns number of errors in a submitted FORM.
*
* @return int Number of errors
*/
function validate ()
{
$args = func_get_args();
$errors = call_user_func_array(array(&$this, 'validateErrors'), $args);
return count($errors);
}
/**
* Validates a FORM according to the rules set up in the Model.
*
* @return int Number of errors
*/
function validateErrors ()
{
$objects = func_get_args();
if (!count($objects)) return false;
$errors = array();
foreach ($objects as $object)
{
$errors = array_merge($errors, $object->invalidFields($object->data));
}
return $this->validationErrors = (count($errors)? $errors: false);
}
/**
* Returns a formatted error message for given FORM field, NULL if no errors.
*
* @param string $field
* @param string $text
* @return string If there are errors this method returns an error message, else NULL.
*/
function tagErrorMsg ($field, $text)
{
$error = $this->tagIsInvalid($field);
if (0 == $error)
{
return sprintf(SHORT_ERROR_MESSAGE, is_array($text)? (empty($text[$error-1])? 'Error in field': $text[$error-1]): $text);
}
else
{
return null;
}
}
}
?>

View file

@ -90,14 +90,6 @@ class Template extends Object
*/
var $pageTitle = false;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_crumbs = array();
/**
* Choose the layout to be used when rendering.
*
@ -278,7 +270,7 @@ class Template extends Object
}
/**
* Enter description here... Renders a layout. Returns output from _render(). Returns false on error.
* Renders a layout. Returns output from _render(). Returns false on error.
*
* @param string $content_for_layout Content to render in a view
* @return string Rendered output
@ -382,6 +374,11 @@ class Template extends Object
if(class_exists($helperCn)===true);
{
${$helper} = new $helperCn;
${$helper}->base = $this->base;
${$helper}->here = $this->here;
${$helper}->params = $this->params;
${$helper}->action = $this->action;
${$helper}->data = $this->data;
}
}
}
@ -412,19 +409,6 @@ class Template extends Object
///////////////////////////////////////////////////////////////////////////
/**
* Returns given string trimmed to given length, adding an elipsis '..' if necessary.
*
* @param string $string String to trim
* @param int $length Length of returned string, excluding ellipsis
* @return string Trimmed string
*/
function trimTo($string, $length)
{
return substr($string, 0, $length).(strlen($string)>$length? '..': null);
}
/**
* Returns an URL for a combination of controller and action.

View file

@ -38,233 +38,6 @@ class ControllerTest extends UnitTestCase
{
unset($this->controller);
}
function testUrlFor()
{
$result = $this->controller->urlFor('/foo/bar');
$expected = '/ease/foo/bar';
$this->assertEqual($result, $expected);
$result = $this->controller->urlFor('baz');
$expected = '/ease/test/baz';
$this->assertEqual($result, $expected);
$result = $this->controller->urlFor();
$expected = '/cake/test';
$this->assertEqual($result, $expected);
}
function testParseHtmlOptions()
{
$result = $this->controller->parseHtmlOptions(null);
$expected = null;
$this->assertEqual($result, $expected);
$result = $this->controller->parseHtmlOptions(array());
$expected = null;
$this->assertEqual($result, $expected);
$result = $this->controller->parseHtmlOptions(array('class'=>'foo'));
$expected = ' class="foo"';
$this->assertEqual($result, $expected);
$result = $this->controller->parseHtmlOptions(array('class'=>'foo', 'id'=>'bar'), array('class'));
$expected = ' id="bar"';
$this->assertEqual($result, $expected);
$result = $this->controller->parseHtmlOptions(array('class'=>'foo', 'id'=>'bar'), null, '', ' ');
$expected = 'class="foo" id="bar" ';
$this->assertEqual($result, $expected);
}
function testLinkTo()
{
$result = $this->controller->linkTo('Testing <20>', '/test/ok', array('style'=>'color:Red'), 'Sure?');
$expected = '<a href="/ease/test/ok" style="color:Red" onClick="return confirm(\'Sure?\')">Testing <20></a>';
$this->assertEqual($result, $expected);
$result = $this->controller->linkTo('Ok', 'ok');
$expected = '<a href="/ease/test/ok">Ok</a>';
$this->assertEqual($result, $expected);
}
function testLinkOut()
{
$result = $this->controller->linkOut('Sputnik.pl', 'http://www.sputnik.pl/', array('style'=>'color:Red'));
$expected = '<a href="http://www.sputnik.pl/" style="color:Red">Sputnik.pl</a>';
$this->assertEqual($result, $expected);
$result = $this->controller->linkOut('http://sputnik.pl');
$expected = '<a href="http://sputnik.pl">http://sputnik.pl</a>';
$this->assertEqual($result, $expected);
}
function testFormTag()
{
$result = $this->controller->formTag();
$expected = "<form action=\"{$this->controller->here}\" method=\"post\">";
$this->assertEqual($result, $expected);
$result = $this->controller->formTag('foo', 'get');
$expected = '<form action="/ease/test/foo" method="get">';
$this->assertEqual($result, $expected);
$result = $this->controller->formTag('/bar/baz', 'file');
$expected = '<form action="/ease/bar/baz" method="post" enctype="multipart/form-data">';
$this->assertEqual($result, $expected);
}
function testSubmitTag()
{
$result = $this->controller->submitTag();
$expected = '<input type="submit" value="Submit" />';
$this->assertEqual($result, $expected);
$result = $this->controller->submitTag('Foo', array('class'=>'Bar'));
$expected = '<input type="submit" class="Bar" value="Foo" />';
$this->assertEqual($result, $expected);
}
function testInputTag()
{
$result = $this->controller->inputTag('foo');
$expected = '<input name="data[foo]" size="20" value="foo_value" />';
$this->assertEqual($result, $expected);
$result = $this->controller->inputTag('bar', 20, array('class'=>'Foobar'));
$expected = '<input name="data[bar]" class="Foobar" size="20" value="" />';
$this->assertEqual($result, $expected);
}
function testPasswordTag()
{
$result = $this->controller->passwordTag('foo');
$expected = '<input type="password" name="data[foo]" size="20" value="foo_value" />';
$this->assertEqual($result, $expected);
$result = $this->controller->passwordTag('foo', 33, array('class'=>'Bar'));
$expected = '<input type="password" name="data[foo]" class="Bar" size="33" value="foo_value" />';
$this->assertEqual($result, $expected);
}
function testHiddenTag()
{
$result = $this->controller->hiddenTag('foo');
$expected = '<input type="hidden" name="data[foo]" value="foo_value" />';
$this->assertEqual($result, $expected);
$result = $this->controller->hiddenTag('bar', 'baz');
$expected = '<input type="hidden" name="data[bar]" value="baz" />';
$this->assertEqual($result, $expected);
$result = $this->controller->hiddenTag('foobar', null, array('class'=>'Bar'));
$expected = '<input type="hidden" name="data[foobar]" class="Bar" value="foobar_value" />';
$this->assertEqual($result, $expected);
}
function testFileTag()
{
$result = $this->controller->fileTag('bar', array('class'=>'Foo', 'disabled'=>'1'));
$expected = '<input type="file" name="bar" class="Foo" disabled="1" />';
$this->assertEqual($result, $expected);
}
function testAreaTag()
{
$result = $this->controller->areaTag('foo');
$expected = '<textarea name="data[foo]" cols="60" rows="10">foo_value</textarea>';
$this->assertEqual($result, $expected);
$result = $this->controller->areaTag('foo', 33, 33, array('class'=>'Bar'));
$expected = '<textarea name="data[foo]" class="Bar" cols="33" rows="33">foo_value</textarea>';
$this->assertEqual($result, $expected);
}
function testCheckboxTag()
{
$result = $this->controller->checkboxTag('bar');
$expected = '<label for="tag_bar"><input type="checkbox" name="data[bar]" id="tag_bar" />Bar</label>';
$this->assertEqual($result, $expected);
$result = $this->controller->checkboxTag('tofu', 'ToFu title', array('class'=>'Baz'));
$expected = '<label for="tag_tofu"><input type="checkbox" name="data[tofu]" id="tag_tofu" class="Baz" checked="checked" />ToFu title</label>';
$this->assertEqual($result, $expected);
}
function testRadioTags()
{
$result = $this->controller->radioTags('foo', array('foo'=>'Foo', 'bar'=>'Bar'), '---', array('class'=>'Foo'));
$expected = '<label for="tag_foo_foo"><input type="radio" name="data[foo]" id="tag_foo_foo" class="Foo" value="foo" />Foo</label>---<label for="tag_foo_bar"><input type="radio" name="data[foo]" id="tag_foo_bar" class="Foo" value="bar" />Bar</label>';
$this->assertEqual($result, $expected);
$result = $this->controller->radioTags('bar', array());
$expected = null;
$this->assertEqual($result, $expected);
}
function testSelectTag()
{
$result = $this->controller->selectTag('tofu', array('m'=>'male', 'f'=>'female'), 'm', array('class'=>'Outer'), array('class'=>'Inner', 'id'=>'FooID'));
$expected = '<select name="data[tofu]" class="Outer">'."\n".'<option value="" class="Inner" id="FooID"></option>'."\n".'<option value="m" class="Inner" id="FooID" selected="selected">male</option>'."\n".'<option value="f" class="Inner" id="FooID">female</option>'."\n".'</select>';
$this->assertEqual($result, $expected);
$result = $this->controller->selectTag('tofu', array());
$expected = null;
$this->assertEqual($result, $expected);
}
function testTableHeaders()
{
$result = $this->controller->tableHeaders(array('One', 'Two', 'Three'));
$expected = '<tr><th>One</th> <th>Two</th> <th>Three</th></tr>';
$this->assertEqual($result, $expected);
$result = $this->controller->tableHeaders(array('Foo Bar', 'Baz'), array('class'=>'Eco'), array('align'=>'left'));
$expected = '<tr class="Eco"><th align="left">Foo Bar</th> <th align="left">Baz</th></tr>';
$this->assertEqual($result, $expected);
}
function testTableCells()
{
$result = $this->controller->tableCells(array('Foo', 'Bar'));
$expected = '<tr><td>Foo</td> <td>Bar</td></tr>';
$this->assertEqual($result, $expected);
$result = $this->controller->tableCells(array(array('Foo','Bar'),array('Baz','Echo'),array('Nul','Pio')), array('class'=>'Mini'), array('align'=>'left'));
$expected = join("\n", array('<tr class="Mini"><td>Foo</td> <td>Bar</td></tr>', '<tr align="left"><td>Baz</td> <td>Echo</td></tr>', '<tr class="Mini"><td>Nul</td> <td>Pio</td></tr>'));
$this->assertEqual($result, $expected);
}
function testImageTag()
{
$result = $this->controller->imageTag('foo.gif');
$expected = '<img src="/ease'.IMAGES_URL.'foo.gif" alt="" />';
$this->assertEqual($result, $expected);
$result = $this->controller->imageTag('bar/baz.gif', 'Foobar', array('class'=>'Zet'));
$expected = '<img src="/ease'.IMAGES_URL.'bar/baz.gif" alt="Foobar" class="Zet" />';
$this->assertEqual($result, $expected);
}
function testTagValue()
{
$result = $this->controller->tagValue('foo');
$expected = 'foo_value';
$this->assertEqual($result, $expected);
$result = $this->controller->tagValue('bar');
$expected = false;
$this->assertEqual($result, $expected);
}
function testGetCrumbs()
{
$this->controller->addCrumb('Foo', '/bar/foo');
$result = $this->controller->getCrumbs();
$expected = '<a href="/ease">START</a>&raquo;<a href="/ease/bar/foo">Foo</a>';
$this->assertEqual($result, $expected);
}
}
?>

272
tests/libs/helpers/html.php Normal file
View file

@ -0,0 +1,272 @@
<?php
uses('helpers/html');
class HtmlHelperTest extends UnitTestCase
{
var $html;
// constructor of the test suite
function ControllerTest()
{
$this->UnitTestCase('Html helper test');
}
function setUp()
{
$this->html = new HtmlHelper();
$this->html->base = '/ease';
$data = array('foo'=>'foo_value', 'foobar'=>'foobar_value', 'tofu'=>'1');
$params = array('controller'=>'Test', 'action'=>'test_action', 'data'=>$data);
$here = '/cake/test';
$this->html->params = $params;
$this->html->data = $data;
$this->html->here = $here;
$this->html->action = $this->html->params['action'];
$this->html->passed_args = null;
}
function tearDown()
{
unset($this->html);
}
function testTrim()
{
$expected = 'Long ...';
$result = $this->html->trim('Long string', 5, '...');
$this->assertEqual($expected, $result);
}
function testUrlFor()
{
$result = $this->html->urlFor('/foo/bar');
$expected = '/ease/foo/bar';
$this->assertEqual($result, $expected);
$result = $this->html->urlFor('baz');
$expected = '/ease/test/baz';
$this->assertEqual($result, $expected);
$result = $this->html->urlFor();
$expected = '/cake/test';
$this->assertEqual($result, $expected);
}
function testParseHtmlOptions()
{
$result = $this->html->parseHtmlOptions(null);
$expected = null;
$this->assertEqual($result, $expected);
$result = $this->html->parseHtmlOptions(array());
$expected = null;
$this->assertEqual($result, $expected);
$result = $this->html->parseHtmlOptions(array('class'=>'foo'));
$expected = ' class="foo"';
$this->assertEqual($result, $expected);
$result = $this->html->parseHtmlOptions(array('class'=>'foo', 'id'=>'bar'), array('class'));
$expected = ' id="bar"';
$this->assertEqual($result, $expected);
$result = $this->html->parseHtmlOptions(array('class'=>'foo', 'id'=>'bar'), null, '', ' ');
$expected = 'class="foo" id="bar" ';
$this->assertEqual($result, $expected);
}
function testLinkTo()
{
$result = $this->html->linkTo('Testing <20>', '/test/ok', array('style'=>'color:Red'), 'Sure?');
$expected = '<a href="/ease/test/ok" style="color:Red" onClick="return confirm(\'Sure?\')">Testing <20></a>';
$this->assertEqual($result, $expected);
$result = $this->html->linkTo('Ok', 'ok');
$expected = '<a href="/ease/test/ok">Ok</a>';
$this->assertEqual($result, $expected);
}
function testLinkOut()
{
$result = $this->html->linkOut('Sputnik.pl', 'http://www.sputnik.pl/', array('style'=>'color:Red'));
$expected = '<a href="http://www.sputnik.pl/" style="color:Red">Sputnik.pl</a>';
$this->assertEqual($result, $expected);
$result = $this->html->linkOut('http://sputnik.pl');
$expected = '<a href="http://sputnik.pl">http://sputnik.pl</a>';
$this->assertEqual($result, $expected);
}
function testFormTag()
{
$result = $this->html->formTag();
$expected = "<form action=\"{$this->html->here}\" method=\"post\">";
$this->assertEqual($result, $expected);
$result = $this->html->formTag('foo', 'get');
$expected = '<form action="/ease/test/foo" method="get">';
$this->assertEqual($result, $expected);
$result = $this->html->formTag('/bar/baz', 'file');
$expected = '<form action="/ease/bar/baz" method="post" enctype="multipart/form-data">';
$this->assertEqual($result, $expected);
}
function testSubmitTag()
{
$result = $this->html->submitTag();
$expected = '<input type="submit" value="Submit" />';
$this->assertEqual($result, $expected);
$result = $this->html->submitTag('Foo', array('class'=>'Bar'));
$expected = '<input type="submit" class="Bar" value="Foo" />';
$this->assertEqual($result, $expected);
}
function testInputTag()
{
$result = $this->html->inputTag('foo');
$expected = '<input name="data[foo]" size="20" value="foo_value" />';
$this->assertEqual($result, $expected);
$result = $this->html->inputTag('bar', 20, array('class'=>'Foobar'));
$expected = '<input name="data[bar]" class="Foobar" size="20" value="" />';
$this->assertEqual($result, $expected);
}
function testPasswordTag()
{
$result = $this->html->passwordTag('foo');
$expected = '<input type="password" name="data[foo]" size="20" value="foo_value" />';
$this->assertEqual($result, $expected);
$result = $this->html->passwordTag('foo', 33, array('class'=>'Bar'));
$expected = '<input type="password" name="data[foo]" class="Bar" size="33" value="foo_value" />';
$this->assertEqual($result, $expected);
}
function testHiddenTag()
{
$result = $this->html->hiddenTag('foo');
$expected = '<input type="hidden" name="data[foo]" value="foo_value" />';
$this->assertEqual($result, $expected);
$result = $this->html->hiddenTag('bar', 'baz');
$expected = '<input type="hidden" name="data[bar]" value="baz" />';
$this->assertEqual($result, $expected);
$result = $this->html->hiddenTag('foobar', null, array('class'=>'Bar'));
$expected = '<input type="hidden" name="data[foobar]" class="Bar" value="foobar_value" />';
$this->assertEqual($result, $expected);
}
function testFileTag()
{
$result = $this->html->fileTag('bar', array('class'=>'Foo', 'disabled'=>'1'));
$expected = '<input type="file" name="bar" class="Foo" disabled="1" />';
$this->assertEqual($result, $expected);
}
function testAreaTag()
{
$result = $this->html->areaTag('foo');
$expected = '<textarea name="data[foo]" cols="60" rows="10">foo_value</textarea>';
$this->assertEqual($result, $expected);
$result = $this->html->areaTag('foo', 33, 33, array('class'=>'Bar'));
$expected = '<textarea name="data[foo]" class="Bar" cols="33" rows="33">foo_value</textarea>';
$this->assertEqual($result, $expected);
}
function testCheckboxTag()
{
$result = $this->html->checkboxTag('bar');
$expected = '<label for="tag_bar"><input type="checkbox" name="data[bar]" id="tag_bar" />Bar</label>';
$this->assertEqual($result, $expected);
$result = $this->html->checkboxTag('tofu', 'ToFu title', array('class'=>'Baz'));
$expected = '<label for="tag_tofu"><input type="checkbox" name="data[tofu]" id="tag_tofu" class="Baz" checked="checked" />ToFu title</label>';
$this->assertEqual($result, $expected);
}
function testRadioTags()
{
$result = $this->html->radioTags('foo', array('foo'=>'Foo', 'bar'=>'Bar'), '---', array('class'=>'Foo'));
$expected = '<label for="tag_foo_foo"><input type="radio" name="data[foo]" id="tag_foo_foo" class="Foo" value="foo" />Foo</label>---<label for="tag_foo_bar"><input type="radio" name="data[foo]" id="tag_foo_bar" class="Foo" value="bar" />Bar</label>';
$this->assertEqual($result, $expected);
$result = $this->html->radioTags('bar', array());
$expected = null;
$this->assertEqual($result, $expected);
}
function testSelectTag()
{
$result = $this->html->selectTag('tofu', array('m'=>'male', 'f'=>'female'), 'm', array('class'=>'Outer'), array('class'=>'Inner', 'id'=>'FooID'));
$expected = '<select name="data[tofu]" class="Outer">'."\n".'<option value="" class="Inner" id="FooID"></option>'."\n".'<option value="m" class="Inner" id="FooID" selected="selected">male</option>'."\n".'<option value="f" class="Inner" id="FooID">female</option>'."\n".'</select>';
$this->assertEqual($result, $expected);
$result = $this->html->selectTag('tofu', array());
$expected = null;
$this->assertEqual($result, $expected);
}
function testTableHeaders()
{
$result = $this->html->tableHeaders(array('One', 'Two', 'Three'));
$expected = '<tr><th>One</th> <th>Two</th> <th>Three</th></tr>';
$this->assertEqual($result, $expected);
$result = $this->html->tableHeaders(array('Foo Bar', 'Baz'), array('class'=>'Eco'), array('align'=>'left'));
$expected = '<tr class="Eco"><th align="left">Foo Bar</th> <th align="left">Baz</th></tr>';
$this->assertEqual($result, $expected);
}
function testTableCells()
{
$result = $this->html->tableCells(array('Foo', 'Bar'));
$expected = '<tr><td>Foo</td> <td>Bar</td></tr>';
$this->assertEqual($result, $expected);
$result = $this->html->tableCells(array(array('Foo','Bar'),array('Baz','Echo'),array('Nul','Pio')), array('class'=>'Mini'), array('align'=>'left'));
$expected = join("\n", array('<tr class="Mini"><td>Foo</td> <td>Bar</td></tr>', '<tr align="left"><td>Baz</td> <td>Echo</td></tr>', '<tr class="Mini"><td>Nul</td> <td>Pio</td></tr>'));
$this->assertEqual($result, $expected);
}
function testImageTag()
{
$result = $this->html->imageTag('foo.gif');
$expected = '<img src="/ease'.IMAGES_URL.'foo.gif" alt="" />';
$this->assertEqual($result, $expected);
$result = $this->html->imageTag('bar/baz.gif', 'Foobar', array('class'=>'Zet'));
$expected = '<img src="/ease'.IMAGES_URL.'bar/baz.gif" alt="Foobar" class="Zet" />';
$this->assertEqual($result, $expected);
}
function testTagValue()
{
$result = $this->html->tagValue('foo');
$expected = 'foo_value';
$this->assertEqual($result, $expected);
$result = $this->html->tagValue('bar');
$expected = false;
$this->assertEqual($result, $expected);
}
function testGetCrumbs()
{
$this->html->addCrumb('Foo', '/bar/foo');
$result = $this->html->getCrumbs();
$expected = '<a href="/ease">START</a>&raquo;<a href="/ease/bar/foo">Foo</a>';
$this->assertEqual($result, $expected);
}
}
?>