I have a controller function that i'm trying to test but can't because of the authorization component.
If have read both http:cakephp.1045679.n5.nabble.com/testing-a-controller-s-add-action-td1311830.html and http:www.mark-story.com/posts/view/testing-cakephp-controllers-the-hard-way but when i run the test it still redirects me to the login page which makes me believe that I don't have the correct understanding of mocking the Auth component. Here is my code, my problem is on the function called test_exampleOfOne (which is a fake test, I just want to get the concept working before applying it to a functional controller. test_exampleOfOne simply returns the number 44) <?php App::import('Component', 'Auth'); App::import('Controller', 'Users'); class TestUsersController extends UsersController { var $name = 'Users'; var $autoRender = false; function redirect($url, $status = null, $exit = true) { $this->redirectUrl = $url; } function render($action = null, $layout = null, $file = null) { $this->renderedAction = $action; } function _stop($status = 0) { $this->stopped = $status; } } class UsersControllerTest extends CakeTestCase { function startCase() { echo ' Starting Test Case'; } function endCase() { echo ' Ending Test Case'; } function startTest($method) { echo ' Starting method ' . $method . ''; $this->UsersController = new TestUsersController(); //$this->UsersController->initialize($this->UsersController); Mock::generate('AuthComponent'); $this->UsersController->Auth = new MockAuthComponent(); } function endTest($method) { echo ' '; } function test_exampleOfOne() { $this->UsersController->Auth->setReturnValue('user',1); $this->Users->Session->write('Auth.User', array( 'id' => 1, 'username' => 'markstory', )); $result = $this->testAction('/users/exampleOfOne'); $this->assertEqual($result, 44); ?> -- View this message in context: http://cakephp.1045679.n5.nabble.com/Mocking-the-controller-validation-on-testcases-tp3411358p3411358.html Sent from the CakePHP mailing list archive at Nabble.com. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php