/** * @covers \BjyAuthorize\Guard\Controller::onDispatch */ public function testOnDispatchWithInvalidResource() { $event = $this->createMvcEvent('test-controller', 'test-action'); $this->authorize->expects($this->any())->method('getIdentity')->will($this->returnValue('admin')); $this->authorize->expects($this->any())->method('isAllowed')->will($this->returnValue(false)); $event->expects($this->once())->method('setError')->with(Controller::ERROR); $event->expects($this->at(4))->method('setParam')->with('identity', 'admin'); $event->expects($this->at(5))->method('setParam')->with('controller', 'test-controller'); $event->expects($this->at(6))->method('setParam')->with('action', 'test-action'); $event->expects($this->at(7))->method('setParam')->with('exception', $this->isInstanceOf('BjyAuthorize\\Exception\\UnauthorizedException')); $event->getTarget()->getEventManager()->expects($this->once())->method('trigger')->with(MvcEvent::EVENT_DISPATCH_ERROR, $event); $this->assertNull($this->controllerGuard->onDispatch($event), 'Does not stop event propagation'); }
/** * @covers \BjyAuthorize\Guard\Controller::onDispatch */ public function testOnDispatchWithInvalidResource() { $event = $this->createMvcEvent('test-controller', 'test-action'); $this->authorize->expects($this->any())->method('getIdentity')->will($this->returnValue('admin')); $this->authorize->expects($this->any())->method('isAllowed')->will($this->returnValue(false)); $event->expects($this->once())->method('setError')->with(Controller::ERROR); $event->expects($this->exactly(3))->method('setParam')->with($this->callback(function ($key) { return in_array($key, array('identity', 'controller', 'action')); }), $this->callback(function ($val) { return in_array($val, array('admin', 'test-controller', 'test-action')); })); $event->getTarget()->getEventManager()->expects($this->once())->method('trigger')->with(MvcEvent::EVENT_DISPATCH_ERROR, $event); $this->assertNull($this->controllerGuard->onDispatch($event), 'Does not stop event propagation'); }