The standard site controller renders actionIndex with
$this->render('index');
How does it know to look in the site folder to find index?
I ask because when I run a unit test on a controller action, this fails. I have to modify it to
$this->render('/site/index');
I’ve tried all sorts of includes in the tests, but haven’t managed to make them work without modifying the controller. How can I make the test work without having to modify the controller?
Unfortunately, that does not seem to work when running a test.
I’m fairly new to test driven development. I was going to create a simple test for each action. Just to check for a piece of text on each page. Then use functional tests for more in depth testing. I was going to do this because unit tests run quicker, and I didn’t think it would take very long to write them. However this problem combined with another (I can’t work out how to access the rendered page from the test) has led me to abandon this. I’ll just write functional test as you suggest.
I suppose you created a controller instance and then called the action. That’s why it doesn’t really work: The framework does much more before it calls a controller action: Init the application, use an URL manager to inspect $_GET to find the controller and action, etc. etc.
You’d have to emulate all request parameters, create an application and call run() to really create the same conditions. Much more cumbersome than using functional tests right away.