This event listener will listen to all incoming OPTIONS requests and adds the correct headers required for CORS to function properly - all configured on a per-user/resource base.
Author: Espen Hovlandsdal (espen@hovlandsdal.com)
Inheritance: implements Imbo\EventListener\ListenerInterface
Example #1
0
 /**
  * @covers Imbo\EventListener\Cors::invoke
  */
 public function testAddsVaryHeaderContainingOriginRegardlessOfAllowedStatus()
 {
     $this->request->expects($this->any())->method('getMethod')->will($this->returnValue('GET'));
     $route = $this->getMock('Imbo\\Router\\Route');
     $route->expects($this->any())->method('__toString')->will($this->returnValue('index'));
     $this->request->expects($this->any())->method('getRoute')->will($this->returnValue($route));
     // Allowed
     $listener = new Cors(['allowedOrigins' => ['http://imbo-project.org']]);
     $event = $this->getMock('Imbo\\EventManager\\Event');
     $event->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
     $response = $this->getMock('Imbo\\Http\\Response\\Response');
     $response->expects($this->once())->method('setVary')->with('Origin', false);
     $event->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $listener->invoke($event);
     // Disallowed
     $listener = new Cors(['allowedOrigins' => []]);
     $event = $this->getMock('Imbo\\EventManager\\Event');
     $event->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
     $response = $this->getMock('Imbo\\Http\\Response\\Response');
     $response->expects($this->once())->method('setVary')->with('Origin', false);
     $event->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $listener->invoke($event);
 }