1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

OPTIONS tests

This commit is contained in:
J. King 2020-12-01 12:08:45 -05:00
parent 7fa5523a7d
commit 2a0d6e6599
2 changed files with 12 additions and 16 deletions

View file

@ -18,8 +18,8 @@ use Psr\Http\Message\ResponseInterface;
use Laminas\Diactoros\Response\EmptyResponse; use Laminas\Diactoros\Response\EmptyResponse;
class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
protected const ACCEPTED_TYPES_OPML = ["text/xml", "application/xml", "text/x-opml"]; protected const ACCEPTED_TYPES_OPML = ["application/xml", "text/xml", "text/x-opml"];
protected const ACCEPTED_TYPES_JSON = ["application/json", "text/json"]; protected const ACCEPTED_TYPES_JSON = ["application/json"];
protected const TOKEN_LENGTH = 32; protected const TOKEN_LENGTH = 32;
public const VERSION = "2.0.25"; public const VERSION = "2.0.25";
@ -140,7 +140,7 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
array_unshift($allowed, "HEAD"); array_unshift($allowed, "HEAD");
} }
return new EmptyResponse(204, [ return new EmptyResponse(204, [
'Allow' => implode(",", $allowed), 'Allow' => implode(", ", $allowed),
'Accept' => implode(", ", $url === "/import" ? self::ACCEPTED_TYPES_OPML : self::ACCEPTED_TYPES_JSON), 'Accept' => implode(", ", $url === "/import" ? self::ACCEPTED_TYPES_OPML : self::ACCEPTED_TYPES_JSON),
]); ]);
} else { } else {

View file

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\REST\NextcloudNews; namespace JKingWeb\Arsse\TestCase\REST\Miniflux;
use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\User; use JKingWeb\Arsse\User;
@ -98,20 +98,14 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
public function provideInvalidPaths(): array { public function provideInvalidPaths(): array {
return [ return [
["/", "GET", 404], ["/", "GET", 404],
["/", "OPTIONS", 404],
["/me", "POST", 405, "GET"], ["/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", '<data/>', ['Content-Type' => "application/xml"]));
$exp = new EmptyResponse(400);
$this->assertMessage($exp, $this->req("PUT", "/folders/1", '<data/>'));
$this->assertMessage($exp, $this->req("PUT", "/folders/1", '<data/>', ['Content-Type' => null]));
}
/** @dataProvider provideOptionsRequests */ /** @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, [ $exp = new EmptyResponse(204, [
'Allow' => $allow, 'Allow' => $allow,
'Accept' => $accept, 'Accept' => $accept,
@ -121,9 +115,11 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
public function provideOptionsRequests(): array { public function provideOptionsRequests(): array {
return [ return [
["/feeds", "HEAD,GET,POST", "application/json"], ["/feeds", "HEAD, GET, POST", "application/json"],
["/feeds/2112", "DELETE", "application/json"], ["/feeds/2112", "HEAD, GET, PUT, DELETE", "application/json"],
["/user", "HEAD,GET", "application/json"], ["/me", "HEAD, GET", "application/json"],
["/users/someone", "HEAD, GET", "application/json"],
["/import", "POST", "application/xml, text/xml, text/x-opml"],
]; ];
} }
} }