/** * * @param ServiceLocatorInterface $serviceLocator * @return RouteGuardListener */ public function createService(ServiceLocatorInterface $serviceLocator) { /* @var $options ModuleOptions */ $options = $serviceLocator->get('UghAuthorization\\Options\\ModuleOptions'); /* @var $routeGuard Guard */ $routeGuard = $serviceLocator->get('UghAuthorization\\Guards\\RouteGuard'); $viewModel = new ViewModel(); $viewModel->setTemplate($options->getUnauthorizedViewScript()); $routeGuardListener = new RouteGuardListener($routeGuard); $routeGuardListener->setErrorViewModel($viewModel); return $routeGuardListener; }
public function testCanAllowAccess() { $eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface'); $eventManager->expects($this->never())->method('trigger'); $application = $this->getMock('Zend\\Mvc\\Application', array(), array(), '', false); $application->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager)); $routeMatch = new RouteMatch(array()); $routeMatch->setMatchedRouteName('secure'); $event = new MvcEvent(); $event->setRouteMatch($routeMatch); $event->setApplication($application); $routeGuardMock = $this->getMockBuilder('UghAuthorization\\Guards\\Guard', array('isGranted'))->disableOriginalConstructor()->getMock(); $routeGuardMock->expects($this->any())->method('isGranted')->will($this->returnValue(true)); $routeGuardListener = new RouteGuardListener($routeGuardMock); $routeGuardListener->onGuard($event); $this->assertFalse($event->propagationIsStopped()); $this->assertEmpty($event->getError()); }