I'm writing some test for an app, I have a controller named Message
accessible only to logged users, with three actions: compose, preview, send.
One cannot access preview if he has not accessed composeAction succesfully
before. I made this check using a session variable and if this variable is
not present when accessing preview the following code of previewAction will
be triggered:

                if (!$this->_data->messageSet) {
                        //$log = new Zend_Log(new Zend_Log_Writer_Firebug());
                        //$log->info("redirect messagectrl");
                        $this->_helper->redirector('compose');
                }

For authentication and acl I use a plugin and the predispatch method in this
way:

class Plugin_Authentication extends Zend_Controller_Plugin_Abstract {   
        public function preDispatch(Zend_Controller_Request_Abstract $request) {
                $auth = Zend_Auth::getInstance();
                if ($auth->hasIdentity()) {
                        // check ACL stuff
                }
                // user not authenticated
                if ($request->getControllerName() != 'login' || 
$request->getActionName()
!=
                                 'index') {
                        // redirect the user to the login page and stop process 
this request
                        $fc = Zend_Controller_Front::getInstance();
                        $this->getResponse()->setRedirect($fc->getBaseUrl() . 
'/login/');
                        //$this->getResponse()->sendResponse();
                        //$this->getRequest()->setDispatched(true);
                        //exit();
                }
        }
}

Now I've written the following tests

        public function testNotLoggedMustRedirect() {
                $this->dispatch('/message/preview');
                $this->assertRedirectTo('/login/');
                //Zend_Debug::dump($this->getResponse()->getHeaders());
        }

The problem is that when I run this test the code from MessageController
will be executed and the Location header is overwritten by /message/compose
instead of /login.

When I call my code from the browser the $log->info("redirect messagectrl");
instruction is triggered only when I'm logged and not when trying without
credentials.

Is this a Zend_Test_* bug or am I missing something??

In every case my interpretation to plugin and redirect behaviour is that
when I'm calling setRedirect into the plugin the controller code will not be
executed? Is that right?

I've tried the commented code in auth plugin, with the exit call to enforce
my opinion, but if I use it in tests, the exit call will interrupt the test.

Thanks for your attention.
-- 
View this message in context: 
http://www.nabble.com/Possible-bug-in-Zend_Test_PHPUnit---tp21535557p21535557.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to