1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JDesrosiers\Silex\Provider\Tests; |
4
|
|
|
|
5
|
|
|
use JDesrosiers\Silex\Provider\CorsServiceProvider; |
6
|
|
|
use Silex\Application; |
7
|
|
|
use Symfony\Component\HttpKernel\Client; |
8
|
|
|
|
9
|
|
|
class CorsEnableApplicationTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
protected $client; |
12
|
|
|
|
13
|
|
|
public function setUp() |
14
|
|
|
{ |
15
|
|
|
$app = new Application(); |
16
|
|
|
$app["debug"] = true; |
17
|
|
|
$app->register(new CorsServiceProvider()); |
18
|
|
|
|
19
|
|
|
$app->get("/foo", function () { |
20
|
|
|
return "foo"; |
21
|
|
|
}); |
22
|
|
|
|
23
|
|
|
$app->get("/bar", function () { |
24
|
|
|
return "bar"; |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
$this->client = new Client($app["cors-enabled"]($app), ["HTTP_ORIGIN" => "http://www.foo.com"]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testFooPreflight() |
31
|
|
|
{ |
32
|
|
|
$this->client->request("OPTIONS", "/foo"); |
33
|
|
|
$response = $this->client->getResponse(); |
34
|
|
|
|
35
|
|
|
$this->assertTrue($response->isEmpty()); |
36
|
|
|
$this->assertTrue($response->headers->has("Access-Control-Allow-Origin")); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testBarPreflight() |
40
|
|
|
{ |
41
|
|
|
$this->client->request("OPTIONS", "/bar"); |
42
|
|
|
$response = $this->client->getResponse(); |
43
|
|
|
|
44
|
|
|
$this->assertTrue($response->isEmpty()); |
45
|
|
|
$this->assertTrue($response->headers->has("Access-Control-Allow-Origin")); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testFooController() |
49
|
|
|
{ |
50
|
|
|
$this->client->request("GET", "/foo"); |
51
|
|
|
$response = $this->client->getResponse(); |
52
|
|
|
|
53
|
|
|
$this->assertTrue($response->isOk()); |
54
|
|
|
$this->assertTrue($response->headers->has("Access-Control-Allow-Origin")); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testBarController() |
58
|
|
|
{ |
59
|
|
|
$this->client->request("GET", "/bar"); |
60
|
|
|
$response = $this->client->getResponse(); |
61
|
|
|
|
62
|
|
|
$this->assertTrue($response->isOk()); |
63
|
|
|
$this->assertTrue($response->headers->has("Access-Control-Allow-Origin")); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|