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);
|
2017-12-21 22:47:19 -05:00
|
|
|
namespace JKingWeb\Arsse\TestCase\REST\NextCloudNews;
|
2017-08-29 10:50:31 -04:00
|
|
|
|
2017-12-21 22:47:19 -05:00
|
|
|
use JKingWeb\Arsse\REST\NextCloudNews\Versions;
|
2017-05-21 19:51:03 -04:00
|
|
|
use JKingWeb\Arsse\REST\Request;
|
2018-01-03 23:13:08 -05:00
|
|
|
use Zend\Diactoros\Response\JsonResponse as Response;
|
|
|
|
use Zend\Diactoros\Response\EmptyResponse;
|
2017-03-19 21:50:00 -04:00
|
|
|
|
2017-07-20 18:36:03 -04:00
|
|
|
/** @covers \JKingWeb\Arsse\REST\NextCloudNews\Versions */
|
2017-12-21 22:47:19 -05:00
|
|
|
class TestVersions extends \JKingWeb\Arsse\Test\AbstractTest {
|
2017-08-29 10:50:31 -04:00
|
|
|
public function setUp() {
|
2017-04-06 21:41:21 -04:00
|
|
|
$this->clearData();
|
|
|
|
}
|
2017-03-19 21:50:00 -04:00
|
|
|
|
2017-08-29 10:50:31 -04:00
|
|
|
public function testFetchVersionList() {
|
2018-01-03 23:13:08 -05:00
|
|
|
$exp = new Response(['apiLevels' => ['v1-2']]);
|
2017-12-21 22:47:19 -05:00
|
|
|
$h = new Versions;
|
2017-04-06 21:41:21 -04:00
|
|
|
$req = new Request("GET", "/");
|
|
|
|
$res = $h->dispatch($req);
|
2018-01-03 23:13:08 -05:00
|
|
|
$this->assertResponse($exp, $res);
|
2017-04-06 21:41:21 -04:00
|
|
|
$req = new Request("GET", "");
|
|
|
|
$res = $h->dispatch($req);
|
2018-01-03 23:13:08 -05:00
|
|
|
$this->assertResponse($exp, $res);
|
2017-04-06 21:41:21 -04:00
|
|
|
$req = new Request("GET", "/?id=1827");
|
|
|
|
$res = $h->dispatch($req);
|
2018-01-03 23:13:08 -05:00
|
|
|
$this->assertResponse($exp, $res);
|
2017-04-06 21:41:21 -04:00
|
|
|
}
|
2017-03-24 13:16:34 -04:00
|
|
|
|
2017-11-29 15:28:33 -05:00
|
|
|
public function testRespondToOptionsRequest() {
|
2018-01-03 23:13:08 -05:00
|
|
|
$exp = new EmptyResponse(204, ['Allow' => "HEAD,GET"]);
|
2017-12-21 22:47:19 -05:00
|
|
|
$h = new Versions;
|
2017-11-29 15:28:33 -05:00
|
|
|
$req = new Request("OPTIONS", "/");
|
|
|
|
$res = $h->dispatch($req);
|
2018-01-03 23:13:08 -05:00
|
|
|
$this->assertResponse($exp, $res);
|
2017-11-29 15:28:33 -05:00
|
|
|
}
|
|
|
|
|
2017-08-29 10:50:31 -04:00
|
|
|
public function testUseIncorrectMethod() {
|
2018-01-03 23:13:08 -05:00
|
|
|
$exp = new EmptyResponse(405, ['Allow' => "HEAD,GET"]);
|
2017-12-21 22:47:19 -05:00
|
|
|
$h = new Versions;
|
2017-04-06 21:41:21 -04:00
|
|
|
$req = new Request("POST", "/");
|
|
|
|
$res = $h->dispatch($req);
|
2018-01-03 23:13:08 -05:00
|
|
|
$this->assertResponse($exp, $res);
|
2017-04-06 21:41:21 -04:00
|
|
|
}
|
2017-03-24 13:16:34 -04:00
|
|
|
|
2017-08-29 10:50:31 -04:00
|
|
|
public function testUseIncorrectPath() {
|
2018-01-03 23:13:08 -05:00
|
|
|
$exp = new EmptyResponse(404);
|
2017-12-21 22:47:19 -05:00
|
|
|
$h = new Versions;
|
2017-04-06 21:41:21 -04:00
|
|
|
$req = new Request("GET", "/ook");
|
|
|
|
$res = $h->dispatch($req);
|
2018-01-03 23:13:08 -05:00
|
|
|
$this->assertResponse($exp, $res);
|
2017-11-29 15:28:33 -05:00
|
|
|
$req = new Request("OPTIONS", "/ook");
|
|
|
|
$res = $h->dispatch($req);
|
2018-01-03 23:13:08 -05:00
|
|
|
$this->assertResponse($exp, $res);
|
2017-04-06 21:41:21 -04:00
|
|
|
}
|
2017-08-29 10:50:31 -04:00
|
|
|
}
|