-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiddlewareTest.php
More file actions
43 lines (37 loc) · 2.53 KB
/
MiddlewareTest.php
File metadata and controls
43 lines (37 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Pdsinterop\PhpSolid;
use Pdsinterop\PhpSolid\Middleware;
const PUBSUB_SERVER = "https://localhost:1234";
function header($header) {
MiddleWareTest::$headers[] = $header;
}
class MiddlewareTest extends \PHPUnit\Framework\TestCase
{
public static $headers = [];
public function testCors() {
Middleware::cors();
$this->assertTrue(in_array("Access-Control-Allow-Origin: *", self::$headers));
$this->assertTrue(in_array("Access-Control-Allow-Headers: *, allow, accept, authorization, content-type, dpop, slug, link", self::$headers));
$this->assertTrue(in_array("Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE, PATCH", self::$headers));
$this->assertTrue(in_array("Access-Control-Max-Age: 1728000", self::$headers));
$this->assertTrue(in_array("Access-Control-Allow-Credentials: true", self::$headers));
$this->assertTrue(in_array("Accept-Patch: text/n3", self::$headers));
$this->assertTrue(in_array("Access-Control-Expose-Headers: Authorization, User, Location, Link, Vary, Last-Modified, ETag, Accept-Patch, Accept-Post, Updates-Via, Allow, WAC-Allow, Content-Length, WWW-Authenticate, MS-Author-Via", self::$headers));
}
public function testCorsWithOrigin() {
$origin = "https://example.com";
$_REQUEST['HTTP_ORIGIN'] = $origin;
Middleware::cors();
$this->assertTrue(in_array("Access-Control-Allow-Origin: $origin", self::$headers));
$this->assertTrue(in_array("Access-Control-Allow-Headers: *, allow, accept, authorization, content-type, dpop, slug, link", self::$headers));
$this->assertTrue(in_array("Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE, PATCH", self::$headers));
$this->assertTrue(in_array("Access-Control-Max-Age: 1728000", self::$headers));
$this->assertTrue(in_array("Access-Control-Allow-Credentials: true", self::$headers));
$this->assertTrue(in_array("Accept-Patch: text/n3", self::$headers));
$this->assertTrue(in_array("Access-Control-Expose-Headers: Authorization, User, Location, Link, Vary, Last-Modified, ETag, Accept-Patch, Accept-Post, Updates-Via, Allow, WAC-Allow, Content-Length, WWW-Authenticate, MS-Author-Via", self::$headers));
}
public function testPubSub() {
Middleware::pubsub();
$this->assertTrue(in_array("updates-via: " . PUBSUB_SERVER, self::$headers));
}
}