mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 17:12:41 +00:00
9eadd602bd
While the test suite passes, this commit yields a broken server: replacing ad hoc request objectss with PSR-7 ones is still required, as is emission of PSR-7 responses. Both will come in subsequent commits, with tests Diactoros was chosen specifically because it includes facilities for emitting responses, something which is awkward to test. The end of this refactoring should see both the Response and Request classes disappear, and the general REST class fully covered (as well as any speculative additions to AbstractHanlder).
60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
/** @license MIT
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
declare(strict_types=1);
|
|
namespace JKingWeb\Arsse\TestCase\REST\NextCloudNews;
|
|
|
|
use JKingWeb\Arsse\REST\NextCloudNews\Versions;
|
|
use JKingWeb\Arsse\REST\Request;
|
|
use Zend\Diactoros\Response\JsonResponse as Response;
|
|
use Zend\Diactoros\Response\EmptyResponse;
|
|
|
|
/** @covers \JKingWeb\Arsse\REST\NextCloudNews\Versions */
|
|
class TestVersions extends \JKingWeb\Arsse\Test\AbstractTest {
|
|
public function setUp() {
|
|
$this->clearData();
|
|
}
|
|
|
|
public function testFetchVersionList() {
|
|
$exp = new Response(['apiLevels' => ['v1-2']]);
|
|
$h = new Versions;
|
|
$req = new Request("GET", "/");
|
|
$res = $h->dispatch($req);
|
|
$this->assertResponse($exp, $res);
|
|
$req = new Request("GET", "");
|
|
$res = $h->dispatch($req);
|
|
$this->assertResponse($exp, $res);
|
|
$req = new Request("GET", "/?id=1827");
|
|
$res = $h->dispatch($req);
|
|
$this->assertResponse($exp, $res);
|
|
}
|
|
|
|
public function testRespondToOptionsRequest() {
|
|
$exp = new EmptyResponse(204, ['Allow' => "HEAD,GET"]);
|
|
$h = new Versions;
|
|
$req = new Request("OPTIONS", "/");
|
|
$res = $h->dispatch($req);
|
|
$this->assertResponse($exp, $res);
|
|
}
|
|
|
|
public function testUseIncorrectMethod() {
|
|
$exp = new EmptyResponse(405, ['Allow' => "HEAD,GET"]);
|
|
$h = new Versions;
|
|
$req = new Request("POST", "/");
|
|
$res = $h->dispatch($req);
|
|
$this->assertResponse($exp, $res);
|
|
}
|
|
|
|
public function testUseIncorrectPath() {
|
|
$exp = new EmptyResponse(404);
|
|
$h = new Versions;
|
|
$req = new Request("GET", "/ook");
|
|
$res = $h->dispatch($req);
|
|
$this->assertResponse($exp, $res);
|
|
$req = new Request("OPTIONS", "/ook");
|
|
$res = $h->dispatch($req);
|
|
$this->assertResponse($exp, $res);
|
|
}
|
|
}
|