public function testProperlySetUnauthorizedAndTriggerEventOnUnauthorization() { $event = new MvcEvent(); $routeMatch = $this->createRouteMatch(); $application = $this->getMock('Zend\\Mvc\\Application', [], [], '', false); $eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface'); $application->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager)); if (method_exists($eventManager, 'triggerEvent')) { $eventManager->expects($this->once())->method('triggerEvent')->with($event); } else { $eventManager->expects($this->once())->method('trigger')->with(MvcEvent::EVENT_DISPATCH_ERROR); } $routeMatch->setMatchedRouteName('adminRoute'); $event->setRouteMatch($routeMatch); $event->setApplication($application); $identityProvider = $this->getMock('ZfcRbac\\Identity\\IdentityProviderInterface'); $identityProvider->expects($this->any())->method('getIdentityRoles')->will($this->returnValue('member')); $roleProvider = new InMemoryRoleProvider(['member', 'guest']); $roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy()); $routeGuard = new RouteGuard($roleService, ['adminRoute' => 'guest']); $routeGuard->onResult($event); $this->assertTrue($event->propagationIsStopped()); $this->assertEquals(RouteGuard::GUARD_UNAUTHORIZED, $event->getError()); $this->assertInstanceOf('ZfcRbac\\Exception\\UnauthorizedException', $event->getParam('exception')); }