mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 09:50:17 -06:00
Added first tests to Rest module
This commit is contained in:
parent
fe8ef2030f
commit
f917697b8e
54
module/Rest/test/Middleware/CrossDomainMiddlewareTest.php
Normal file
54
module/Rest/test/Middleware/CrossDomainMiddlewareTest.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
@ -6,6 +6,9 @@
|
||||
<testsuite name="Core">
|
||||
<directory>./module/Core/test</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Rest">
|
||||
<directory>./module/Rest/test</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
|
Loading…
Reference in New Issue
Block a user