In this recipe, we will learn how to test controller actions and ensure that their views produce the result we expect.
To go through this recipe we need a basic application skeleton to work with, and have the SimpleTest library installed. Go through the entire recipe Setting up the test framework.
We also need test data. Go through the creation of fixtures described in the recipe Creating fixtures and testing model methods.
Create a file named articles_controller.test.php
and place it in your app/tests/cases/controllers
folder, with the following contents:
<?php class ArticlesControllerTestCase extends CakeTestCase { public $fixtures = array('app.article', 'app.user', 'app.vote'); public function testView() { $result = $this->testAction('/articles/view/1', array('return'=>'vars')); $expected = array( 'Article' => array( 'id' => 1, 'title' => 'Article 1', 'body' => 'Body for Article 1' ), 0 => array...