mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Make HTTP message testing generic
assertMessage will test the method and target URL of requests, attributes of server requests, as well as the existing testing of a response's status code. All messages' bodies and header fields are tested for equivalence (with a special case for JSON response bodies).
This commit is contained in:
parent
d61fc0c359
commit
daea0ceb27
6 changed files with 290 additions and 276 deletions
|
@ -356,7 +356,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
public function testSendAuthenticationChallenge() {
|
||||
Phake::when(Arsse::$user)->authHTTP->thenReturn(false);
|
||||
$exp = new EmptyResponse(401, ['WWW-Authenticate' => 'Basic realm="'.V1_2::REALM.'"']);
|
||||
$this->assertResponse($exp, $this->req("GET", "/"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/"));
|
||||
}
|
||||
|
||||
public function testRespondToInvalidPaths() {
|
||||
|
@ -394,23 +394,23 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
foreach ($errs[404] as $req) {
|
||||
$exp = new EmptyResponse(404);
|
||||
list($method, $path) = $req;
|
||||
$this->assertResponse($exp, $this->req($method, $path), "$method call to $path did not return 404.");
|
||||
$this->assertMessage($exp, $this->req($method, $path), "$method call to $path did not return 404.");
|
||||
}
|
||||
foreach ($errs[405] as $allow => $cases) {
|
||||
$exp = new EmptyResponse(405, ['Allow' => $allow]);
|
||||
foreach ($cases as $req) {
|
||||
list($method, $path) = $req;
|
||||
$this->assertResponse($exp, $this->req($method, $path), "$method call to $path did not return 405.");
|
||||
$this->assertMessage($exp, $this->req($method, $path), "$method call to $path did not return 405.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testRespondToInvalidInputTypes() {
|
||||
$exp = new EmptyResponse(415, ['Accept' => "application/json"]);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1", '<data/>', ['Content-Type' => "application/xml"]));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1", '<data/>', ['Content-Type' => "application/xml"]));
|
||||
$exp = new EmptyResponse(400);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1", '<data/>'));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1", '<data/>', ['Content-Type' => null]));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1", '<data/>'));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1", '<data/>', ['Content-Type' => null]));
|
||||
}
|
||||
|
||||
public function testRespondToOptionsRequests() {
|
||||
|
@ -418,19 +418,19 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
'Allow' => "HEAD,GET,POST",
|
||||
'Accept' => "application/json",
|
||||
]);
|
||||
$this->assertResponse($exp, $this->req("OPTIONS", "/feeds"));
|
||||
$this->assertMessage($exp, $this->req("OPTIONS", "/feeds"));
|
||||
$exp = new EmptyResponse(204, [
|
||||
'Allow' => "DELETE",
|
||||
'Accept' => "application/json",
|
||||
]);
|
||||
$this->assertResponse($exp, $this->req("OPTIONS", "/feeds/2112"));
|
||||
$this->assertMessage($exp, $this->req("OPTIONS", "/feeds/2112"));
|
||||
$exp = new EmptyResponse(204, [
|
||||
'Allow' => "HEAD,GET",
|
||||
'Accept' => "application/json",
|
||||
]);
|
||||
$this->assertResponse($exp, $this->req("OPTIONS", "/user"));
|
||||
$this->assertMessage($exp, $this->req("OPTIONS", "/user"));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("OPTIONS", "/invalid/path"));
|
||||
$this->assertMessage($exp, $this->req("OPTIONS", "/invalid/path"));
|
||||
}
|
||||
|
||||
public function testListFolders() {
|
||||
|
@ -444,9 +444,9 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
];
|
||||
Phake::when(Arsse::$db)->folderList(Arsse::$user->id, null, false)->thenReturn(new Result([]))->thenReturn(new Result($list));
|
||||
$exp = new Response(['folders' => []]);
|
||||
$this->assertResponse($exp, $this->req("GET", "/folders"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/folders"));
|
||||
$exp = new Response(['folders' => $out]);
|
||||
$this->assertResponse($exp, $this->req("GET", "/folders"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/folders"));
|
||||
}
|
||||
|
||||
public function testAddAFolder() {
|
||||
|
@ -474,33 +474,33 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->folderAdd(Arsse::$user->id, ['name' => " "])->thenThrow(new ExceptionInput("whitespace"));
|
||||
// correctly add two folders, using different means
|
||||
$exp = new Response(['folders' => [$out[0]]]);
|
||||
$this->assertResponse($exp, $this->req("POST", "/folders", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/folders", json_encode($in[0])));
|
||||
$exp = new Response(['folders' => [$out[1]]]);
|
||||
$this->assertResponse($exp, $this->req("POST", "/folders?name=Hardware"));
|
||||
$this->assertMessage($exp, $this->req("POST", "/folders?name=Hardware"));
|
||||
Phake::verify(Arsse::$db)->folderAdd(Arsse::$user->id, $in[0]);
|
||||
Phake::verify(Arsse::$db)->folderAdd(Arsse::$user->id, $in[1]);
|
||||
Phake::verify(Arsse::$db)->folderPropertiesGet(Arsse::$user->id, 1);
|
||||
Phake::verify(Arsse::$db)->folderPropertiesGet(Arsse::$user->id, 2);
|
||||
// test bad folder names
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("POST", "/folders"));
|
||||
$this->assertResponse($exp, $this->req("POST", "/folders", '{"name":""}'));
|
||||
$this->assertResponse($exp, $this->req("POST", "/folders", '{"name":" "}'));
|
||||
$this->assertResponse($exp, $this->req("POST", "/folders", '{"name":{}}'));
|
||||
$this->assertMessage($exp, $this->req("POST", "/folders"));
|
||||
$this->assertMessage($exp, $this->req("POST", "/folders", '{"name":""}'));
|
||||
$this->assertMessage($exp, $this->req("POST", "/folders", '{"name":" "}'));
|
||||
$this->assertMessage($exp, $this->req("POST", "/folders", '{"name":{}}'));
|
||||
// try adding the same two folders again
|
||||
$exp = new EmptyResponse(409);
|
||||
$this->assertResponse($exp, $this->req("POST", "/folders?name=Software"));
|
||||
$this->assertMessage($exp, $this->req("POST", "/folders?name=Software"));
|
||||
$exp = new EmptyResponse(409);
|
||||
$this->assertResponse($exp, $this->req("POST", "/folders", json_encode($in[1])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/folders", json_encode($in[1])));
|
||||
}
|
||||
|
||||
public function testRemoveAFolder() {
|
||||
Phake::when(Arsse::$db)->folderRemove(Arsse::$user->id, 1)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("DELETE", "/folders/1"));
|
||||
$this->assertMessage($exp, $this->req("DELETE", "/folders/1"));
|
||||
// fail on the second invocation because it no longer exists
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("DELETE", "/folders/1"));
|
||||
$this->assertMessage($exp, $this->req("DELETE", "/folders/1"));
|
||||
Phake::verify(Arsse::$db, Phake::times(2))->folderRemove(Arsse::$user->id, 1);
|
||||
}
|
||||
|
||||
|
@ -519,17 +519,17 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->folderPropertiesSet(Arsse::$user->id, 1, $in[4])->thenReturn(true); // this should be stopped by the handler before the request gets to the database
|
||||
Phake::when(Arsse::$db)->folderPropertiesSet(Arsse::$user->id, 3, $this->anything())->thenThrow(new ExceptionInput("subjectMissing")); // folder ID 3 does not exist
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1", json_encode($in[0])));
|
||||
$exp = new EmptyResponse(409);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/2", json_encode($in[1])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/2", json_encode($in[1])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1", json_encode($in[2])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1", json_encode($in[2])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1", json_encode($in[3])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1", json_encode($in[3])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1", json_encode($in[4])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1", json_encode($in[4])));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/3", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/3", json_encode($in[0])));
|
||||
}
|
||||
|
||||
public function testRetrieveServerVersion() {
|
||||
|
@ -537,7 +537,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
'version' => V1_2::VERSION,
|
||||
'arsse_version' => Arsse::VERSION,
|
||||
]);
|
||||
$this->assertResponse($exp, $this->req("GET", "/version"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/version"));
|
||||
}
|
||||
|
||||
public function testListSubscriptions() {
|
||||
|
@ -554,9 +554,9 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->articleStarred(Arsse::$user->id)->thenReturn(['total' => 0])->thenReturn(['total' => 5]);
|
||||
Phake::when(Arsse::$db)->editionLatest(Arsse::$user->id)->thenReturn(0)->thenReturn(4758915);
|
||||
$exp = new Response($exp1);
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds"));
|
||||
$exp = new Response($exp2);
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds"));
|
||||
}
|
||||
|
||||
public function testAddASubscription() {
|
||||
|
@ -589,31 +589,31 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->subscriptionAdd(Arsse::$user->id, "http://example.net/news.atom")->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.net/news.atom", new \PicoFeed\Client\InvalidUrlException()))->thenReturn(47);
|
||||
// add the subscriptions
|
||||
$exp = new Response($out[0]);
|
||||
$this->assertResponse($exp, $this->req("POST", "/feeds", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/feeds", json_encode($in[0])));
|
||||
$exp = new Response($out[1]);
|
||||
$this->assertResponse($exp, $this->req("POST", "/feeds", json_encode($in[1])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/feeds", json_encode($in[1])));
|
||||
// try to add them a second time
|
||||
$exp = new EmptyResponse(409);
|
||||
$this->assertResponse($exp, $this->req("POST", "/feeds", json_encode($in[0])));
|
||||
$this->assertResponse($exp, $this->req("POST", "/feeds", json_encode($in[1])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/feeds", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/feeds", json_encode($in[1])));
|
||||
// try to add a bad feed
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("POST", "/feeds", json_encode($in[2])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/feeds", json_encode($in[2])));
|
||||
// try again (this will succeed), with an invalid folder ID
|
||||
$exp = new Response($out[2]);
|
||||
$this->assertResponse($exp, $this->req("POST", "/feeds", json_encode($in[3])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/feeds", json_encode($in[3])));
|
||||
// try to add no feed
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("POST", "/feeds", json_encode($in[4])));
|
||||
$this->assertMessage($exp, $this->req("POST", "/feeds", json_encode($in[4])));
|
||||
}
|
||||
|
||||
public function testRemoveASubscription() {
|
||||
Phake::when(Arsse::$db)->subscriptionRemove(Arsse::$user->id, 1)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("DELETE", "/feeds/1"));
|
||||
$this->assertMessage($exp, $this->req("DELETE", "/feeds/1"));
|
||||
// fail on the second invocation because it no longer exists
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("DELETE", "/feeds/1"));
|
||||
$this->assertMessage($exp, $this->req("DELETE", "/feeds/1"));
|
||||
Phake::verify(Arsse::$db, Phake::times(2))->subscriptionRemove(Arsse::$user->id, 1);
|
||||
}
|
||||
|
||||
|
@ -632,17 +632,17 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, ['folder' => -1])->thenThrow(new ExceptionInput("typeViolation")); // folder is invalid
|
||||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 42, $this->anything())->thenThrow(new ExceptionInput("subjectMissing")); // subscription does not exist
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[0])));
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[1])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[1])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[2])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[2])));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/42/move", json_encode($in[3])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/42/move", json_encode($in[3])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[4])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[4])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[5])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/move", json_encode($in[5])));
|
||||
}
|
||||
|
||||
public function testRenameASubscription() {
|
||||
|
@ -662,17 +662,17 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, $this->identicalTo(['title' => false]))->thenThrow(new ExceptionInput("missing"));
|
||||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 42, $this->anything())->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[0])));
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[1])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[1])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[2])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[2])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[3])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[3])));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/42/rename", json_encode($in[4])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/42/rename", json_encode($in[4])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[6])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/rename", json_encode($in[6])));
|
||||
}
|
||||
|
||||
public function testListStaleFeeds() {
|
||||
|
@ -688,11 +688,11 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
];
|
||||
Phake::when(Arsse::$db)->feedListStale->thenReturn(array_column($out, "id"));
|
||||
$exp = new Response(['feeds' => $out]);
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds/all"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds/all"));
|
||||
// retrieving the list when not an admin fails
|
||||
Phake::when(Arsse::$user)->rightsGet->thenReturn(0);
|
||||
$exp = new EmptyResponse(403);
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds/all"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds/all"));
|
||||
}
|
||||
|
||||
public function testUpdateAFeed() {
|
||||
|
@ -707,17 +707,17 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->feedUpdate(2112)->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
Phake::when(Arsse::$db)->feedUpdate($this->lessThan(1))->thenThrow(new ExceptionInput("typeViolation"));
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds/update", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[0])));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds/update", json_encode($in[1])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[1])));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds/update", json_encode($in[2])));
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds/update", json_encode($in[3])));
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds/update", json_encode($in[4])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[2])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[3])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[4])));
|
||||
// updating a feed when not an admin fails
|
||||
Phake::when(Arsse::$user)->rightsGet->thenReturn(0);
|
||||
$exp = new EmptyResponse(403);
|
||||
$this->assertResponse($exp, $this->req("GET", "/feeds/update", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[0])));
|
||||
}
|
||||
|
||||
public function testListArticles() {
|
||||
|
@ -744,14 +744,14 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->reverse(true)->folder(-1), Database::LIST_TYPICAL)->thenThrow(new ExceptionInput("typeViolation"));
|
||||
$exp = new Response(['items' => $this->articles['rest']]);
|
||||
// check the contents of the response
|
||||
$this->assertResponse($exp, $this->req("GET", "/items")); // first instance of base context
|
||||
$this->assertResponse($exp, $this->req("GET", "/items/updated")); // second instance of base context
|
||||
$this->assertMessage($exp, $this->req("GET", "/items")); // first instance of base context
|
||||
$this->assertMessage($exp, $this->req("GET", "/items/updated")); // second instance of base context
|
||||
// check error conditions
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("GET", "/items", json_encode($in[0])));
|
||||
$this->assertResponse($exp, $this->req("GET", "/items", json_encode($in[1])));
|
||||
$this->assertResponse($exp, $this->req("GET", "/items", json_encode($in[2])));
|
||||
$this->assertResponse($exp, $this->req("GET", "/items", json_encode($in[3])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/items", json_encode($in[0])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/items", json_encode($in[1])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/items", json_encode($in[2])));
|
||||
$this->assertMessage($exp, $this->req("GET", "/items", json_encode($in[3])));
|
||||
// simply run through the remainder of the input for later method verification
|
||||
$this->req("GET", "/items", json_encode($in[4]));
|
||||
$this->req("GET", "/items", json_encode($in[5])); // third instance of base context
|
||||
|
@ -781,13 +781,13 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->folder(1)->latestEdition(2112))->thenReturn(42);
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->folder(42)->latestEdition(2112))->thenThrow(new ExceptionInput("idMissing")); // folder doesn't exist
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1/read", $in));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1/read?newestItemId=2112"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1/read", $in));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1/read?newestItemId=2112"));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1/read"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/1/read?newestItemId=ook"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1/read"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/1/read?newestItemId=ook"));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/folders/42/read", $in));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/folders/42/read", $in));
|
||||
}
|
||||
|
||||
public function testMarkASubscriptionRead() {
|
||||
|
@ -796,13 +796,13 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->subscription(1)->latestEdition(2112))->thenReturn(42);
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->subscription(42)->latestEdition(2112))->thenThrow(new ExceptionInput("idMissing")); // subscription doesn't exist
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/read", $in));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/read?newestItemId=2112"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/read", $in));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/read?newestItemId=2112"));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/read"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/1/read?newestItemId=ook"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/read"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/1/read?newestItemId=ook"));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/feeds/42/read", $in));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/feeds/42/read", $in));
|
||||
}
|
||||
|
||||
public function testMarkAllItemsRead() {
|
||||
|
@ -810,11 +810,11 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
$in = json_encode(['newestItemId' => 2112]);
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->latestEdition(2112))->thenReturn(42);
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read", $in));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read?newestItemId=2112"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read", $in));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read?newestItemId=2112"));
|
||||
$exp = new EmptyResponse(422);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read?newestItemId=ook"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read?newestItemId=ook"));
|
||||
}
|
||||
|
||||
public function testChangeMarksOfASingleArticle() {
|
||||
|
@ -831,15 +831,15 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $unstar, (new Context)->article(4))->thenReturn(42);
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $unstar, (new Context)->article(1337))->thenThrow(new ExceptionInput("subjectMissing")); // article doesn't exist doesn't exist
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/1/read"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/2/unread"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/1/3/star"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/4400/4/unstar"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/1/read"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/2/unread"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/1/3/star"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/4400/4/unstar"));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/42/read"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/47/unread"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/1/2112/star"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/4400/1337/unstar"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/42/read"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/47/unread"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/1/2112/star"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/4400/1337/unstar"));
|
||||
Phake::verify(Arsse::$db, Phake::times(8))->articleMark(Arsse::$user->id, $this->anything(), $this->anything());
|
||||
}
|
||||
|
||||
|
@ -862,26 +862,26 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->editions([]))->thenThrow(new ExceptionInput("tooShort")); // data model function requires one valid integer for multiples
|
||||
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->articles([]))->thenThrow(new ExceptionInput("tooShort")); // data model function requires one valid integer for multiples
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read/multiple"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unread/multiple"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/star/multiple"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unstar/multiple"));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read/multiple", json_encode(['items' => "ook"])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unread/multiple", json_encode(['items' => "ook"])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/star/multiple", json_encode(['items' => "ook"])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unstar/multiple", json_encode(['items' => "ook"])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read/multiple", json_encode(['items' => []])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unread/multiple", json_encode(['items' => []])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read/multiple", json_encode(['items' => $in[0]])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unread/multiple", json_encode(['items' => $in[0]])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/read/multiple", json_encode(['items' => $in[1]])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unread/multiple", json_encode(['items' => $in[1]])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/star/multiple", json_encode(['items' => []])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unstar/multiple", json_encode(['items' => []])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/star/multiple", json_encode(['items' => $inStar[0]])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unstar/multiple", json_encode(['items' => $inStar[0]])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/star/multiple", json_encode(['items' => $inStar[1]])));
|
||||
$this->assertResponse($exp, $this->req("PUT", "/items/unstar/multiple", json_encode(['items' => $inStar[1]])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read/multiple"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unread/multiple"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/star/multiple"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unstar/multiple"));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read/multiple", json_encode(['items' => "ook"])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unread/multiple", json_encode(['items' => "ook"])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/star/multiple", json_encode(['items' => "ook"])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unstar/multiple", json_encode(['items' => "ook"])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read/multiple", json_encode(['items' => []])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unread/multiple", json_encode(['items' => []])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read/multiple", json_encode(['items' => $in[0]])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unread/multiple", json_encode(['items' => $in[0]])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/read/multiple", json_encode(['items' => $in[1]])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unread/multiple", json_encode(['items' => $in[1]])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/star/multiple", json_encode(['items' => []])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unstar/multiple", json_encode(['items' => []])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/star/multiple", json_encode(['items' => $inStar[0]])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unstar/multiple", json_encode(['items' => $inStar[0]])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/star/multiple", json_encode(['items' => $inStar[1]])));
|
||||
$this->assertMessage($exp, $this->req("PUT", "/items/unstar/multiple", json_encode(['items' => $inStar[1]])));
|
||||
// ensure the data model was queried appropriately for read/unread
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $read, (new Context)->editions([]));
|
||||
Phake::verify(Arsse::$db, Phake::atLeast(1))->articleMark(Arsse::$user->id, $read, (new Context)->editions($in[0]));
|
||||
|
@ -915,28 +915,28 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
$arr2['warnings']['improperlyConfiguredCron'] = true;
|
||||
$arr2['warnings']['incorrectDbCharset'] = true;
|
||||
$exp = new Response($arr1);
|
||||
$this->assertResponse($exp, $this->req("GET", "/status"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/status"));
|
||||
}
|
||||
|
||||
public function testCleanUpBeforeUpdate() {
|
||||
Phake::when(Arsse::$db)->feedCleanup()->thenReturn(true);
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("GET", "/cleanup/before-update"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/cleanup/before-update"));
|
||||
Phake::verify(Arsse::$db)->feedCleanup();
|
||||
// performing a cleanup when not an admin fails
|
||||
Phake::when(Arsse::$user)->rightsGet->thenReturn(0);
|
||||
$exp = new EmptyResponse(403);
|
||||
$this->assertResponse($exp, $this->req("GET", "/cleanup/before-update"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/cleanup/before-update"));
|
||||
}
|
||||
|
||||
public function testCleanUpAfterUpdate() {
|
||||
Phake::when(Arsse::$db)->articleCleanup()->thenReturn(true);
|
||||
$exp = new EmptyResponse(204);
|
||||
$this->assertResponse($exp, $this->req("GET", "/cleanup/after-update"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/cleanup/after-update"));
|
||||
Phake::verify(Arsse::$db)->articleCleanup();
|
||||
// performing a cleanup when not an admin fails
|
||||
Phake::when(Arsse::$user)->rightsGet->thenReturn(0);
|
||||
$exp = new EmptyResponse(403);
|
||||
$this->assertResponse($exp, $this->req("GET", "/cleanup/after-update"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/cleanup/after-update"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,24 +31,24 @@ class TestVersions extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
|
||||
public function testFetchVersionList() {
|
||||
$exp = new Response(['apiLevels' => ['v1-2']]);
|
||||
$this->assertResponse($exp, $this->req("GET", "/"));
|
||||
$this->assertResponse($exp, $this->req("GET", "/"));
|
||||
$this->assertResponse($exp, $this->req("GET", "/"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/"));
|
||||
}
|
||||
|
||||
public function testRespondToOptionsRequest() {
|
||||
$exp = new EmptyResponse(204, ['Allow' => "HEAD,GET"]);
|
||||
$this->assertResponse($exp, $this->req("OPTIONS", "/"));
|
||||
$this->assertMessage($exp, $this->req("OPTIONS", "/"));
|
||||
}
|
||||
|
||||
public function testUseIncorrectMethod() {
|
||||
$exp = new EmptyResponse(405, ['Allow' => "HEAD,GET"]);
|
||||
$this->assertResponse($exp, $this->req("POST", "/"));
|
||||
$this->assertMessage($exp, $this->req("POST", "/"));
|
||||
}
|
||||
|
||||
public function testUseIncorrectPath() {
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req("GET", "/ook"));
|
||||
$this->assertResponse($exp, $this->req("OPTIONS", "/ook"));
|
||||
$this->assertMessage($exp, $this->req("GET", "/ook"));
|
||||
$this->assertMessage($exp, $this->req("OPTIONS", "/ook"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
$res = new EmptyResponse(204, $resHeaders);
|
||||
$exp = new EmptyResponse(204, $expHeaders);
|
||||
$act = $r->corsApply($res, $req);
|
||||
$this->assertResponse($exp, $act);
|
||||
$this->assertMessage($exp, $act);
|
||||
}
|
||||
|
||||
public function provideCorsHeaders() {
|
||||
|
@ -211,7 +211,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
return $res;
|
||||
});
|
||||
$act = $r->normalizeResponse($res, $req);
|
||||
$this->assertResponse($exp, $act);
|
||||
$this->assertMessage($exp, $act);
|
||||
}
|
||||
|
||||
public function provideUnnormalizedResponses() {
|
||||
|
|
|
@ -187,11 +187,11 @@ LONG_STRING;
|
|||
|
||||
public function testHandleInvalidPaths() {
|
||||
$exp = $this->respErr("MALFORMED_INPUT", [], null);
|
||||
$this->assertResponse($exp, $this->req(null, "POST", "", ""));
|
||||
$this->assertResponse($exp, $this->req(null, "POST", "/", ""));
|
||||
$this->assertResponse($exp, $this->req(null, "POST", "/index.php", ""));
|
||||
$this->assertMessage($exp, $this->req(null, "POST", "", ""));
|
||||
$this->assertMessage($exp, $this->req(null, "POST", "/", ""));
|
||||
$this->assertMessage($exp, $this->req(null, "POST", "/index.php", ""));
|
||||
$exp = new EmptyResponse(404);
|
||||
$this->assertResponse($exp, $this->req(null, "POST", "/bad/path", ""));
|
||||
$this->assertMessage($exp, $this->req(null, "POST", "/bad/path", ""));
|
||||
}
|
||||
|
||||
public function testHandleOptionsRequest() {
|
||||
|
@ -199,13 +199,13 @@ LONG_STRING;
|
|||
'Allow' => "POST",
|
||||
'Accept' => "application/json, text/json",
|
||||
]);
|
||||
$this->assertResponse($exp, $this->req(null, "OPTIONS", "", ""));
|
||||
$this->assertMessage($exp, $this->req(null, "OPTIONS", "", ""));
|
||||
}
|
||||
|
||||
public function testHandleInvalidData() {
|
||||
$exp = $this->respErr("MALFORMED_INPUT", [], null);
|
||||
$this->assertResponse($exp, $this->req(null, "POST", "", "This is not valid JSON data"));
|
||||
$this->assertResponse($exp, $this->req(null, "POST", "", "")); // lack of data is also an error
|
||||
$this->assertMessage($exp, $this->req(null, "POST", "", "This is not valid JSON data"));
|
||||
$this->assertMessage($exp, $this->req(null, "POST", "", "")); // lack of data is also an error
|
||||
}
|
||||
|
||||
public function testLogIn() {
|
||||
|
@ -218,15 +218,15 @@ LONG_STRING;
|
|||
'password' => "secret",
|
||||
];
|
||||
$exp = $this->respGood(['session_id' => "PriestsOfSyrinx", 'api_level' => \JKingWeb\Arsse\REST\TinyTinyRSS\API::LEVEL]);
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
// base64 passwords are also accepted
|
||||
$data['password'] = base64_encode($data['password']);
|
||||
$exp = $this->respGood(['session_id' => "SolarFederation", 'api_level' => \JKingWeb\Arsse\REST\TinyTinyRSS\API::LEVEL]);
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
// test a failed log-in
|
||||
$data['password'] = "superman";
|
||||
$exp = $this->respErr("LOGIN_ERROR");
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
// logging in should never try to resume a session
|
||||
Phake::verify(Arsse::$db, Phake::times(0))->sessionResume($this->anything());
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ LONG_STRING;
|
|||
'password' => "secret",
|
||||
];
|
||||
$exp = new EmptyResponse(500);
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
}
|
||||
|
||||
public function testLogOut() {
|
||||
|
@ -249,7 +249,7 @@ LONG_STRING;
|
|||
'sid' => "PriestsOfSyrinx",
|
||||
];
|
||||
$exp = $this->respGood(['status' => "OK"]);
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
Phake::verify(Arsse::$db)->sessionDestroy(Arsse::$user->id, "PriestsOfSyrinx");
|
||||
}
|
||||
|
||||
|
@ -259,10 +259,10 @@ LONG_STRING;
|
|||
'sid' => "PriestsOfSyrinx",
|
||||
];
|
||||
$exp = $this->respGood(['status' => true]);
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
$data['sid'] = "SolarFederation";
|
||||
$exp = $this->respErr("NOT_LOGGED_IN");
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
}
|
||||
|
||||
public function testHandleUnknownMethods() {
|
||||
|
@ -271,7 +271,7 @@ LONG_STRING;
|
|||
'op' => "thisMethodDoesNotExist",
|
||||
'sid' => "PriestsOfSyrinx",
|
||||
];
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
}
|
||||
|
||||
public function testHandleMixedCaseMethods() {
|
||||
|
@ -280,13 +280,13 @@ LONG_STRING;
|
|||
'sid' => "PriestsOfSyrinx",
|
||||
];
|
||||
$exp = $this->respGood(['status' => true]);
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
$data['op'] = "isloggedin";
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
$data['op'] = "ISLOGGEDIN";
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
$data['op'] = "iSlOgGeDiN";
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
}
|
||||
|
||||
public function testRetrieveServerVersion() {
|
||||
|
@ -298,7 +298,7 @@ LONG_STRING;
|
|||
'version' => \JKingWeb\Arsse\REST\TinyTinyRSS\API::VERSION,
|
||||
'arsse_version' => Arsse::VERSION,
|
||||
]);
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
}
|
||||
|
||||
public function testRetrieveProtocolLevel() {
|
||||
|
@ -307,7 +307,7 @@ LONG_STRING;
|
|||
'sid' => "PriestsOfSyrinx",
|
||||
];
|
||||
$exp = $this->respGood(['level' => \JKingWeb\Arsse\REST\TinyTinyRSS\API::LEVEL]);
|
||||
$this->assertResponse($exp, $this->req($data));
|
||||
$this->assertMessage($exp, $this->req($data));
|
||||
}
|
||||
|
||||
public function testAddACategory() {
|
||||
|
@ -341,24 +341,24 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->folderAdd(Arsse::$user->id, ['name' => " ", 'parent' => null])->thenThrow(new ExceptionInput("whitespace"));
|
||||
// correctly add two folders
|
||||
$exp = $this->respGood("2");
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
$exp = $this->respGood("3");
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// attempt to add the two folders again
|
||||
$exp = $this->respGood("2");
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
$exp = $this->respGood("3");
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
Phake::verify(Arsse::$db)->folderList(Arsse::$user->id, null, false);
|
||||
Phake::verify(Arsse::$db)->folderList(Arsse::$user->id, 1, false);
|
||||
// add a folder to a missing parent (silently fails)
|
||||
$exp = $this->respGood(false);
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
// add some invalid folders
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertResponse($exp, $this->req($in[5]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[5]));
|
||||
}
|
||||
|
||||
public function testRemoveACategory() {
|
||||
|
@ -371,16 +371,16 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->folderRemove(Arsse::$user->id, 42)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
// succefully delete a folder
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// try deleting it again (this should silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// delete a folder which does not exist (this should also silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// delete an invalid folder (causes an error)
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
Phake::verify(Arsse::$db, Phake::times(3))->folderRemove(Arsse::$user->id, $this->anything());
|
||||
}
|
||||
|
||||
|
@ -418,21 +418,21 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[8])->thenThrow(new ExceptionInput("typeViolation"));
|
||||
// succefully move a folder
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// move a folder which does not exist (this should silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// move a folder causing a duplication (this should also silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertResponse($exp, $this->req($in[6]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[6]));
|
||||
// all the rest should cause errors
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertResponse($exp, $this->req($in[5]));
|
||||
$this->assertResponse($exp, $this->req($in[7]));
|
||||
$this->assertResponse($exp, $this->req($in[8]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[5]));
|
||||
$this->assertMessage($exp, $this->req($in[7]));
|
||||
$this->assertMessage($exp, $this->req($in[8]));
|
||||
Phake::verify(Arsse::$db, Phake::times(5))->folderPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything());
|
||||
}
|
||||
|
||||
|
@ -458,21 +458,21 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[2])->thenThrow(new ExceptionInput("constraintViolation"));
|
||||
// succefully rename a folder
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// rename a folder which does not exist (this should silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// rename a folder causing a duplication (this should also silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
// all the rest should cause errors
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertResponse($exp, $this->req($in[5]));
|
||||
$this->assertResponse($exp, $this->req($in[6]));
|
||||
$this->assertResponse($exp, $this->req($in[7]));
|
||||
$this->assertResponse($exp, $this->req($in[8]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[5]));
|
||||
$this->assertMessage($exp, $this->req($in[6]));
|
||||
$this->assertMessage($exp, $this->req($in[7]));
|
||||
$this->assertMessage($exp, $this->req($in[8]));
|
||||
Phake::verify(Arsse::$db, Phake::times(3))->folderPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything());
|
||||
}
|
||||
|
||||
|
@ -542,11 +542,11 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->subscriptionList(Arsse::$user->id)->thenReturn(new Result($list));
|
||||
for ($a = 0; $a < (sizeof($in) - 4); $a++) {
|
||||
$exp = $this->respGood($out[$a]);
|
||||
$this->assertResponse($exp, $this->req($in[$a]), "Failed test $a");
|
||||
$this->assertMessage($exp, $this->req($in[$a]), "Failed test $a");
|
||||
}
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
for ($a = (sizeof($in) - 4); $a < sizeof($in); $a++) {
|
||||
$this->assertResponse($exp, $this->req($in[$a]), "Failed test $a");
|
||||
$this->assertMessage($exp, $this->req($in[$a]), "Failed test $a");
|
||||
}
|
||||
Phake::verify(Arsse::$db, Phake::times(0))->subscriptionPropertiesSet(Arsse::$user->id, 4, ['folder' => 1]);
|
||||
}
|
||||
|
@ -563,13 +563,13 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->subscriptionRemove(Arsse::$user->id, 42)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
// succefully delete a folder
|
||||
$exp = $this->respGood(['status' => "OK"]);
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// try deleting it again (this should noisily fail, as should everything else)
|
||||
$exp = $this->respErr("FEED_NOT_FOUND");
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
Phake::verify(Arsse::$db, Phake::times(5))->subscriptionRemove(Arsse::$user->id, $this->anything());
|
||||
}
|
||||
|
||||
|
@ -597,21 +597,21 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(...$db[3])->thenThrow(new ExceptionInput("constraintViolation"));
|
||||
// succefully move a subscription
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// move a subscription which does not exist (this should silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// move a subscription causing a duplication (this should also silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
// all the rest should cause errors
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertResponse($exp, $this->req($in[5]));
|
||||
$this->assertResponse($exp, $this->req($in[6]));
|
||||
$this->assertResponse($exp, $this->req($in[7]));
|
||||
$this->assertResponse($exp, $this->req($in[8]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[5]));
|
||||
$this->assertMessage($exp, $this->req($in[6]));
|
||||
$this->assertMessage($exp, $this->req($in[7]));
|
||||
$this->assertMessage($exp, $this->req($in[8]));
|
||||
Phake::verify(Arsse::$db, Phake::times(4))->subscriptionPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything());
|
||||
}
|
||||
|
||||
|
@ -637,21 +637,21 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->subscriptionPropertiesSet(...$db[2])->thenThrow(new ExceptionInput("constraintViolation"));
|
||||
// succefully rename a subscription
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// rename a subscription which does not exist (this should silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// rename a subscription causing a duplication (this should also silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
// all the rest should cause errors
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertResponse($exp, $this->req($in[5]));
|
||||
$this->assertResponse($exp, $this->req($in[6]));
|
||||
$this->assertResponse($exp, $this->req($in[7]));
|
||||
$this->assertResponse($exp, $this->req($in[8]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[5]));
|
||||
$this->assertMessage($exp, $this->req($in[6]));
|
||||
$this->assertMessage($exp, $this->req($in[7]));
|
||||
$this->assertMessage($exp, $this->req($in[8]));
|
||||
Phake::verify(Arsse::$db)->subscriptionPropertiesSet(...$db[0]);
|
||||
Phake::verify(Arsse::$db)->subscriptionPropertiesSet(...$db[1]);
|
||||
Phake::verify(Arsse::$db)->subscriptionPropertiesSet(...$db[2]);
|
||||
|
@ -665,7 +665,7 @@ LONG_STRING;
|
|||
['id' => 3, 'unread' => 47],
|
||||
]));
|
||||
$exp = $this->respGood(['unread' => (string) (2112 + 42 + 47)]);
|
||||
$this->assertResponse($exp, $this->req($in));
|
||||
$this->assertMessage($exp, $this->req($in));
|
||||
}
|
||||
|
||||
public function testRetrieveTheServerConfiguration() {
|
||||
|
@ -679,8 +679,8 @@ LONG_STRING;
|
|||
['icons_dir' => "feed-icons", 'icons_url' => "feed-icons", 'daemon_is_running' => true, 'num_feeds' => 12],
|
||||
['icons_dir' => "feed-icons", 'icons_url' => "feed-icons", 'daemon_is_running' => false, 'num_feeds' => 2],
|
||||
];
|
||||
$this->assertResponse($this->respGood($exp[0]), $this->req($in));
|
||||
$this->assertResponse($this->respGood($exp[1]), $this->req($in));
|
||||
$this->assertMessage($this->respGood($exp[0]), $this->req($in));
|
||||
$this->assertMessage($this->respGood($exp[1]), $this->req($in));
|
||||
}
|
||||
|
||||
public function testUpdateAFeed() {
|
||||
|
@ -694,13 +694,13 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 1)->thenReturn(['id' => 1, 'feed' => 11]);
|
||||
Phake::when(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 2)->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
$exp = $this->respGood(['status' => "OK"]);
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
Phake::verify(Arsse::$db)->feedUpdate(11);
|
||||
$exp = $this->respErr("FEED_NOT_FOUND");
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
}
|
||||
|
||||
public function testAddALabel() {
|
||||
|
@ -731,21 +731,21 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->labelAdd(Arsse::$user->id, ['name' => " "])->thenThrow(new ExceptionInput("whitespace"));
|
||||
// correctly add two labels
|
||||
$exp = $this->respGood((-1 * API::LABEL_OFFSET) - 2);
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
$exp = $this->respGood((-1 * API::LABEL_OFFSET) - 3);
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// attempt to add the two labels again
|
||||
$exp = $this->respGood((-1 * API::LABEL_OFFSET) - 2);
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
$exp = $this->respGood((-1 * API::LABEL_OFFSET) - 3);
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
Phake::verify(Arsse::$db)->labelPropertiesGet(Arsse::$user->id, "Software", true);
|
||||
Phake::verify(Arsse::$db)->labelPropertiesGet(Arsse::$user->id, "Hardware", true);
|
||||
// add some invalid labels
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
}
|
||||
|
||||
public function testRemoveALabel() {
|
||||
|
@ -760,18 +760,18 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->labelRemove(Arsse::$user->id, 18)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
// succefully delete a label
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// try deleting it again (this should silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// delete a label which does not exist (this should also silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// delete some invalid labels (causes an error)
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
Phake::verify(Arsse::$db, Phake::times(2))->labelRemove(Arsse::$user->id, 18);
|
||||
Phake::verify(Arsse::$db)->labelRemove(Arsse::$user->id, 1088);
|
||||
}
|
||||
|
@ -804,21 +804,21 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->labelPropertiesSet(...$db[5])->thenThrow(new ExceptionInput("typeViolation"));
|
||||
// succefully rename a label
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
// rename a label which does not exist (this should silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
// rename a label causing a duplication (this should also silently fail)
|
||||
$exp = $this->respGood();
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
// all the rest should cause errors
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertResponse($exp, $this->req($in[5]));
|
||||
$this->assertResponse($exp, $this->req($in[6]));
|
||||
$this->assertResponse($exp, $this->req($in[7]));
|
||||
$this->assertResponse($exp, $this->req($in[8]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[5]));
|
||||
$this->assertMessage($exp, $this->req($in[6]));
|
||||
$this->assertMessage($exp, $this->req($in[7]));
|
||||
$this->assertMessage($exp, $this->req($in[8]));
|
||||
Phake::verify(Arsse::$db, Phake::times(6))->labelPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything());
|
||||
}
|
||||
|
||||
|
@ -890,7 +890,7 @@ LONG_STRING;
|
|||
],
|
||||
];
|
||||
for ($a = 0; $a < sizeof($in); $a++) {
|
||||
$this->assertResponse($this->respGood($exp[$a]), $this->req($in[$a]), "Test $a failed");
|
||||
$this->assertMessage($this->respGood($exp[$a]), $this->req($in[$a]), "Test $a failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -926,7 +926,7 @@ LONG_STRING;
|
|||
['id' => 0, 'kind' => "cat", 'counter' => 0],
|
||||
['id' => -2, 'kind' => "cat", 'counter' => 6],
|
||||
];
|
||||
$this->assertResponse($this->respGood($exp), $this->req($in));
|
||||
$this->assertMessage($this->respGood($exp), $this->req($in));
|
||||
}
|
||||
|
||||
public function testRetrieveTheLabelList() {
|
||||
|
@ -970,7 +970,7 @@ LONG_STRING;
|
|||
],
|
||||
];
|
||||
for ($a = 0; $a < sizeof($in); $a++) {
|
||||
$this->assertResponse($this->respGood($exp[$a]), $this->req($in[$a]), "Test $a failed");
|
||||
$this->assertMessage($this->respGood($exp[$a]), $this->req($in[$a]), "Test $a failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -996,20 +996,20 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->labelArticlesSet(Arsse::$user->id, 1088, (new Context)->articles($list[1]), false)->thenReturn(5);
|
||||
Phake::when(Arsse::$db)->labelArticlesSet(Arsse::$user->id, 1088, (new Context)->articles($list[2]), false)->thenReturn(2);
|
||||
$exp = $this->respGood(['status' => "OK", 'updated' => 89]);
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
Phake::verify(Arsse::$db)->labelArticlesSet(Arsse::$user->id, 1088, (new Context)->articles($list[1]), true);
|
||||
Phake::verify(Arsse::$db)->labelArticlesSet(Arsse::$user->id, 1088, (new Context)->articles($list[2]), true);
|
||||
$exp = $this->respGood(['status' => "OK", 'updated' => 7]);
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
Phake::verify(Arsse::$db)->labelArticlesSet(Arsse::$user->id, 1088, (new Context)->articles($list[1]), false);
|
||||
Phake::verify(Arsse::$db)->labelArticlesSet(Arsse::$user->id, 1088, (new Context)->articles($list[2]), false);
|
||||
$exp = $this->respGood(['status' => "OK", 'updated' => 0]);
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertResponse($exp, $this->req($in[4]));
|
||||
$this->assertResponse($exp, $this->req($in[5]));
|
||||
$this->assertResponse($exp, $this->req($in[6]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[4]));
|
||||
$this->assertMessage($exp, $this->req($in[5]));
|
||||
$this->assertMessage($exp, $this->req($in[6]));
|
||||
}
|
||||
|
||||
public function testRetrieveFeedTree() {
|
||||
|
@ -1024,9 +1024,9 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->articleStarred($this->anything())->thenReturn($this->starred);
|
||||
// the expectations are packed tightly since they're very verbose; one can use var_export() (or convert to JSON) to pretty-print them
|
||||
$exp = ['categories'=>['identifier'=>'id','label'=>'name','items'=>[['name'=>'Special','id'=>'CAT:-1','bare_id'=>-1,'type'=>'category','unread'=>0,'items'=>[['name'=>'All articles','id'=>'FEED:-4','bare_id'=>-4,'icon'=>'images/folder.png','unread'=>35,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Fresh articles','id'=>'FEED:-3','bare_id'=>-3,'icon'=>'images/fresh.png','unread'=>7,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Starred articles','id'=>'FEED:-1','bare_id'=>-1,'icon'=>'images/star.png','unread'=>4,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Published articles','id'=>'FEED:-2','bare_id'=>-2,'icon'=>'images/feed.png','unread'=>0,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Archived articles','id'=>'FEED:0','bare_id'=>0,'icon'=>'images/archive.png','unread'=>0,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Recently read','id'=>'FEED:-6','bare_id'=>-6,'icon'=>'images/time.png','unread'=>0,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],],],['name'=>'Labels','id'=>'CAT:-2','bare_id'=>-2,'type'=>'category','unread'=>6,'items'=>[['name'=>'Fascinating','id'=>'FEED:-1027','bare_id'=>-1027,'unread'=>0,'icon'=>'images/label.png','type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'','fg_color'=>'','bg_color'=>'',],['name'=>'Interesting','id'=>'FEED:-1029','bare_id'=>-1029,'unread'=>0,'icon'=>'images/label.png','type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'','fg_color'=>'','bg_color'=>'',],['name'=>'Logical','id'=>'FEED:-1025','bare_id'=>-1025,'unread'=>0,'icon'=>'images/label.png','type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'','fg_color'=>'','bg_color'=>'',],],],['name'=>'Photography','id'=>'CAT:4','bare_id'=>4,'parent_id'=>null,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(0 feeds)','items'=>[],],['name'=>'Politics','id'=>'CAT:3','bare_id'=>3,'parent_id'=>null,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(3 feeds)','items'=>[['name'=>'Local','id'=>'CAT:5','bare_id'=>5,'parent_id'=>3,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(1 feed)','items'=>[['name'=>'Toronto Star','id'=>'FEED:2','bare_id'=>2,'icon'=>'feed-icons/2.ico','error'=>'oops','param'=>'2011-11-11T11:11:11Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],['name'=>'National','id'=>'CAT:6','bare_id'=>6,'parent_id'=>3,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(2 feeds)','items'=>[['name'=>'CBC News','id'=>'FEED:4','bare_id'=>4,'icon'=>'feed-icons/4.ico','error'=>'','param'=>'2017-10-09T15:58:34Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],['name'=>'Ottawa Citizen','id'=>'FEED:5','bare_id'=>5,'icon'=>false,'error'=>'','param'=>'2017-07-07T17:07:17Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],],],['name'=>'Science','id'=>'CAT:1','bare_id'=>1,'parent_id'=>null,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(2 feeds)','items'=>[['name'=>'Rocketry','id'=>'CAT:2','bare_id'=>2,'parent_id'=>1,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(1 feed)','items'=>[['name'=>'NASA JPL','id'=>'FEED:1','bare_id'=>1,'icon'=>false,'error'=>'','param'=>'2017-09-15T22:54:16Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],['name'=>'Ars Technica','id'=>'FEED:3','bare_id'=>3,'icon'=>'feed-icons/3.ico','error'=>'argh','param'=>'2016-05-23T06:40:02Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],['name'=>'Uncategorized','id'=>'CAT:0','bare_id'=>0,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'parent_id'=>null,'param'=>'(1 feed)','items'=>[['name'=>'Eurogamer','id'=>'FEED:6','bare_id'=>6,'icon'=>'feed-icons/6.ico','error'=>'','param'=>'2010-02-12T20:08:47Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],],],];
|
||||
$this->assertResponse($this->respGood($exp), $this->req($in[0]));
|
||||
$this->assertMessage($this->respGood($exp), $this->req($in[0]));
|
||||
$exp = ['categories'=>['identifier'=>'id','label'=>'name','items'=>[['name'=>'Special','id'=>'CAT:-1','bare_id'=>-1,'type'=>'category','unread'=>0,'items'=>[['name'=>'All articles','id'=>'FEED:-4','bare_id'=>-4,'icon'=>'images/folder.png','unread'=>35,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Fresh articles','id'=>'FEED:-3','bare_id'=>-3,'icon'=>'images/fresh.png','unread'=>7,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Starred articles','id'=>'FEED:-1','bare_id'=>-1,'icon'=>'images/star.png','unread'=>4,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Published articles','id'=>'FEED:-2','bare_id'=>-2,'icon'=>'images/feed.png','unread'=>0,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Archived articles','id'=>'FEED:0','bare_id'=>0,'icon'=>'images/archive.png','unread'=>0,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],['name'=>'Recently read','id'=>'FEED:-6','bare_id'=>-6,'icon'=>'images/time.png','unread'=>0,'type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'',],],],['name'=>'Labels','id'=>'CAT:-2','bare_id'=>-2,'type'=>'category','unread'=>6,'items'=>[['name'=>'Fascinating','id'=>'FEED:-1027','bare_id'=>-1027,'unread'=>0,'icon'=>'images/label.png','type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'','fg_color'=>'','bg_color'=>'',],['name'=>'Interesting','id'=>'FEED:-1029','bare_id'=>-1029,'unread'=>0,'icon'=>'images/label.png','type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'','fg_color'=>'','bg_color'=>'',],['name'=>'Logical','id'=>'FEED:-1025','bare_id'=>-1025,'unread'=>0,'icon'=>'images/label.png','type'=>'feed','auxcounter'=>0,'error'=>'','updated'=>'','fg_color'=>'','bg_color'=>'',],],],['name'=>'Politics','id'=>'CAT:3','bare_id'=>3,'parent_id'=>null,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(3 feeds)','items'=>[['name'=>'Local','id'=>'CAT:5','bare_id'=>5,'parent_id'=>3,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(1 feed)','items'=>[['name'=>'Toronto Star','id'=>'FEED:2','bare_id'=>2,'icon'=>'feed-icons/2.ico','error'=>'oops','param'=>'2011-11-11T11:11:11Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],['name'=>'National','id'=>'CAT:6','bare_id'=>6,'parent_id'=>3,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(2 feeds)','items'=>[['name'=>'CBC News','id'=>'FEED:4','bare_id'=>4,'icon'=>'feed-icons/4.ico','error'=>'','param'=>'2017-10-09T15:58:34Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],['name'=>'Ottawa Citizen','id'=>'FEED:5','bare_id'=>5,'icon'=>false,'error'=>'','param'=>'2017-07-07T17:07:17Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],],],['name'=>'Science','id'=>'CAT:1','bare_id'=>1,'parent_id'=>null,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(2 feeds)','items'=>[['name'=>'Rocketry','id'=>'CAT:2','bare_id'=>2,'parent_id'=>1,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'param'=>'(1 feed)','items'=>[['name'=>'NASA JPL','id'=>'FEED:1','bare_id'=>1,'icon'=>false,'error'=>'','param'=>'2017-09-15T22:54:16Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],['name'=>'Ars Technica','id'=>'FEED:3','bare_id'=>3,'icon'=>'feed-icons/3.ico','error'=>'argh','param'=>'2016-05-23T06:40:02Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],['name'=>'Uncategorized','id'=>'CAT:0','bare_id'=>0,'type'=>'category','auxcounter'=>0,'unread'=>0,'child_unread'=>0,'checkbox'=>false,'parent_id'=>null,'param'=>'(1 feed)','items'=>[['name'=>'Eurogamer','id'=>'FEED:6','bare_id'=>6,'icon'=>'feed-icons/6.ico','error'=>'','param'=>'2010-02-12T20:08:47Z','unread'=>0,'auxcounter'=>0,'checkbox'=>false,],],],],],];
|
||||
$this->assertResponse($this->respGood($exp), $this->req($in[1]));
|
||||
$this->assertMessage($this->respGood($exp), $this->req($in[1]));
|
||||
}
|
||||
|
||||
public function testMarkFeedsAsRead() {
|
||||
|
@ -1058,12 +1058,12 @@ LONG_STRING;
|
|||
$exp = $this->respGood(['status' => "OK"]);
|
||||
// verify the above are in fact no-ops
|
||||
for ($a = 0; $a < sizeof($in1); $a++) {
|
||||
$this->assertResponse($exp, $this->req($in1[$a]), "Test $a failed");
|
||||
$this->assertMessage($exp, $this->req($in1[$a]), "Test $a failed");
|
||||
}
|
||||
Phake::verify(Arsse::$db, Phake::times(0))->articleMark;
|
||||
// verify the simple contexts
|
||||
for ($a = 0; $a < sizeof($in2); $a++) {
|
||||
$this->assertResponse($exp, $this->req($in2[$a]), "Test $a failed");
|
||||
$this->assertMessage($exp, $this->req($in2[$a]), "Test $a failed");
|
||||
}
|
||||
Phake::verify(Arsse::$db)->articleMark($this->anything(), ['read' => true], new Context);
|
||||
Phake::verify(Arsse::$db)->articleMark($this->anything(), ['read' => true], (new Context)->starred(true));
|
||||
|
@ -1075,7 +1075,7 @@ LONG_STRING;
|
|||
// verify the time-based mock
|
||||
$t = Date::sub("PT24H");
|
||||
for ($a = 0; $a < sizeof($in3); $a++) {
|
||||
$this->assertResponse($exp, $this->req($in3[$a]), "Test $a failed");
|
||||
$this->assertMessage($exp, $this->req($in3[$a]), "Test $a failed");
|
||||
}
|
||||
Phake::verify(Arsse::$db)->articleMark($this->anything(), ['read' => true], (new Context)->modifiedSince($t));
|
||||
}
|
||||
|
@ -1210,10 +1210,10 @@ LONG_STRING;
|
|||
],
|
||||
];
|
||||
for ($a = 0; $a < sizeof($in1); $a++) {
|
||||
$this->assertResponse($this->respGood($exp[$a]), $this->req($in1[$a]), "Test $a failed");
|
||||
$this->assertMessage($this->respGood($exp[$a]), $this->req($in1[$a]), "Test $a failed");
|
||||
}
|
||||
for ($a = 0; $a < sizeof($in2); $a++) {
|
||||
$this->assertResponse($this->respGood([]), $this->req($in2[$a]), "Test $a failed");
|
||||
$this->assertMessage($this->respGood([]), $this->req($in2[$a]), "Test $a failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1323,7 +1323,7 @@ LONG_STRING;
|
|||
$this->respErr("INCORRECT_USAGE"),
|
||||
];
|
||||
for ($a = 0; $a < sizeof($in); $a++) {
|
||||
$this->assertResponse($out[$a], $this->req($in[$a]), "Test $a failed");
|
||||
$this->assertMessage($out[$a], $this->req($in[$a]), "Test $a failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1347,10 +1347,10 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->articleList($this->anything(), (new Context)->articles([101]))->thenReturn(new Result([$this->articles[0]]));
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (new Context)->articles([102]))->thenReturn(new Result([$this->articles[1]]));
|
||||
$exp = $this->respErr("INCORRECT_USAGE");
|
||||
$this->assertResponse($exp, $this->req($in[0]));
|
||||
$this->assertResponse($exp, $this->req($in[1]));
|
||||
$this->assertResponse($exp, $this->req($in[2]));
|
||||
$this->assertResponse($exp, $this->req($in[3]));
|
||||
$this->assertMessage($exp, $this->req($in[0]));
|
||||
$this->assertMessage($exp, $this->req($in[1]));
|
||||
$this->assertMessage($exp, $this->req($in[2]));
|
||||
$this->assertMessage($exp, $this->req($in[3]));
|
||||
$exp = [
|
||||
[
|
||||
'id' => "101",
|
||||
|
@ -1407,13 +1407,13 @@ LONG_STRING;
|
|||
'content' => '<p>Article content 2</p>',
|
||||
],
|
||||
];
|
||||
$this->assertResponse($this->respGood($exp), $this->req($in[4]));
|
||||
$this->assertResponse($this->respGood([$exp[0]]), $this->req($in[5]));
|
||||
$this->assertResponse($this->respGood([$exp[1]]), $this->req($in[6]));
|
||||
$this->assertMessage($this->respGood($exp), $this->req($in[4]));
|
||||
$this->assertMessage($this->respGood([$exp[0]]), $this->req($in[5]));
|
||||
$this->assertMessage($this->respGood([$exp[1]]), $this->req($in[6]));
|
||||
// test the special case when labels are not used
|
||||
Phake::when(Arsse::$db)->labelList($this->anything())->thenReturn(new Result([]));
|
||||
Phake::when(Arsse::$db)->labelList($this->anything(), false)->thenReturn(new Result([]));
|
||||
$this->assertResponse($this->respGood([$exp[0]]), $this->req($in[5]));
|
||||
$this->assertMessage($this->respGood([$exp[0]]), $this->req($in[5]));
|
||||
}
|
||||
|
||||
public function testRetrieveCompactHeadlines() {
|
||||
|
@ -1492,13 +1492,13 @@ LONG_STRING;
|
|||
$this->respGood([['id' => 1003]]),
|
||||
];
|
||||
for ($a = 0; $a < sizeof($in1); $a++) {
|
||||
$this->assertResponse($out1[$a], $this->req($in1[$a]), "Test $a failed");
|
||||
$this->assertMessage($out1[$a], $this->req($in1[$a]), "Test $a failed");
|
||||
}
|
||||
for ($a = 0; $a < sizeof($in2); $a++) {
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (clone $c)->unread(false)->markedSince(Date::sub("PT24H")), Database::LIST_MINIMAL)->thenReturn(new Result([['id' => 1001]]));
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (clone $c)->unread(true)->modifiedSince(Date::sub("PT24H")), Database::LIST_MINIMAL)->thenReturn(new Result([['id' => 1002]]));
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (clone $c)->unread(true)->modifiedSince(Date::sub("PT24H"))->starred(true), Database::LIST_MINIMAL)->thenReturn(new Result([['id' => 1003]]));
|
||||
$this->assertResponse($out2[$a], $this->req($in2[$a]), "Test $a failed");
|
||||
$this->assertMessage($out2[$a], $this->req($in2[$a]), "Test $a failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1600,16 +1600,16 @@ LONG_STRING;
|
|||
$this->outputHeadlines(1003),
|
||||
];
|
||||
for ($a = 0; $a < sizeof($in1); $a++) {
|
||||
$this->assertResponse($this->respGood([]), $this->req($in1[$a]), "Test $a failed");
|
||||
$this->assertMessage($this->respGood([]), $this->req($in1[$a]), "Test $a failed");
|
||||
}
|
||||
for ($a = 0; $a < sizeof($in2); $a++) {
|
||||
$this->assertResponse($out2[$a], $this->req($in2[$a]), "Test $a failed");
|
||||
$this->assertMessage($out2[$a], $this->req($in2[$a]), "Test $a failed");
|
||||
}
|
||||
for ($a = 0; $a < sizeof($in3); $a++) {
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (clone $c)->unread(false)->markedSince(Date::sub("PT24H")), Database::LIST_FULL)->thenReturn($this->generateHeadlines(1001));
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (clone $c)->unread(true)->modifiedSince(Date::sub("PT24H")), Database::LIST_FULL)->thenReturn($this->generateHeadlines(1002));
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (clone $c)->unread(true)->modifiedSince(Date::sub("PT24H"))->starred(true), Database::LIST_FULL)->thenReturn($this->generateHeadlines(1003));
|
||||
$this->assertResponse($out3[$a], $this->req($in3[$a]), "Test $a failed");
|
||||
$this->assertMessage($out3[$a], $this->req($in3[$a]), "Test $a failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1639,7 +1639,7 @@ LONG_STRING;
|
|||
Phake::when(Arsse::$db)->articleCount($this->anything(), (new Context)->unread(true))->thenReturn(1);
|
||||
// sanity check; this makes sure extra fields are not included in default situations
|
||||
$test = $this->req($in[0]);
|
||||
$this->assertResponse($this->outputHeadlines(1), $test);
|
||||
$this->assertMessage($this->outputHeadlines(1), $test);
|
||||
// test 'show_content'
|
||||
$test = $this->req($in[1]);
|
||||
$this->assertArrayHasKey("content", $test->getPayload()['content'][0]);
|
||||
|
@ -1671,21 +1671,21 @@ LONG_STRING;
|
|||
['id' => -4, 'is_cat' => false, 'first_id' => 1],
|
||||
$this->outputHeadlines(1)->getPayload()['content'],
|
||||
]);
|
||||
$this->assertResponse($exp, $test);
|
||||
$this->assertMessage($exp, $test);
|
||||
// test 'include_header' with a category
|
||||
$test = $this->req($in[4]);
|
||||
$exp = $this->respGood([
|
||||
['id' => -3, 'is_cat' => true, 'first_id' => 1],
|
||||
$this->outputHeadlines(1)->getPayload()['content'],
|
||||
]);
|
||||
$this->assertResponse($exp, $test);
|
||||
$this->assertMessage($exp, $test);
|
||||
// test 'include_header' with an empty result
|
||||
$test = $this->req($in[5]);
|
||||
$exp = $this->respGood([
|
||||
['id' => -1, 'is_cat' => true, 'first_id' => 0],
|
||||
[],
|
||||
]);
|
||||
$this->assertResponse($exp, $test);
|
||||
$this->assertMessage($exp, $test);
|
||||
// test 'include_header' with an erroneous result
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (new Context)->limit(200)->reverse(true)->subscription(2112), $this->anything())->thenThrow(new ExceptionInput("subjectMissing"));
|
||||
$test = $this->req($in[6]);
|
||||
|
@ -1693,14 +1693,14 @@ LONG_STRING;
|
|||
['id' => 2112, 'is_cat' => false, 'first_id' => 0],
|
||||
[],
|
||||
]);
|
||||
$this->assertResponse($exp, $test);
|
||||
$this->assertMessage($exp, $test);
|
||||
// test 'include_header' with ascending order
|
||||
$test = $this->req($in[7]);
|
||||
$exp = $this->respGood([
|
||||
['id' => -4, 'is_cat' => false, 'first_id' => 0],
|
||||
$this->outputHeadlines(1)->getPayload()['content'],
|
||||
]);
|
||||
$this->assertResponse($exp, $test);
|
||||
$this->assertMessage($exp, $test);
|
||||
// test 'include_header' with skip
|
||||
Phake::when(Arsse::$db)->articleList($this->anything(), (new Context)->reverse(true)->limit(1)->subscription(42), Database::LIST_MINIMAL)->thenReturn($this->generateHeadlines(1867));
|
||||
$test = $this->req($in[8]);
|
||||
|
@ -1708,14 +1708,14 @@ LONG_STRING;
|
|||
['id' => 42, 'is_cat' => false, 'first_id' => 1867],
|
||||
$this->outputHeadlines(1)->getPayload()['content'],
|
||||
]);
|
||||
$this->assertResponse($exp, $test);
|
||||
$this->assertMessage($exp, $test);
|
||||
// test 'include_header' with skip and ascending order
|
||||
$test = $this->req($in[9]);
|
||||
$exp = $this->respGood([
|
||||
['id' => 42, 'is_cat' => false, 'first_id' => 0],
|
||||
$this->outputHeadlines(1)->getPayload()['content'],
|
||||
]);
|
||||
$this->assertResponse($exp, $test);
|
||||
$this->assertMessage($exp, $test);
|
||||
// test 'show_excerpt'
|
||||
$exp1 = "“This & that, you know‽”";
|
||||
$exp2 = "Pour vous faire mieux connaitre d’ou\u{300} vient l’erreur de ceux qui bla\u{302}ment la volupte\u{301}, et qui louent en…";
|
||||
|
|
|
@ -52,19 +52,19 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Phake::when(Arsse::$db)->subscriptionFavicon(1337)->thenReturn("http://example.org/icon.gif\r\nLocation: http://bad.example.com/");
|
||||
// these requests should succeed
|
||||
$exp = new Response(301, ['Location' => "http://example.com/favicon.ico"]);
|
||||
$this->assertResponse($exp, $this->req("42.ico"));
|
||||
$this->assertMessage($exp, $this->req("42.ico"));
|
||||
$exp = new Response(301, ['Location' => "http://example.net/logo.png"]);
|
||||
$this->assertResponse($exp, $this->req("2112.ico"));
|
||||
$this->assertMessage($exp, $this->req("2112.ico"));
|
||||
$exp = new Response(301, ['Location' => "http://example.org/icon.gif"]);
|
||||
$this->assertResponse($exp, $this->req("1337.ico"));
|
||||
$this->assertMessage($exp, $this->req("1337.ico"));
|
||||
// these requests should fail
|
||||
$exp = new Response(404);
|
||||
$this->assertResponse($exp, $this->req("ook.ico"));
|
||||
$this->assertResponse($exp, $this->req("ook"));
|
||||
$this->assertResponse($exp, $this->req("47.ico"));
|
||||
$this->assertResponse($exp, $this->req("2112.png"));
|
||||
$this->assertMessage($exp, $this->req("ook.ico"));
|
||||
$this->assertMessage($exp, $this->req("ook"));
|
||||
$this->assertMessage($exp, $this->req("47.ico"));
|
||||
$this->assertMessage($exp, $this->req("2112.png"));
|
||||
// only GET is allowed
|
||||
$exp = new Response(405, ['Allow' => "GET"]);
|
||||
$this->assertResponse($exp, $this->req("2112.ico", "PUT"));
|
||||
$this->assertMessage($exp, $this->req("2112.ico", "PUT"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ use JKingWeb\Arsse\Exception;
|
|||
use JKingWeb\Arsse\Arsse;
|
||||
use JKingWeb\Arsse\Conf;
|
||||
use JKingWeb\Arsse\Misc\Date;
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
@ -45,8 +48,19 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
protected function assertResponse(ResponseInterface $exp, ResponseInterface $act, string $text = null) {
|
||||
$this->assertEquals($exp->getStatusCode(), $act->getStatusCode(), $text);
|
||||
protected function assertMessage(MessageInterface $exp, MessageInterface $act, string $text = null) {
|
||||
if ($exp instanceof ResponseInterface) {
|
||||
$this->assertInstanceOf(ResponseInterface::class, $act, $text);
|
||||
$this->assertEquals($exp->getStatusCode(), $act->getStatusCode(), $text);
|
||||
} elseif ($exp instanceof RequestInterface) {
|
||||
if ($exp instanceof ServerRequestInterface) {
|
||||
$this->assertInstanceOf(ServerRequestInterface::class, $act, $text);
|
||||
$this->assertEquals($exp->getAttributes(), $act->getAttributes(), $text);
|
||||
}
|
||||
$this->assertInstanceOf(RequestInterface::class, $act, $text);
|
||||
$this->assertSame($exp->getRequestMethod(), $act->getRequestMethod(), $text);
|
||||
$this->assertSame($exp->getRequestTarget(), $act->getRequestTarget(), $text);
|
||||
}
|
||||
if ($exp instanceof JsonResponse) {
|
||||
$this->assertEquals($exp->getPayload(), $act->getPayload(), $text);
|
||||
$this->assertSame($exp->getPayload(), $act->getPayload(), $text);
|
||||
|
|
Loading…
Reference in a new issue