resetInstance(); $this->request = new Zend_Controller_Request_Http(); $this->response = new Zend_Controller_Response_Http(); $this->plugin = new Zend_Controller_Plugin_ErrorHandler(); $this->plugin->setRequest($this->request); $this->plugin->setResponse($this->response); } /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. * * @access protected */ protected function tearDown() { } public function testSetErrorHandler() { $this->plugin->setErrorHandler(array( 'module' => 'myfoo', 'controller' => 'bar', 'action' => 'boobaz', )); $this->assertEquals('myfoo', $this->plugin->getErrorHandlerModule()); $this->assertEquals('bar', $this->plugin->getErrorHandlerController()); $this->assertEquals('boobaz', $this->plugin->getErrorHandlerAction()); } public function testSetErrorHandlerModule() { $this->plugin->setErrorHandlerModule('boobah'); $this->assertEquals('boobah', $this->plugin->getErrorHandlerModule()); } public function testSetErrorHandlerController() { $this->plugin->setErrorHandlerController('boobah'); $this->assertEquals('boobah', $this->plugin->getErrorHandlerController()); } public function testSetErrorHandlerAction() { $this->plugin->setErrorHandlerAction('boobah'); $this->assertEquals('boobah', $this->plugin->getErrorHandlerAction()); } public function testPostDispatchNoControllerException() { $this->response->setException(new Zend_Controller_Dispatcher_Exception('Testing controller exception')); $this->request->setModuleName('foo') ->setControllerName('bar') ->setActionName('baz'); $this->plugin->postDispatch($this->request); $this->assertNotNull($this->request->getParam('error_handler')); $errorHandler = $this->request->getParam('error_handler'); $this->assertTrue($errorHandler instanceof ArrayObject); $this->assertEquals(Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER, $errorHandler->type); $this->assertEquals('error', $this->request->getActionName()); $this->assertEquals('error', $this->request->getControllerName()); $this->assertEquals('default', $this->request->getModuleName()); } public function testPostDispatchNoActionException() { $this->response->setException(new Zend_Controller_Action_Exception('Testing action exception', 404)); $this->request->setModuleName('foo') ->setControllerName('bar') ->setActionName('baz'); $this->plugin->postDispatch($this->request); $this->assertNotNull($this->request->getParam('error_handler')); $errorHandler = $this->request->getParam('error_handler'); $this->assertTrue($errorHandler instanceof ArrayObject); $this->assertEquals(Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION, $errorHandler->type); $this->assertEquals('error', $this->request->getActionName()); $this->assertEquals('error', $this->request->getControllerName()); $this->assertEquals('default', $this->request->getModuleName()); } public function testPostDispatchOtherException() { $this->response->setException(new Exception('Testing other exception')); $this->request->setModuleName('foo') ->setControllerName('bar') ->setActionName('baz'); $this->plugin->postDispatch($this->request); $this->assertNotNull($this->request->getParam('error_handler')); $errorHandler = $this->request->getParam('error_handler'); $this->assertTrue($errorHandler instanceof ArrayObject); $this->assertEquals(Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER, $errorHandler->type); $this->assertEquals('error', $this->request->getActionName()); $this->assertEquals('error', $this->request->getControllerName()); $this->assertEquals('default', $this->request->getModuleName()); } public function testPostDispatchThrowsWhenCalledRepeatedly() { $this->response->setException(new Exception('Testing other exception')); $this->request->setModuleName('foo') ->setControllerName('bar') ->setActionName('baz'); $this->plugin->postDispatch($this->request); $this->response->setException(new Zend_Controller_Dispatcher_Exception('Another exception')); try { $this->plugin->postDispatch($this->request); $this->fail('Repeated calls with new exceptions should throw exceptions'); } catch (Exception $e) { $type = get_class($e); $this->assertEquals('Zend_Controller_Dispatcher_Exception', $type); $this->assertEquals('Another exception', $e->getMessage()); } } public function testPostDispatchDoesNothingWhenCalledRepeatedlyWithoutNewExceptions() { $this->response->setException(new Exception('Testing other exception')); $this->request->setModuleName('foo') ->setControllerName('bar') ->setActionName('baz'); $this->plugin->postDispatch($this->request); try { $this->plugin->postDispatch($this->request); } catch (Exception $e) { $this->fail('Repeated calls with no new exceptions should not throw exceptions'); } } public function testPostDispatchWithoutException() { $this->request->setModuleName('foo') ->setControllerName('bar') ->setActionName('baz'); $this->plugin->postDispatch($this->request); $this->assertEquals('baz', $this->request->getActionName()); $this->assertEquals('bar', $this->request->getControllerName()); $this->assertEquals('foo', $this->request->getModuleName()); } public function testPostDispatchErrorRequestIsClone() { $this->response->setException(new Zend_Controller_Dispatcher_Exception('Testing controller exception')); $this->request->setModuleName('foo') ->setControllerName('bar') ->setActionName('baz'); $this->plugin->postDispatch($this->request); $this->assertNotNull($this->request->getParam('error_handler')); $errorHandler = $this->request->getParam('error_handler'); $this->assertTrue($errorHandler instanceof ArrayObject); $this->assertTrue($errorHandler->request instanceof Zend_Controller_Request_Http); $this->assertNotSame($this->request, $errorHandler->request); } public function testPostDispatchQuitsWithFalseUserErrorHandlerParam() { $front = Zend_Controller_Front::getInstance(); $front->resetInstance(); $front->setParam('noErrorHandler', true); $this->response->setException(new Zend_Controller_Dispatcher_Exception('Testing controller exception')); $this->request->setModuleName('foo') ->setControllerName('bar') ->setActionName('baz'); $this->plugin->postDispatch($this->request); $this->assertNull($this->request->getParam('error_handler')); } } // Call Zend_Controller_Plugin_ErrorHandlerTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Controller_Plugin_ErrorHandlerTest::main") { Zend_Controller_Plugin_ErrorHandlerTest::main(); }