shlink/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php

55 lines
1.5 KiB
PHP
Raw Normal View History

2016-07-19 19:19:05 +03:00
<?php
namespace ShlinkioTest\Shlink\Rest\Middleware;
use PHPUnit_Framework_TestCase as TestCase;
use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
class CrossDomainMiddlewareTest extends TestCase
{
/**
* @var CrossDomainMiddleware
*/
protected $middleware;
public function setUp()
{
$this->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);
}
}