From 2a0d6e659996997a6798b96d4f8089eca4d500e1 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Tue, 1 Dec 2020 12:08:45 -0500 Subject: [PATCH] OPTIONS tests --- lib/REST/Miniflux/V1.php | 6 +++--- tests/cases/REST/Miniflux/TestV1.php | 22 +++++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/REST/Miniflux/V1.php b/lib/REST/Miniflux/V1.php index 887d61f..c2e84dd 100644 --- a/lib/REST/Miniflux/V1.php +++ b/lib/REST/Miniflux/V1.php @@ -18,8 +18,8 @@ use Psr\Http\Message\ResponseInterface; use Laminas\Diactoros\Response\EmptyResponse; class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { - protected const ACCEPTED_TYPES_OPML = ["text/xml", "application/xml", "text/x-opml"]; - protected const ACCEPTED_TYPES_JSON = ["application/json", "text/json"]; + protected const ACCEPTED_TYPES_OPML = ["application/xml", "text/xml", "text/x-opml"]; + protected const ACCEPTED_TYPES_JSON = ["application/json"]; protected const TOKEN_LENGTH = 32; public const VERSION = "2.0.25"; @@ -140,7 +140,7 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { array_unshift($allowed, "HEAD"); } return new EmptyResponse(204, [ - 'Allow' => implode(",", $allowed), + 'Allow' => implode(", ", $allowed), 'Accept' => implode(", ", $url === "/import" ? self::ACCEPTED_TYPES_OPML : self::ACCEPTED_TYPES_JSON), ]); } else { diff --git a/tests/cases/REST/Miniflux/TestV1.php b/tests/cases/REST/Miniflux/TestV1.php index c62f0c0..a66a890 100644 --- a/tests/cases/REST/Miniflux/TestV1.php +++ b/tests/cases/REST/Miniflux/TestV1.php @@ -4,7 +4,7 @@ * See LICENSE and AUTHORS files for details */ declare(strict_types=1); -namespace JKingWeb\Arsse\TestCase\REST\NextcloudNews; +namespace JKingWeb\Arsse\TestCase\REST\Miniflux; use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\User; @@ -98,20 +98,14 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { public function provideInvalidPaths(): array { return [ ["/", "GET", 404], + ["/", "OPTIONS", 404], ["/me", "POST", 405, "GET"], + ["/me/", "GET", 404], ]; } - public function xtestRespondToInvalidInputTypes(): void { - $exp = new EmptyResponse(415, ['Accept' => "application/json"]); - $this->assertMessage($exp, $this->req("PUT", "/folders/1", '', ['Content-Type' => "application/xml"])); - $exp = new EmptyResponse(400); - $this->assertMessage($exp, $this->req("PUT", "/folders/1", '')); - $this->assertMessage($exp, $this->req("PUT", "/folders/1", '', ['Content-Type' => null])); - } - /** @dataProvider provideOptionsRequests */ - public function xtestRespondToOptionsRequests(string $url, string $allow, string $accept): void { + public function testRespondToOptionsRequests(string $url, string $allow, string $accept): void { $exp = new EmptyResponse(204, [ 'Allow' => $allow, 'Accept' => $accept, @@ -121,9 +115,11 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { public function provideOptionsRequests(): array { return [ - ["/feeds", "HEAD,GET,POST", "application/json"], - ["/feeds/2112", "DELETE", "application/json"], - ["/user", "HEAD,GET", "application/json"], + ["/feeds", "HEAD, GET, POST", "application/json"], + ["/feeds/2112", "HEAD, GET, PUT, DELETE", "application/json"], + ["/me", "HEAD, GET", "application/json"], + ["/users/someone", "HEAD, GET", "application/json"], + ["/import", "POST", "application/xml, text/xml, text/x-opml"], ]; } }