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);
|
2017-12-22 03:47:19 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\REST\NextCloudNews;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-12-22 03:47:19 +00:00
|
|
|
use JKingWeb\Arsse\REST\NextCloudNews\Versions;
|
2018-01-05 04:08:53 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Zend\Diactoros\ServerRequest;
|
2018-01-04 04:13:08 +00:00
|
|
|
use Zend\Diactoros\Response\JsonResponse as Response;
|
|
|
|
use Zend\Diactoros\Response\EmptyResponse;
|
2017-03-20 01:50:00 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @covers \JKingWeb\Arsse\REST\NextCloudNews\Versions */
|
2017-12-22 03:47:19 +00:00
|
|
|
class TestVersions extends \JKingWeb\Arsse\Test\AbstractTest {
|
2017-08-29 14:50:31 +00:00
|
|
|
public function setUp() {
|
2018-11-23 15:01:17 +00:00
|
|
|
self::clearData();
|
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);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testFetchVersionList() {
|
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
|
|
|
|
2017-11-29 20:28:33 +00:00
|
|
|
public function testRespondToOptionsRequest() {
|
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
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testUseIncorrectMethod() {
|
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
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testUseIncorrectPath() {
|
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
|
|
|
}
|