Пример #1
0
 /**
  * @covers \BjyAuthorize\Guard\Route::onRoute
  */
 public function testOnRouteWithInvalidResource()
 {
     $event = $this->createMvcEvent('test-route');
     $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(Route::ERROR);
     $event->expects($this->at(3))->method('setParam')->with('route', 'test-route');
     $event->expects($this->at(4))->method('setParam')->with('identity', 'admin');
     $event->expects($this->at(5))->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->routeGuard->onRoute($event), 'Does not stop event propagation');
 }
Пример #2
0
 /**
  * @covers \BjyAuthorize\Guard\Route::onRoute
  */
 public function testOnRouteWithInvalidResource()
 {
     $event = $this->createMvcEvent('test-route');
     $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(Route::ERROR);
     $event->expects($this->exactly(2))->method('setParam')->with($this->callback(function ($key) {
         return in_array($key, array('identity', 'route'));
     }), $this->callback(function ($val) {
         return in_array($val, array('admin', 'test-route'));
     }));
     $event->getTarget()->getEventManager()->expects($this->once())->method('trigger')->with(MvcEvent::EVENT_DISPATCH_ERROR, $event);
     $this->assertNull($this->routeGuard->onRoute($event), 'Does not stop event propagation');
 }