mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Improve REST test coverage
This commit is contained in:
parent
69005ad61b
commit
5df7217cff
3 changed files with 73 additions and 5 deletions
|
@ -237,7 +237,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
case 10231:
|
||||
case 10232: return new Response(422);
|
||||
// other errors related to input
|
||||
default: return new Response(400);
|
||||
default: return new Response(400); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
$folder = Arsse::$db->folderPropertiesGet(Arsse::$user->id, $folder);
|
||||
|
@ -275,7 +275,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
case 10231:
|
||||
case 10232: return new Response(422);
|
||||
// other errors related to input
|
||||
default: return new Response(400);
|
||||
default: return new Response(400); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
return new Response(204);
|
||||
|
@ -421,7 +421,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
case 10231:
|
||||
case 10232: return new Response(422);
|
||||
// other errors related to input
|
||||
default: return new Response(400);
|
||||
default: return new Response(400); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
return new Response(204);
|
||||
|
@ -446,7 +446,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
// folder does not exist
|
||||
case 10235: return new Response(422);
|
||||
// other errors related to input
|
||||
default: return new Response(400);
|
||||
default: return new Response(400); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
return new Response(204);
|
||||
|
@ -517,7 +517,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
case 2: // starred
|
||||
$c->starred(true);
|
||||
break;
|
||||
default:
|
||||
default: // @codeCoverageIgnore
|
||||
// return all items
|
||||
}
|
||||
// whether to return only updated items
|
||||
|
|
|
@ -5,16 +5,66 @@ return [
|
|||
'Driver.Service.Internal.Name' => 'Internal',
|
||||
'Driver.User.Internal.Name' => 'Internal',
|
||||
|
||||
'HTTP.Status.100' => 'Continue',
|
||||
'HTTP.Status.101' => 'Switching Protocols',
|
||||
'HTTP.Status.102' => 'Processing',
|
||||
'HTTP.Status.200' => 'OK',
|
||||
'HTTP.Status.201' => 'Created',
|
||||
'HTTP.Status.202' => 'Accepted',
|
||||
'HTTP.Status.203' => 'Non-Authoritative Information',
|
||||
'HTTP.Status.204' => 'No Content',
|
||||
'HTTP.Status.205' => 'Reset Content',
|
||||
'HTTP.Status.206' => 'Partial Content',
|
||||
'HTTP.Status.207' => 'Multi-Status',
|
||||
'HTTP.Status.208' => 'Already Reported',
|
||||
'HTTP.Status.226' => 'IM Used',
|
||||
'HTTP.Status.300' => 'Multiple Choice',
|
||||
'HTTP.Status.301' => 'Moved Permanently',
|
||||
'HTTP.Status.302' => 'Found',
|
||||
'HTTP.Status.303' => 'See Other',
|
||||
'HTTP.Status.304' => 'Not Modified',
|
||||
'HTTP.Status.305' => 'Use Proxy',
|
||||
'HTTP.Status.306' => 'Switch Proxy',
|
||||
'HTTP.Status.307' => 'Temporary Redirect',
|
||||
'HTTP.Status.308' => 'Permanent Redirect',
|
||||
'HTTP.Status.400' => 'Bad Request',
|
||||
'HTTP.Status.401' => 'Unauthorized',
|
||||
'HTTP.Status.402' => 'Payment Required',
|
||||
'HTTP.Status.403' => 'Forbidden',
|
||||
'HTTP.Status.404' => 'Not Found',
|
||||
'HTTP.Status.405' => 'Method Not Allowed',
|
||||
'HTTP.Status.406' => 'Not Acceptable',
|
||||
'HTTP.Status.407' => 'Proxy Authentication Required',
|
||||
'HTTP.Status.408' => 'Request Timeout',
|
||||
'HTTP.Status.409' => 'Conflict',
|
||||
'HTTP.Status.410' => 'Gone',
|
||||
'HTTP.Status.411' => 'Length Required',
|
||||
'HTTP.Status.412' => 'Precondition Failed',
|
||||
'HTTP.Status.413' => 'Payload Too Large',
|
||||
'HTTP.Status.414' => 'URL Too Long',
|
||||
'HTTP.Status.415' => 'Unsupported Media Type',
|
||||
'HTTP.Status.416' => 'Range Not Satisfiable',
|
||||
'HTTP.Status.417' => 'Expectation Failed',
|
||||
'HTTP.Status.421' => 'Misdirected Request',
|
||||
'HTTP.Status.422' => 'Unprocessable Entity',
|
||||
'HTTP.Status.423' => 'Locked',
|
||||
'HTTP.Status.424' => 'Failed Depedency',
|
||||
'HTTP.Status.426' => 'Upgrade Required',
|
||||
'HTTP.Status.428' => 'Precondition Failed',
|
||||
'HTTP.Status.429' => 'Too Many Requests',
|
||||
'HTTP.Status.431' => 'Request Header Fields Too Large',
|
||||
'HTTP.Status.451' => 'Unavailable For Legal Reasons',
|
||||
'HTTP.Status.500' => 'Internal Server Error',
|
||||
'HTTP.Status.501' => 'Not Implemented',
|
||||
'HTTP.Status.502' => 'Bad Gateway',
|
||||
'HTTP.Status.503' => 'Service Unavailable',
|
||||
'HTTP.Status.504' => 'Gateway Timeout',
|
||||
'HTTP.Status.505' => 'HTTP Version Not Supported',
|
||||
'HTTP.Status.506' => 'Variant Also Negotiates',
|
||||
'HTTP.Status.507' => 'Insufficient Storage',
|
||||
'HTTP.Status.508' => 'Loop Detected',
|
||||
'HTTP.Status.510' => 'Not Extended',
|
||||
'HTTP.Status.511' => 'Network Authentication Required',
|
||||
|
||||
// this should only be encountered in testing (because tests should cover all exceptions!)
|
||||
'Exception.JKingWeb/Arsse/Exception.uncoded' => 'The specified exception symbol {0} has no code specified in AbstractException.php',
|
||||
|
|
|
@ -323,6 +323,13 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
}
|
||||
}
|
||||
|
||||
function testRespondToInvalidInputTypes() {
|
||||
$exp = new Response(415, "", "", ['Accept: application/json']);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/folders/1", '<data/>', 'application/xml')));
|
||||
$exp = new Response(400);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/folders/1", '<data/>', 'application/json')));
|
||||
}
|
||||
|
||||
function testReceiveAuthenticationChallenge() {
|
||||
Phake::when(Arsse::$user)->authHTTP->thenReturn(false);
|
||||
$exp = new Response(401, "", "", ['WWW-Authenticate: Basic realm="'.REST\NextCloudNews\V1_2::REALM.'"']);
|
||||
|
@ -450,11 +457,13 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
['url' => "http://example.com/news.atom", 'folderId' => 3],
|
||||
['url' => "http://example.org/news.atom", 'folderId' => 8],
|
||||
['url' => "http://example.net/news.atom", 'folderId' => 0],
|
||||
[],
|
||||
];
|
||||
$out = [
|
||||
['feeds' => [$this->feeds['rest'][0]]],
|
||||
['feeds' => [$this->feeds['rest'][1]], 'newestItemId' => 4758915],
|
||||
[],
|
||||
[],
|
||||
];
|
||||
// set up the necessary mocks
|
||||
Phake::when(Arsse::$db)->subscriptionAdd(Arsse::$user->id, "http://example.com/news.atom")->thenReturn(2112)->thenThrow(new ExceptionInput("constraintViolation")); // error on the second call
|
||||
|
@ -480,6 +489,9 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
// try to add a bad feed
|
||||
$exp = new Response(422);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[2]), 'application/json')));
|
||||
// try to add no feed
|
||||
$exp = new Response(422);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[3]), 'application/json')));
|
||||
}
|
||||
|
||||
function testRemoveASubscription() {
|
||||
|
@ -498,6 +510,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
['folderId' => 42],
|
||||
['folderId' => 2112],
|
||||
['folderId' => 42],
|
||||
[],
|
||||
];
|
||||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, ['folder' => 42])->thenReturn(true);
|
||||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, ['folder' => null])->thenReturn(true);
|
||||
|
@ -511,6 +524,8 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/move", json_encode($in[2]), 'application/json')));
|
||||
$exp = new Response(404);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/feeds/42/move", json_encode($in[3]), 'application/json')));
|
||||
$exp = new Response(422);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/move", json_encode($in[4]), 'application/json')));
|
||||
}
|
||||
|
||||
function testRenameASubscription() {
|
||||
|
@ -521,6 +536,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
['feedTitle' => ""],
|
||||
['feedTitle' => false],
|
||||
['feedTitle' => "Feed does not exist"],
|
||||
[],
|
||||
];
|
||||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, $this->identicalTo(['title' => null]))->thenReturn(true);
|
||||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, $this->identicalTo(['title' => "Ook"]))->thenReturn(true);
|
||||
|
@ -538,6 +554,8 @@ class TestNCNV1_2 extends Test\AbstractTest {
|
|||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/rename", json_encode($in[3]), 'application/json')));
|
||||
$exp = new Response(404);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/feeds/42/rename", json_encode($in[4]), 'application/json')));
|
||||
$exp = new Response(422);
|
||||
$this->assertEquals($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/rename", json_encode($in[6]), 'application/json')));
|
||||
}
|
||||
|
||||
function testListStaleFeeds() {
|
||||
|
|
Loading…
Reference in a new issue