diff --git a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php new file mode 100644 index 00000000..92656c82 --- /dev/null +++ b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php @@ -0,0 +1,54 @@ +middleware = new CrossDomainMiddleware(); + } + + /** + * @test + */ + public function anyRequestIncludesTheAllowAccessHeader() + { + $response = $this->middleware->__invoke( + ServerRequestFactory::fromGlobals(), + new Response(), + function ($req, $resp) { + return $resp; + } + ); + + $headers = $response->getHeaders(); + $this->assertArrayHasKey('Access-Control-Allow-Origin', $headers); + $this->assertArrayNotHasKey('Access-Control-Allow-Headers', $headers); + } + + /** + * @test + */ + public function optionsRequestIncludesMoreHeaders() + { + $request = ServerRequestFactory::fromGlobals(['REQUEST_METHOD' => 'OPTIONS']); + + $response = $this->middleware->__invoke($request, new Response(), function ($req, $resp) { + return $resp; + }); + + $headers = $response->getHeaders(); + $this->assertArrayHasKey('Access-Control-Allow-Origin', $headers); + $this->assertArrayHasKey('Access-Control-Allow-Headers', $headers); + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 61fefa13..2c43e876 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,6 +6,9 @@ ./module/Core/test + + ./module/Rest/test +