==== Testing a controller ====
This entry is the result of a forum thread. "The section Testing an HTTP GET on the Controller" doesn't work yet. It is on the front burner until the procedure and code does work. Watch the thread "functional tests (http://forum.akelos.org/discussion/123/)" for progress.
=== General Setup ===
Definitions/variables:
* **project** - The name at the root of your project
* **root-folder** - The whole path up to your project, such as
- Linux: /home/alan/develop/php
* **docroot** - The place where Apache has direct access, such as
- Linux: /var/www/html
* **server** - The base of the URL to access your web server, such as http://localhost
* **name** - The name of the controller that you are writing the test for.
-------------------------------
- Make **project**/test/fixtures/public folder visible to your web server:
- Linux:
- With a link:\\ ln -s **project**/test/fixtures/public **docroot**/**project**_test
- With a virtual server.\\ This approach requires that you be able to create a virtual server by editing httpd.conf. Make the docroot of your server point to **project**/test/fixtures/public.
- In **project**/config/config.php, add a line to tell Akelos where the testing URL is:
- Linux:
- With a link:\\ defined('AK_TESTING_URL') ? null : define('AK_TESTING_URL', '**server**/**project**_test');
- With a virtual server:\\ defined('AK_TESTING_URL') ? null : define('AK_TESTING_URL', '**server**);
- With your editor, open a [[http://www.lastcraft.com/web_tester_documentation.php|simple test web test case]] in **project**/test/functional/controllers/**name**_controller.php. Please note that "name" and "Name" in this illustration is the name of your controller. It will look something like this:\\
assertTrue(false, 'NameController has not been tested');
}
}
ak_test('NameControllerTest',true);
?>
To run the whole suite of tests in the above file, open a terminal window and enter:\\
cd **root-folder**/**project**\\
./script/test test/functional/controllers/**name**_controller.php\\ \\
=== Testing an HTTP GET on the Controller ===
Add the following method to the above test:\\
function test_should_get_index()
{
$this->setMaximumRedirects(0);
$this->get(AK_TESTING_URL.'/name/');
$this->assertResponse(200);
}
This test is presently giving a response of 500 instead of the expected 200. This author, alake, doesn't know how to adjust this code for the desired result.