views:

368

answers:

1

Hi,

I'm doing unit testing in CakePHP. I want to test two of my controllers. My app has different kinds of users. I want to test the results the app return depending on which type of user is logged in. I don't know, however, how to log in to the app from the controller test case. I tried a couple of approaches without success. 1) I tried to log in using the Users controller and then running my test case, and 2) tried to group a web test case with the controller unit test.

Any help would be greatly appreaciated.

Thanks.

+2  A: 

try Mark-story's article on testing controllers. Not really testing units though are you? By definition a unit is the smallest testable part of an application. Creating such a broad big tests of your app seems like a bad idea since the application can not grow without failing tests. I believe you should try to split the issue into lesser parts. In other words making sure users are identified as proper type, and given that type, they cant access specific information they shouldnt.

Alexander Morland
Thanks for your reply. I'm wondering if you could explain why what I'm trying to do is not unit-testing. I want to test one method in a controller. What this method returns, however, depends on the type of user logged in. That seems to be what you are suggesting: testing that users can't access information they shouldn't. Anyhow, thanks again for your reply.
David Jimenez
A controller method (ie Action) does not actually return anything though, not in any coding sense. It takes input, does any number of verifications and checks, then makes any number of requests of one or more models, then passes data along to the view. Testing this as a whole, is not something that makes sense to me at least.
Alexander Morland