Source for file ActionControllerTest.php
Documentation is available at ActionControllerTest.php
* File for the ActionControllerTest class
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright (c) Walter O. Haas 2006
* @version $Id: ActionControllerTest.php 208 2006-05-28 17:59:55Z john $
* @author Walt Haas <haas@xmission.com>
echo "testing ActionController\n";
// root Trax files in the test directory
define("TRAX_ROOT", dirname(__FILE__ ));
require_once 'testenv.php';
// Call ActionControllerTest::main() if this source file is executed directly.
if (!defined("PHPUnit2_MAIN_METHOD")) {
define("PHPUnit2_MAIN_METHOD", "ActionControllerTest::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";
require_once "router.php";
require_once "inflector.php";
require_once "trax_exceptions.php";
require_once "action_controller.php";
* Test class for ActionController.
* Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:16:01.
* Runs the test methods of this class.
public static function main() {
require_once "PHPUnit2/TextUI/TestRunner.php";
$suite = new PHPUnit2_Framework_TestSuite("ActionControllerTest");
$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() {
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
* @todo Implement test__construct().
* The constructor calls load_router() to load
* routes from config/routes.php
* Test recognize_route().
* recognize_route() sets up a lot of private variables that we
* don't have access to so we can't test it very thoroughly here
// read routes from config/routes.php
// this URL doesn't match any route
$_SERVER['REDIRECT_URL'] = '/~haas/foo/bar';
$this->assertFalse($ac->recognize_route());
// this URL matches but the controller doesn't exist
$_SERVER['REDIRECT_URL'] = '/~haas/nocontroller/foo/bar';
$this->assertFalse($ac->recognize_route());
// this URL matches and the controller is where it should be
$_SERVER['REDIRECT_URL'] = '/~haas/products/bar';
$this->assertTrue($ac->recognize_route());
* Test raise() with default value of code
$ac->raise('text1','text2');
$this->assertTrue(is_a($e,'ActionControllerError'));
$this->assertEquals('Error Message: text1',$e->getMessage());
$this->assertEquals('Error Message: text1',$e->error_message);
$this->assertEquals('text2',$e->error_heading);
$this->assertEquals('404',$e->error_code);
$this->fail('raise() exception with default code not raised');
* Test raise() with specified of code
$ac->raise('text3','text4', 250);
$this->assertTrue(is_a($e,'ActionControllerError'));
$this->assertEquals('Error Message: text3',$e->getMessage());
$this->assertEquals('Error Message: text3',$e->error_message);
$this->assertEquals('text4',$e->error_heading);
$this->assertEquals(250,$e->error_code);
$this->fail('raise() exception with code 250 not raised');
* Test process_route() with an unrecognized route
// read routes from config/routes.php
// this URL doesn't match any route
$_SERVER['REDIRECT_URL'] = '/~haas/foo/bar';
$this->assertTrue(is_a($e,'ActionControllerError'));
$this->assertEquals('Error Message: Failed to load any'
. ' defined routes',$e->getMessage());
$this->assertEquals('Error Message: Failed to load any'
. ' defined routes',$e->error_message);
$this->assertEquals('Controller foo not found',
$this->assertEquals('404',$e->error_code);
$this->fail('raise() exception with default code not raised');
* Test process_route() with missing controller file
// read routes from config/routes.php
// this URL matches default route
$_SERVER['REDIRECT_URL'] = '/~haas/nocontroller/foo/bar';
$this->assertTrue(is_a($e,'ActionControllerError'));
$this->assertEquals('Error Message: Failed to load any'
. ' defined routes',$e->getMessage());
$this->assertEquals('Error Message: Failed to load any'
. ' defined routes',$e->error_message);
$this->assertEquals('Controller nocontroller not found',
$this->assertEquals('404',$e->error_code);
$this->fail('process_route() missing controller file'
. ' exception not raised');
* Test process_route() with missing controller class
// read routes from config/routes.php
// this URL matches default route, but the controller
// file doesn't have a Noclass class
$_SERVER['REDIRECT_URL'] = '/~haas/noclass/foo/bar';
$this->assertTrue(is_a($e,'ActionControllerError'));
$this->assertEquals('Error Message: Failed to instantiate'
. ' controller object "noclass"',
$this->assertEquals('Error Message: Failed to instantiate'
. ' controller object "noclass"',
$this->assertEquals('ActionController error',
$this->assertEquals('500',$e->error_code);
$this->fail('process_route() missing class exception not raised');
* @todo Implement testProcess_route().
// public function testProcess_route() {
// $ac = new ActionController;
// // should invoke CatalogController
// $_SERVER['REDIRECT_URL'] = '/~haas/products/bar';
// // Remove the following line when you implement this test.
// throw new PHPUnit2_Framework_IncompleteTestError;
* FIXME: need controllers with layout undefined, layout=null,
* layout=false, layout=file, layout=method
* @todo Implement testDetermine_layout().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement test__set().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement test__call().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testSet_paths().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testExecute_before_filters().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testAdd_before_filter().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testExecute_after_filters().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testAdd_after_filter().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testAdd_helper().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testRender_partial().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testRedirect_to().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
* @todo Implement testProcess_with_exception().
// Remove the following line when you implement this test.
throw new PHPUnit2_Framework_IncompleteTestError;
// Call ActionControllerTest::main() if this source file is executed directly.
// -- set Emacs parameters --
// c-hanging-comment-ender-p: nil
|