/**
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * @return ControllerGuardListener
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $options ModuleOptions */
     $options = $serviceLocator->get('UghAuthorization\\Options\\ModuleOptions');
     /* @var $controllerGuard Guard */
     $controllerGuard = $serviceLocator->get('UghAuthorization\\Guards\\ControllerGuard');
     $viewModel = new ViewModel();
     $viewModel->setTemplate($options->getUnauthorizedViewScript());
     $controllerGuardListener = new ControllerGuardListener($controllerGuard);
     $controllerGuardListener->setErrorViewModel($viewModel);
     return $controllerGuardListener;
 }
 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->setParam("controller", "index");
     $routeMatch->setParam("action", "update");
     $event = new MvcEvent();
     $event->setRouteMatch($routeMatch);
     $event->setApplication($application);
     $controllerGuardMock = $this->getMockBuilder('UghAuthorization\\Guards\\Guard', array('isGranted'))->disableOriginalConstructor()->getMock();
     $controllerGuardMock->expects($this->any())->method('isGranted')->will($this->returnValue(true));
     $controllerGuardListener = new ControllerGuardListener($controllerGuardMock);
     $controllerGuardListener->onGuard($event);
     $this->assertFalse($event->propagationIsStopped());
     $this->assertEmpty($event->getError());
 }