Esempio n. 1
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $sm = $e->getApplication()->getServiceManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $this->customLayout($e);
     //403 跳转 bzhang
     $redirectUri = $e->getRequest()->getRequestURI();
     $redirectUri = urlencode($redirectUri);
     $strategy = new RedirectionStrategy();
     //        $strategy->setRedirectRoute('user',array('action'=>'unauthorized'),array('query'=>array('redirect'=>$redirectUri)));
     $strategy->setRedirectUri('/test_qoros/user/unauthorized?redirect=' . $redirectUri);
     $eventManager->attach($strategy);
 }
 /**
  * @covers \BjyAuthorize\View\RedirectionStrategy::onDispatchError
  * @covers \BjyAuthorize\View\RedirectionStrategy::setRedirectUri
  */
 public function testWillRedirectToRouteOnSetUriWithApplicationError()
 {
     $this->strategy->setRedirectUri('http://www.example.org/');
     $mvcEvent = $this->getMock('Zend\\Mvc\\MvcEvent');
     $response = $this->getMock('Zend\\Http\\Response');
     $routeMatch = $this->getMock('Zend\\Mvc\\Router\\RouteMatch', array(), array(), '', false);
     $route = $this->getMock('Zend\\Mvc\\Router\\RouteInterface');
     $headers = $this->getMock('Zend\\Http\\Headers');
     $exception = $this->getMock('BjyAuthorize\\Exception\\UnauthorizedException');
     $mvcEvent->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $mvcEvent->expects($this->any())->method('getRouteMatch')->will($this->returnValue($routeMatch));
     $mvcEvent->expects($this->any())->method('getRouter')->will($this->returnValue($route));
     $mvcEvent->expects($this->any())->method('getError')->will($this->returnValue(Application::ERROR_EXCEPTION));
     $mvcEvent->expects($this->any())->method('getParam')->with('exception')->will($this->returnValue($exception));
     $response->expects($this->any())->method('getHeaders')->will($this->returnValue($headers));
     $response->expects($this->once())->method('setStatusCode')->with(302);
     $headers->expects($this->once())->method('addHeaderLine')->with('Location', 'http://www.example.org/');
     $mvcEvent->expects($this->once())->method('setResponse')->with($response);
     $this->strategy->onDispatchError($mvcEvent);
 }