options() public method

Handle the OPTIONS requests
public options ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The event instance
Beispiel #1
0
 /**
  * @covers Imbo\EventListener\Cors::options
  */
 public function testSetsCorrectResposeHeadersOnOptionsRequestWhenOriginIsAllowed()
 {
     $listener = new Cors(['allowedOrigins' => ['*'], 'allowedMethods' => ['image' => ['HEAD']], 'maxAge' => 60]);
     $route = $this->getMock('Imbo\\Router\\Route');
     $route->expects($this->once())->method('__toString')->will($this->returnValue('image'));
     $this->request->expects($this->once())->method('getRoute')->will($this->returnValue($route));
     $this->request->headers = $this->getMock('Symfony\\Component\\HttpFoundation\\HeaderBag');
     $this->request->headers->expects($this->at(0))->method('get')->with('Origin')->will($this->returnValue('http://imbo-project.org'));
     $this->request->headers->expects($this->at(1))->method('get')->with('Access-Control-Request-Headers', '')->will($this->returnValue('x-imbo-signature,something-else'));
     $headers = $this->getMock('Symfony\\Component\\HttpFoundation\\HeaderBag');
     $headers->expects($this->once())->method('add')->with(['Access-Control-Allow-Origin' => 'http://imbo-project.org', 'Access-Control-Allow-Methods' => 'OPTIONS, HEAD', 'Access-Control-Allow-Headers' => 'Content-Type, Accept, X-Imbo-Signature', 'Access-Control-Max-Age' => 60]);
     $this->response->headers = $headers;
     $this->response->expects($this->once())->method('setStatusCode')->with(204);
     $this->event->expects($this->once())->method('stopPropagation');
     $listener->options($this->event);
 }