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