Hello--

I'm attempting to override the redirect/render/stop methods when
executing tests and I'm trying to avoid using a constant after reading
messages by Mark Story. It makes sense why you would simply override
the method in the test controller, rather than with the constant.

However, this is not working.

If I use a constant and override the method in an if statement inside
the real controller this works like a charm.

However, if I attempt to follow the same methods as described here:
http://mark-story.com/posts/view/testing-cakephp-controllers-the-hard-way

It still performs the redirect. I've put this code in my test case
file:

=====

<?
php
/* Users Test cases generated on: 2010-10-20 09:10:45 : 1287581445*/
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 UsersControllerTestCase extends CakeTestCase {
  function testDelete() {
    $user = $this->Users->User->find('first',array('conditions' =>
array('User.active' => 1), 'recursive' => 0));
    $id = $user['User']['id'];
    $result = $this->testAction('/users/delete/' . $id, array('return'
=> 'view'));
    $this->assertEqual($this->redirectUrl, array('action' =>
'index'));
    $this->assertEqual($this->Users->Session-
>read('Message.flash.message'), 'User deleted');
  }
}

=====

Now I realize that I'm still using "testAction" rather than doing it
"the hard way", but from what I understand from his post, this method
of overriding the redirect method should work. He says,

=~=~=
"You may have noticed that I created a subclass of the test subject,
this lets me do a few things. First I can test functions that call
redirect(), as they no longer redirect. I can also call methods that
use $this->_stop() as they no longer halt script execution.
Furthermore, I override Controller::render() so I can test actions
that use render() without having to deal with piles of HTML. I
personally don’t do many tests that assert the html of my views
because I find it takes too much time and is tedious. Lastly, I set
$autoRender to false just in case."
=~=~=

So. What am I missing? I'm using Cake 1.3.4. I can't find anything on
this subject on-line. Thank you!

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en

Reply via email to