2017-03-20 01:50:00 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-03-20 01:50:00 +00:00
|
|
|
declare(strict_types=1);
|
2019-12-05 18:02:02 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\REST\NextcloudNews;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2019-12-05 18:02:02 +00:00
|
|
|
use JKingWeb\Arsse\REST\NextcloudNews\Versions;
|
2018-01-05 04:08:53 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2020-01-20 15:40:05 +00:00
|
|
|
use Laminas\Diactoros\Response\JsonResponse as Response;
|
|
|
|
use Laminas\Diactoros\Response\EmptyResponse;
|
2017-03-20 01:50:00 +00:00
|
|
|
|
2019-12-05 18:02:02 +00:00
|
|
|
/** @covers \JKingWeb\Arsse\REST\NextcloudNews\Versions */
|
2017-12-22 03:47:19 +00:00
|
|
|
class TestVersions extends \JKingWeb\Arsse\Test\AbstractTest {
|
2019-10-16 18:42:43 +00:00
|
|
|
public function setUp(): void {
|
2021-02-27 20:24:02 +00:00
|
|
|
parent::setUp();
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-20 01:50:00 +00:00
|
|
|
|
2018-01-05 04:08:53 +00:00
|
|
|
protected function req(string $method, string $target): ResponseInterface {
|
2019-09-25 22:30:53 +00:00
|
|
|
$prefix = "/index.php/apps/news/api";
|
|
|
|
$url = $prefix.$target;
|
|
|
|
$req = $this->serverRequest($method, $url, $prefix);
|
2018-01-05 04:08:53 +00:00
|
|
|
return (new Versions)->dispatch($req);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testFetchVersionList(): void {
|
2018-01-04 04:13:08 +00:00
|
|
|
$exp = new Response(['apiLevels' => ['v1-2']]);
|
2018-01-11 16:09:25 +00:00
|
|
|
$this->assertMessage($exp, $this->req("GET", "/"));
|
|
|
|
$this->assertMessage($exp, $this->req("GET", "/"));
|
|
|
|
$this->assertMessage($exp, $this->req("GET", "/"));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-24 17:16:34 +00:00
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRespondToOptionsRequest(): void {
|
2018-01-04 04:13:08 +00:00
|
|
|
$exp = new EmptyResponse(204, ['Allow' => "HEAD,GET"]);
|
2018-01-11 16:09:25 +00:00
|
|
|
$this->assertMessage($exp, $this->req("OPTIONS", "/"));
|
2017-11-29 20:28:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testUseIncorrectMethod(): void {
|
2018-01-04 04:13:08 +00:00
|
|
|
$exp = new EmptyResponse(405, ['Allow' => "HEAD,GET"]);
|
2018-01-11 16:09:25 +00:00
|
|
|
$this->assertMessage($exp, $this->req("POST", "/"));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-24 17:16:34 +00:00
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testUseIncorrectPath(): void {
|
2018-01-04 04:13:08 +00:00
|
|
|
$exp = new EmptyResponse(404);
|
2018-01-11 16:09:25 +00:00
|
|
|
$this->assertMessage($exp, $this->req("GET", "/ook"));
|
|
|
|
$this->assertMessage($exp, $this->req("OPTIONS", "/ook"));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|