Source for file HelpersTest.php
Documentation is available at HelpersTest.php
* File for the HelpersTest class
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright (c) Walter O. Haas 2006
* @version $Id: HelpersTest.php 208 2006-05-28 17:59:55Z john $
* @author Walt Haas <haas@xmission.com>
echo "testing Helpers\n";
// Call HelpersTest::main() if this source file is executed directly.
if (!defined("PHPUnit2_MAIN_METHOD")) {
define("PHPUnit2_MAIN_METHOD", "HelpersTest::main");
require_once "PHPUnit2/Framework/TestCase.php";
require_once "PHPUnit2/Framework/TestSuite.php";
// You may remove the following line when all tests have been implemented.
require_once "PHPUnit2/Framework/IncompleteTestError.php";
// root Trax files in the test directory
define("TRAX_ROOT", dirname(__FILE__ ));
require_once 'testenv.php';
require_once "action_view/helpers.php";
require_once "action_controller.php";
require_once "router.php";
require_once "controllers/application.php";
* Extend Helpers class to test protected methods
function __construct($object_name = null, $attribute_name = null) {
function object($object_name = null) {
return parent::object($object_name);
} // class ExtHelpers extends Helpers
* Dummy controller object
} // class DummyController
* Test class for Helpers.
* Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:23:35.
class HelpersTest extends PHPUnit2_Framework_TestCase {
* Runs the test methods of this class.
public static function main() {
require_once "PHPUnit2/TextUI/TestRunner.php";
$suite = new PHPUnit2_Framework_TestSuite("HelpersTest");
$result = PHPUnit2_TextUI_TestRunner::run($suite);
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
protected function setUp() {
Trax::$current_controller_name = 'foo_controller';
Trax::$current_controller_path = '/foo/bar/mumble';
Trax::$current_controller_object = 'nonobject';
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
* @todo Figure out how to test first argument
// No arguments to constructor
$this->assertFalse($h->auto_index);
$this->assertEquals('', $h->object_name);
$this->assertNull($h->attribute_name);
$this->assertEquals('foo_controller', $h->controller_name);
$this->assertEquals('/foo/bar/mumble', $h->controller_path);
$this->assertEquals('nonobject', $h->controller_object);
// Only attribute argument to constructor
$this->assertFalse($h->auto_index);
$this->assertEquals('', $h->object_name);
$this->assertEquals('someattr', $h->attribute_name);
$this->assertEquals('foo_controller', $h->controller_name);
$this->assertEquals('/foo/bar/mumble', $h->controller_path);
$this->assertEquals('nonobject', $h->controller_object);
// Need to figure out how the first argument is used
// and write a test for it.
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
// Test the cdata_section() method of the object
$s = $h->cdata_section('foo');
$this->assertEquals("<![CDATA[foo]]>", $s);
// Test the file function that calls cdata_section()
$this->assertEquals("<![CDATA[foo]]>", $s);
// Test the tag() method of the object
$this->assertEquals("<p />\n",$s);
$s = $h->tag('p', array('id'=> 'a&b'));
$this->assertEquals("<p id=\"a&b\" />\n",$s);
$s = $h->tag('p', array('id'=> 'a&b'),true);
$this->assertEquals("<p id=\"a&b\">\n",$s);
// Test the file function that calls tag()
$this->assertEquals("<p />\n",$s);
$s = tag('p', array('id'=> 'a&b'));
$this->assertEquals("<p id=\"a&b\" />\n",$s);
$s = tag('p', array('id'=> 'a&b'),true);
$this->assertEquals("<p id=\"a&b\">\n",$s);
// Test the content_tag() method of the object
$s = $h->content_tag('p','hello world');
$this->assertEquals("<p >hello world</p>\n",$s);
$s = $h->content_tag('p','hello world',array('class'=> 'content'));
$this->assertEquals("<p class=\"content\">hello world</p>\n",$s);
$s = $h->content_tag('p','hello world',array('id'=> 'a&b'));
$this->assertEquals("<p id=\"a&b\">hello world</p>\n",$s);
// Test the file function that calls content_tag()
$this->assertEquals("<p >hello world</p>\n",$s);
$s = content_tag('p','hello world',array('class'=> 'content'));
$this->assertEquals("<p class=\"content\">hello world</p>\n",$s);
* Test boolean_attribute().
$k = array('foo'=> 'bar', 'mumble'=> 'grumble');
$e->boolean_attribute($k,'foo');
$this->assertEquals(array('foo'=> 'foo', 'mumble'=> 'grumble'), $k);
* Test convert_options().
$k = array('disabled'=> 'foo',
$r = $e->convert_options($k);
$this->assertEquals(array('disabled'=> 'disabled',
// Constructing with no object name and then
// calling object with no argument should return null
$this->assertNull($e->object());
// Create a dummy controller object
Trax::$current_controller_object = $d;
// This should inherit value of current_controller_object
$this->assertEquals('attr value', $e->object('some_attr'));
// This should inherit object name from constructor
$this->assertEquals('attr value', $e->object());
* @todo Implement testValue().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testTo_content_tag().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
// Call HelpersTest::main() if this source file is executed directly.
// -- set Emacs parameters --
// c-hanging-comment-ender-p: nil
|