|
| 1 | +<?php |
| 2 | + namespace Pdsinterop\PhpSolid; |
| 3 | + |
| 4 | + use Pdsinterop\PhpSolid\Middleware; |
| 5 | + |
| 6 | + const PUBSUB_SERVER = "https://localhost:1234"; |
| 7 | + $headers = []; |
| 8 | + function header($header) { |
| 9 | + MiddleWareTest::$headers[] = $header; |
| 10 | + } |
| 11 | + |
| 12 | + class MiddlewareTest extends \PHPUnit\Framework\TestCase |
| 13 | + { |
| 14 | + public static $headers = []; |
| 15 | + public function testCors() { |
| 16 | + Middleware::cors(); |
| 17 | + $this->assertTrue(in_array("Access-Control-Allow-Origin: *", self::$headers)); |
| 18 | + $this->assertTrue(in_array("Access-Control-Allow-Headers: *, allow, accept, authorization, content-type, dpop, slug, link", self::$headers)); |
| 19 | + $this->assertTrue(in_array("Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE, PATCH", self::$headers)); |
| 20 | + $this->assertTrue(in_array("Access-Control-Max-Age: 1728000", self::$headers)); |
| 21 | + $this->assertTrue(in_array("Access-Control-Allow-Credentials: true", self::$headers)); |
| 22 | + $this->assertTrue(in_array("Accept-Patch: text/n3", self::$headers)); |
| 23 | + $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)); |
| 24 | + } |
| 25 | + |
| 26 | + public function testCorsWithOrigin() { |
| 27 | + $origin = "https://example.com"; |
| 28 | + $_REQUEST['HTTP_ORIGIN'] = $origin; |
| 29 | + |
| 30 | + Middleware::cors(); |
| 31 | + $this->assertTrue(in_array("Access-Control-Allow-Origin: $origin", self::$headers)); |
| 32 | + $this->assertTrue(in_array("Access-Control-Allow-Headers: *, allow, accept, authorization, content-type, dpop, slug, link", self::$headers)); |
| 33 | + $this->assertTrue(in_array("Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE, PATCH", self::$headers)); |
| 34 | + $this->assertTrue(in_array("Access-Control-Max-Age: 1728000", self::$headers)); |
| 35 | + $this->assertTrue(in_array("Access-Control-Allow-Credentials: true", self::$headers)); |
| 36 | + $this->assertTrue(in_array("Accept-Patch: text/n3", self::$headers)); |
| 37 | + $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)); |
| 38 | + } |
| 39 | + |
| 40 | + public function testPubSub() { |
| 41 | + Middleware::pubsub(); |
| 42 | + $this->assertTrue(in_array("updates-via: " . PUBSUB_SERVER, self::$headers)); |
| 43 | + } |
| 44 | + } |
0 commit comments