diff --git a/tests/REST/TinyTinyRSS/TestTinyTinyAPI.php b/tests/REST/TinyTinyRSS/TestTinyTinyAPI.php index 8a176dcb..bb16cc04 100644 --- a/tests/REST/TinyTinyRSS/TestTinyTinyAPI.php +++ b/tests/REST/TinyTinyRSS/TestTinyTinyAPI.php @@ -117,6 +117,10 @@ class TestTinyTinyAPI extends Test\AbstractTest { LONG_STRING; + protected function req($data) : Response { + return $this->h->dispatch(new Request("POST", "", json_encode($data))); + } + protected function respGood($content = null, $seq = 0): Response { return new Response(200, [ 'seq' => $seq, @@ -181,13 +185,13 @@ LONG_STRING; 'password' => "secret", ]; $exp = $this->respGood(['session_id' => "PriestsOfSyrinx", 'api_level' => \JKingWeb\Arsse\REST\TinyTinyRSS\API::LEVEL]); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($data)))); + $this->assertEquals($exp, $this->req($data)); $exp = $this->respGood(['session_id' => "SolarFederation", 'api_level' => \JKingWeb\Arsse\REST\TinyTinyRSS\API::LEVEL]); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($data)))); + $this->assertEquals($exp, $this->req($data)); // test a failed log-in $data['password'] = "superman"; $exp = $this->respErr("LOGIN_ERROR"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($data)))); + $this->assertEquals($exp, $this->req($data)); // logging in should never try to resume a session Phake::verify(Arsse::$db, Phake::times(0))->sessionResume($this->anything()); } @@ -199,7 +203,7 @@ LONG_STRING; 'sid' => "PriestsOfSyrinx", ]; $exp = $this->respGood(['status' => "OK"]); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($data)))); + $this->assertEquals($exp, $this->req($data)); Phake::verify(Arsse::$db)->sessionDestroy(Arsse::$user->id, "PriestsOfSyrinx"); } @@ -209,10 +213,10 @@ LONG_STRING; 'sid' => "PriestsOfSyrinx", ]; $exp = $this->respGood(['status' => true]); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($data)))); + $this->assertEquals($exp, $this->req($data)); $data['sid'] = "SolarFederation"; $exp = $this->respErr("NOT_LOGGED_IN"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($data)))); + $this->assertEquals($exp, $this->req($data)); } public function testRetrieveServerVersion() { @@ -224,7 +228,7 @@ LONG_STRING; 'version' => \JKingWeb\Arsse\REST\TinyTinyRSS\API::VERSION, 'arsse_version' => Arsse::VERSION, ]); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($data)))); + $this->assertEquals($exp, $this->req($data)); } public function testRetrieveProtocolLevel() { @@ -233,7 +237,7 @@ LONG_STRING; 'sid' => "PriestsOfSyrinx", ]; $exp = $this->respGood(['level' => \JKingWeb\Arsse\REST\TinyTinyRSS\API::LEVEL]); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($data)))); + $this->assertEquals($exp, $this->req($data)); } public function testAddACategory() { @@ -267,24 +271,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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); $exp = $this->respGood(3); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // attempt to add the two folders again $exp = $this->respGood(2); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); $exp = $this->respGood(3); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); + $this->assertEquals($exp, $this->req($in[2])); // add some invalid folders $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); + $this->assertEquals($exp, $this->req($in[3])); + $this->assertEquals($exp, $this->req($in[4])); + $this->assertEquals($exp, $this->req($in[5])); } public function testRemoveACategory() { @@ -297,16 +301,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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // try deleting it again (this should silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // delete a folder which does not exist (this should also silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // delete an invalid folder (causes an error) $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); + $this->assertEquals($exp, $this->req($in[2])); Phake::verify(Arsse::$db, Phake::times(3))->folderRemove(Arsse::$user->id, $this->anything()); } @@ -344,21 +348,21 @@ LONG_STRING; Phake::when(Arsse::$db)->folderPropertiesSet(...$db[8])->thenThrow(new ExceptionInput("typeViolation")); // succefully move a folder $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // move a folder which does not exist (this should silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // move a folder causing a duplication (this should also silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[6])))); + $this->assertEquals($exp, $this->req($in[2])); + $this->assertEquals($exp, $this->req($in[3])); + $this->assertEquals($exp, $this->req($in[6])); // all the rest should cause errors $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[7])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[8])))); + $this->assertEquals($exp, $this->req($in[4])); + $this->assertEquals($exp, $this->req($in[5])); + $this->assertEquals($exp, $this->req($in[7])); + $this->assertEquals($exp, $this->req($in[8])); Phake::verify(Arsse::$db, Phake::times(5))->folderPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything()); } @@ -384,21 +388,21 @@ LONG_STRING; Phake::when(Arsse::$db)->folderPropertiesSet(...$db[2])->thenThrow(new ExceptionInput("constraintViolation")); // succefully rename a folder $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // rename a folder which does not exist (this should silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // rename a folder causing a duplication (this should also silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); + $this->assertEquals($exp, $this->req($in[2])); // all the rest should cause errors $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[6])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[7])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[8])))); + $this->assertEquals($exp, $this->req($in[3])); + $this->assertEquals($exp, $this->req($in[4])); + $this->assertEquals($exp, $this->req($in[5])); + $this->assertEquals($exp, $this->req($in[6])); + $this->assertEquals($exp, $this->req($in[7])); + $this->assertEquals($exp, $this->req($in[8])); Phake::verify(Arsse::$db, Phake::times(3))->folderPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything()); } @@ -468,11 +472,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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[$a]))), "Failed test $a"); + $this->assertEquals($exp, $this->req($in[$a]), "Failed test $a"); } $exp = $this->respErr("INCORRECT_USAGE"); for ($a = (sizeof($in) - 4); $a < sizeof($in); $a++) { - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[$a]))), "Failed test $a"); + $this->assertEquals($exp, $this->req($in[$a]), "Failed test $a"); } Phake::verify(Arsse::$db, Phake::times(0))->subscriptionPropertiesSet(Arsse::$user->id, 4, ['folder' => 1]); } @@ -489,13 +493,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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // try deleting it again (this should noisily fail, as should everything else) $exp = $this->respErr("FEED_NOT_FOUND"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); + $this->assertEquals($exp, $this->req($in[0])); + $this->assertEquals($exp, $this->req($in[1])); + $this->assertEquals($exp, $this->req($in[2])); + $this->assertEquals($exp, $this->req($in[3])); Phake::verify(Arsse::$db, Phake::times(5))->subscriptionRemove(Arsse::$user->id, $this->anything()); } @@ -523,21 +527,21 @@ LONG_STRING; Phake::when(Arsse::$db)->subscriptionPropertiesSet(...$db[3])->thenThrow(new ExceptionInput("constraintViolation")); // succefully move a subscription $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // move a subscription which does not exist (this should silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // move a subscription causing a duplication (this should also silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); + $this->assertEquals($exp, $this->req($in[2])); + $this->assertEquals($exp, $this->req($in[3])); // all the rest should cause errors $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[6])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[7])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[8])))); + $this->assertEquals($exp, $this->req($in[4])); + $this->assertEquals($exp, $this->req($in[5])); + $this->assertEquals($exp, $this->req($in[6])); + $this->assertEquals($exp, $this->req($in[7])); + $this->assertEquals($exp, $this->req($in[8])); Phake::verify(Arsse::$db, Phake::times(4))->subscriptionPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything()); } @@ -563,21 +567,21 @@ LONG_STRING; Phake::when(Arsse::$db)->subscriptionPropertiesSet(...$db[2])->thenThrow(new ExceptionInput("constraintViolation")); // succefully rename a subscription $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // rename a subscription which does not exist (this should silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // rename a subscription causing a duplication (this should also silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); + $this->assertEquals($exp, $this->req($in[2])); // all the rest should cause errors $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[6])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[7])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[8])))); + $this->assertEquals($exp, $this->req($in[3])); + $this->assertEquals($exp, $this->req($in[4])); + $this->assertEquals($exp, $this->req($in[5])); + $this->assertEquals($exp, $this->req($in[6])); + $this->assertEquals($exp, $this->req($in[7])); + $this->assertEquals($exp, $this->req($in[8])); Phake::verify(Arsse::$db, Phake::times(3))->subscriptionPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything()); } @@ -589,7 +593,7 @@ LONG_STRING; ['id' => 3, 'unread' => 47], ])); $exp = $this->respGood(['unread' => 2112 + 42 + 47]); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in)))); + $this->assertEquals($exp, $this->req($in)); } public function testRetrieveTheServerConfiguration() { @@ -603,8 +607,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->assertEquals($this->respGood($exp[0]), $this->h->dispatch(new Request("POST", "", json_encode($in)))); - $this->assertEquals($this->respGood($exp[1]), $this->h->dispatch(new Request("POST", "", json_encode($in)))); + $this->assertEquals($this->respGood($exp[0]), $this->req($in)); + $this->assertEquals($this->respGood($exp[1]), $this->req($in)); } public function testUpdateAFeed() { @@ -618,13 +622,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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); Phake::verify(Arsse::$db)->feedUpdate(11); $exp = $this->respErr("FEED_NOT_FOUND"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); + $this->assertEquals($exp, $this->req($in[2])); + $this->assertEquals($exp, $this->req($in[3])); } public function testAddALabel() { @@ -655,21 +659,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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); $exp = $this->respGood((-1 * API::LABEL_OFFSET) - 3); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // attempt to add the two labels again $exp = $this->respGood((-1 * API::LABEL_OFFSET) - 2); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); $exp = $this->respGood((-1 * API::LABEL_OFFSET) - 3); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); + $this->assertEquals($exp, $this->req($in[2])); + $this->assertEquals($exp, $this->req($in[3])); + $this->assertEquals($exp, $this->req($in[4])); } public function testRemoveALabel() { @@ -684,18 +688,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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // try deleting it again (this should silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // delete a label which does not exist (this should also silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // delete some invalid labels (causes an error) $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); + $this->assertEquals($exp, $this->req($in[2])); + $this->assertEquals($exp, $this->req($in[3])); + $this->assertEquals($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); } @@ -728,21 +732,21 @@ LONG_STRING; Phake::when(Arsse::$db)->labelPropertiesSet(...$db[5])->thenThrow(new ExceptionInput("typeViolation")); // succefully rename a label $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($exp, $this->req($in[0])); // rename a label which does not exist (this should silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($exp, $this->req($in[1])); // rename a label causing a duplication (this should also silently fail) $exp = $this->respGood(); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); + $this->assertEquals($exp, $this->req($in[2])); // all the rest should cause errors $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[6])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[7])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[8])))); + $this->assertEquals($exp, $this->req($in[3])); + $this->assertEquals($exp, $this->req($in[4])); + $this->assertEquals($exp, $this->req($in[5])); + $this->assertEquals($exp, $this->req($in[6])); + $this->assertEquals($exp, $this->req($in[7])); + $this->assertEquals($exp, $this->req($in[8])); Phake::verify(Arsse::$db, Phake::times(6))->labelPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything()); } @@ -814,7 +818,7 @@ LONG_STRING; ], ]; for ($a = 0; $a < sizeof($in); $a++) { - $this->assertEquals($this->respGood($exp[$a]), $this->h->dispatch(new Request("POST", "", json_encode($in[$a]))), "Test $a failed"); + $this->assertEquals($this->respGood($exp[$a]), $this->req($in[$a]), "Test $a failed"); } } @@ -847,7 +851,7 @@ LONG_STRING; ['id' => 1, 'kind' => "cat", 'counter' => 7], ['id' => -2, 'kind' => "cat", 'counter' => 6], ]; - $this->assertResponse($this->respGood($exp), $this->h->dispatch(new Request("POST", "", json_encode($in)))); + $this->assertResponse($this->respGood($exp), $this->req($in)); } public function testRetrieveTheLabelList() { @@ -891,7 +895,7 @@ LONG_STRING; ], ]; for ($a = 0; $a < sizeof($in); $a++) { - $this->assertResponse($this->respGood($exp[$a]), $this->h->dispatch(new Request("POST", "", json_encode($in[$a]))), "Test $a failed"); + $this->assertResponse($this->respGood($exp[$a]), $this->req($in[$a]), "Test $a failed"); } } @@ -917,20 +921,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->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertResponse($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->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertResponse($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' => 89]); - $this->assertResponse($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); + $this->assertResponse($exp, $this->req($in[2])); $exp = $this->respErr("INCORRECT_USAGE"); - $this->assertResponse($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); - $this->assertResponse($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); - $this->assertResponse($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); - $this->assertResponse($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[6])))); + $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])); } public function testRetrieveFeedTree() { @@ -945,9 +949,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'=>[['id'=>'CAT:-1','items'=>[['id'=>'FEED:-4','name'=>'All articles','unread'=>35,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/folder.png','bare_id'=>-4,'auxcounter'=>0,],['id'=>'FEED:-3','name'=>'Fresh articles','unread'=>7,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/fresh.png','bare_id'=>-3,'auxcounter'=>0,],['id'=>'FEED:-1','name'=>'Starred articles','unread'=>4,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/star.png','bare_id'=>-1,'auxcounter'=>0,],['id'=>'FEED:-2','name'=>'Published articles','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/feed.png','bare_id'=>-2,'auxcounter'=>0,],['id'=>'FEED:0','name'=>'Archived articles','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/archive.png','bare_id'=>0,'auxcounter'=>0,],['id'=>'FEED:-6','name'=>'Recently read','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/time.png','bare_id'=>-6,'auxcounter'=>0,],],'name'=>'Special','type'=>'category','unread'=>0,'bare_id'=>-1,],['id'=>'CAT:-2','items'=>[['id'=>'FEED:-1027','name'=>'Fascinating','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/label.png','bare_id'=>-1027,'auxcounter'=>0,'fg_color'=>'','bg_color'=>'',],['id'=>'FEED:-1029','name'=>'Interesting','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/label.png','bare_id'=>-1029,'auxcounter'=>0,'fg_color'=>'','bg_color'=>'',],['id'=>'FEED:-1025','name'=>'Logical','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/label.png','bare_id'=>-1025,'auxcounter'=>0,'fg_color'=>'','bg_color'=>'',],],'name'=>'Labels','type'=>'category','unread'=>6,'bare_id'=>-2,],['id'=>'CAT:4','bare_id'=>4,'auxcounter'=>0,'name'=>'Photography','items'=>[],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'parent_id'=>null,'param'=>'(0 feeds)',],['id'=>'CAT:3','bare_id'=>3,'auxcounter'=>0,'name'=>'Politics','items'=>[['id'=>'CAT:5','bare_id'=>5,'name'=>'Local','items'=>[['id'=>'FEED:2','bare_id'=>2,'auxcounter'=>0,'name'=>'Toronto Star','checkbox'=>false,'unread'=>0,'error'=>'oops','icon'=>'feed-icons/2.ico','param'=>'2011-11-11T11:11:11',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'auxcounter'=>0,'parent_id'=>3,'param'=>'(1 feed)',],['id'=>'CAT:6','bare_id'=>6,'name'=>'National','items'=>[['id'=>'FEED:4','bare_id'=>4,'auxcounter'=>0,'name'=>'CBC News','checkbox'=>false,'unread'=>0,'error'=>'','icon'=>'feed-icons/4.ico','param'=>'2017-10-09T15:58:34',],['id'=>'FEED:5','bare_id'=>5,'auxcounter'=>0,'name'=>'Ottawa Citizen','checkbox'=>false,'unread'=>0,'error'=>'','icon'=>false,'param'=>'2017-07-07T17:07:17',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'auxcounter'=>0,'parent_id'=>3,'param'=>'(2 feeds)',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'parent_id'=>null,'param'=>'(3 feeds)',],['id'=>'CAT:1','bare_id'=>1,'auxcounter'=>0,'name'=>'Science','items'=>[['id'=>'CAT:2','bare_id'=>2,'name'=>'Rocketry','items'=>[['id'=>'FEED:1','bare_id'=>1,'auxcounter'=>0,'name'=>'NASA JPL','checkbox'=>false,'unread'=>0,'error'=>'','icon'=>false,'param'=>'2017-09-15T22:54:16',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'auxcounter'=>0,'parent_id'=>1,'param'=>'(1 feed)',],['id'=>'FEED:3','bare_id'=>3,'auxcounter'=>0,'name'=>'Ars Technica','checkbox'=>false,'unread'=>0,'error'=>'argh','icon'=>'feed-icons/3.ico','param'=>'2016-05-23T06:40:02',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'parent_id'=>null,'param'=>'(2 feeds)',],['id'=>'CAT:0','bare_id'=>0,'auxcounter'=>0,'name'=>'Uncategorized','items'=>[['id'=>'FEED:6','bare_id'=>6,'auxcounter'=>0,'name'=>'Eurogamer','checkbox'=>false,'error'=>'','icon'=>'feed-icons/6.ico','param'=>'2010-02-12T20:08:47','unread'=>0,],],'type'=>'category','checkbox'=>false,'unread'=>0,'child_unread'=>0,'parent_id'=>null,'param'=>'(1 feed)',],],],]; - $this->assertEquals($this->respGood($exp), $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); + $this->assertEquals($this->respGood($exp), $this->req($in[0])); $exp = ['categories'=>['identifier'=>'id','label'=>'name','items'=>[['id'=>'CAT:-1','items'=>[['id'=>'FEED:-4','name'=>'All articles','unread'=>35,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/folder.png','bare_id'=>-4,'auxcounter'=>0,],['id'=>'FEED:-3','name'=>'Fresh articles','unread'=>7,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/fresh.png','bare_id'=>-3,'auxcounter'=>0,],['id'=>'FEED:-1','name'=>'Starred articles','unread'=>4,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/star.png','bare_id'=>-1,'auxcounter'=>0,],['id'=>'FEED:-2','name'=>'Published articles','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/feed.png','bare_id'=>-2,'auxcounter'=>0,],['id'=>'FEED:0','name'=>'Archived articles','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/archive.png','bare_id'=>0,'auxcounter'=>0,],['id'=>'FEED:-6','name'=>'Recently read','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/time.png','bare_id'=>-6,'auxcounter'=>0,],],'name'=>'Special','type'=>'category','unread'=>0,'bare_id'=>-1,],['id'=>'CAT:-2','items'=>[['id'=>'FEED:-1027','name'=>'Fascinating','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/label.png','bare_id'=>-1027,'auxcounter'=>0,'fg_color'=>'','bg_color'=>'',],['id'=>'FEED:-1029','name'=>'Interesting','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/label.png','bare_id'=>-1029,'auxcounter'=>0,'fg_color'=>'','bg_color'=>'',],['id'=>'FEED:-1025','name'=>'Logical','unread'=>0,'type'=>'feed','error'=>'','updated'=>'','icon'=>'images/label.png','bare_id'=>-1025,'auxcounter'=>0,'fg_color'=>'','bg_color'=>'',],],'name'=>'Labels','type'=>'category','unread'=>6,'bare_id'=>-2,],['id'=>'CAT:3','bare_id'=>3,'auxcounter'=>0,'name'=>'Politics','items'=>[['id'=>'CAT:5','bare_id'=>5,'name'=>'Local','items'=>[['id'=>'FEED:2','bare_id'=>2,'auxcounter'=>0,'name'=>'Toronto Star','checkbox'=>false,'unread'=>0,'error'=>'oops','icon'=>'feed-icons/2.ico','param'=>'2011-11-11T11:11:11',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'auxcounter'=>0,'parent_id'=>3,'param'=>'(1 feed)',],['id'=>'CAT:6','bare_id'=>6,'name'=>'National','items'=>[['id'=>'FEED:4','bare_id'=>4,'auxcounter'=>0,'name'=>'CBC News','checkbox'=>false,'unread'=>0,'error'=>'','icon'=>'feed-icons/4.ico','param'=>'2017-10-09T15:58:34',],['id'=>'FEED:5','bare_id'=>5,'auxcounter'=>0,'name'=>'Ottawa Citizen','checkbox'=>false,'unread'=>0,'error'=>'','icon'=>false,'param'=>'2017-07-07T17:07:17',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'auxcounter'=>0,'parent_id'=>3,'param'=>'(2 feeds)',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'parent_id'=>null,'param'=>'(3 feeds)',],['id'=>'CAT:1','bare_id'=>1,'auxcounter'=>0,'name'=>'Science','items'=>[['id'=>'CAT:2','bare_id'=>2,'name'=>'Rocketry','items'=>[['id'=>'FEED:1','bare_id'=>1,'auxcounter'=>0,'name'=>'NASA JPL','checkbox'=>false,'unread'=>0,'error'=>'','icon'=>false,'param'=>'2017-09-15T22:54:16',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'auxcounter'=>0,'parent_id'=>1,'param'=>'(1 feed)',],['id'=>'FEED:3','bare_id'=>3,'auxcounter'=>0,'name'=>'Ars Technica','checkbox'=>false,'unread'=>0,'error'=>'argh','icon'=>'feed-icons/3.ico','param'=>'2016-05-23T06:40:02',],],'checkbox'=>false,'type'=>'category','unread'=>0,'child_unread'=>0,'parent_id'=>null,'param'=>'(2 feeds)',],['id'=>'CAT:0','bare_id'=>0,'auxcounter'=>0,'name'=>'Uncategorized','items'=>[['id'=>'FEED:6','bare_id'=>6,'auxcounter'=>0,'name'=>'Eurogamer','checkbox'=>false,'error'=>'','icon'=>'feed-icons/6.ico','param'=>'2010-02-12T20:08:47','unread'=>0,],],'type'=>'category','checkbox'=>false,'unread'=>0,'child_unread'=>0,'parent_id'=>null,'param'=>'(1 feed)',],],],]; - $this->assertEquals($this->respGood($exp), $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); + $this->assertEquals($this->respGood($exp), $this->req($in[1])); } public function testMarkFeedsAsRead() { @@ -979,12 +983,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->h->dispatch(new Request("POST", "", json_encode($in1[$a]))), "Test $a failed"); + $this->assertResponse($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->h->dispatch(new Request("POST", "", json_encode($in2[$a]))), "Test $a failed"); + $this->assertResponse($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)); @@ -996,7 +1000,7 @@ LONG_STRING; // verify the time-based mock $t = Date::sub("PT24H"); for ($a = 0; $a < sizeof($in3); $a++) { - $this->assertResponse($exp, $this->h->dispatch(new Request("POST", "", json_encode($in3[$a]))), "Test $a failed"); + $this->assertResponse($exp, $this->req($in3[$a]), "Test $a failed"); } Phake::verify(Arsse::$db)->articleMark($this->anything(), ['read' => true], (new Context)->modifiedSince($t)); } @@ -1131,10 +1135,10 @@ LONG_STRING; ], ]; for ($a = 0; $a < sizeof($in1); $a++) { - $this->assertResponse($this->respGood($exp[$a]), $this->h->dispatch(new Request("POST", "", json_encode($in1[$a]))), "Test $a failed"); + $this->assertResponse($this->respGood($exp[$a]), $this->req($in1[$a]), "Test $a failed"); } for ($a = 0; $a < sizeof($in2); $a++) { - $this->assertResponse($this->respGood([]), $this->h->dispatch(new Request("POST", "", json_encode($in2[$a]))), "Test $a failed"); + $this->assertResponse($this->respGood([]), $this->req($in2[$a]), "Test $a failed"); } } @@ -1232,7 +1236,7 @@ LONG_STRING; $this->respErr("INCORRECT_USAGE"), ]; for ($a = 0; $a < sizeof($in); $a++) { - $this->assertEquals($out[$a], $this->h->dispatch(new Request("POST", "", json_encode($in[$a]))), "Test $a failed"); + $this->assertEquals($out[$a], $this->req($in[$a]), "Test $a failed"); } } @@ -1256,10 +1260,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->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); - $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); + $this->assertEquals($exp, $this->req($in[0])); + $this->assertEquals($exp, $this->req($in[1])); + $this->assertEquals($exp, $this->req($in[2])); + $this->assertEquals($exp, $this->req($in[3])); $exp = [ [ 'id' => 101, @@ -1315,13 +1319,13 @@ LONG_STRING; 'content' => '

Article content 2

', ], ]; - $this->assertEquals($this->respGood($exp), $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); - $this->assertEquals($this->respGood([$exp[0]]), $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); - $this->assertEquals($this->respGood([$exp[1]]), $this->h->dispatch(new Request("POST", "", json_encode($in[6])))); + $this->assertEquals($this->respGood($exp), $this->req($in[4])); + $this->assertEquals($this->respGood([$exp[0]]), $this->req($in[5])); + $this->assertEquals($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->assertEquals($this->respGood([$exp[0]]), $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); + $this->assertEquals($this->respGood([$exp[0]]), $this->req($in[5])); } public function testRetrieveCompactHeadlines() { @@ -1400,13 +1404,13 @@ LONG_STRING; $this->respGood([['id' => 1003]]), ]; for ($a = 0; $a < sizeof($in1); $a++) { - $this->assertEquals($out1[$a], $this->h->dispatch(new Request("POST", "", json_encode($in1[$a]))), "Test $a failed"); + $this->assertEquals($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->assertEquals($out2[$a], $this->h->dispatch(new Request("POST", "", json_encode($in2[$a]))), "Test $a failed"); + $this->assertEquals($out2[$a], $this->req($in2[$a]), "Test $a failed"); } } @@ -1508,16 +1512,16 @@ LONG_STRING; $this->outputHeadlines(1003), ]; for ($a = 0; $a < sizeof($in1); $a++) { - $this->assertResponse($this->respGood([]), $this->h->dispatch(new Request("POST", "", json_encode($in1[$a]))), "Test $a failed"); + $this->assertResponse($this->respGood([]), $this->req($in1[$a]), "Test $a failed"); } for ($a = 0; $a < sizeof($in2); $a++) { - $this->assertEquals($out2[$a], $this->h->dispatch(new Request("POST", "", json_encode($in2[$a]))), "Test $a failed"); + $this->assertEquals($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->assertEquals($out3[$a], $this->h->dispatch(new Request("POST", "", json_encode($in3[$a]))), "Test $a failed"); + $this->assertEquals($out3[$a], $this->req($in3[$a]), "Test $a failed"); } } @@ -1546,17 +1550,17 @@ LONG_STRING; Phake::when(Arsse::$db)->articleCount->thenReturn(0); 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->h->dispatch(new Request("POST", "", json_encode($in[0]))); + $test = $this->req($in[0]); $this->assertEquals($this->outputHeadlines(1), $test); // test 'show_content' - $test = $this->h->dispatch(new Request("POST", "", json_encode($in[1]))); + $test = $this->req($in[1]); $this->assertArrayHasKey("content", $test->payload['content'][0]); $this->assertArrayHasKey("content", $test->payload['content'][1]); foreach ($this->generateHeadlines(1) as $key => $row) { $this->assertSame($row['content'], $test->payload['content'][$key]['content']); } // test 'include_attachments' - $test = $this->h->dispatch(new Request("POST", "", json_encode($in[2]))); + $test = $this->req($in[2]); $exp = [ [ 'content_url' => "http://example.com/text", @@ -1573,7 +1577,7 @@ LONG_STRING; $this->assertSame([], $test->payload['content'][0]['attachments']); $this->assertSame($exp, $test->payload['content'][1]['attachments']); // test 'include_header' - $test = $this->h->dispatch(new Request("POST", "", json_encode($in[3]))); + $test = $this->req($in[3]); $exp = $this->outputHeadlines(1); $exp->payload['content'] = [ ['id' => -4, 'is_cat' => false, 'first_id' => 1], @@ -1581,7 +1585,7 @@ LONG_STRING; ]; $this->assertEquals($exp, $test); // test 'include_header' with a category - $test = $this->h->dispatch(new Request("POST", "", json_encode($in[4]))); + $test = $this->req($in[4]); $exp = $this->outputHeadlines(1); $exp->payload['content'] = [ ['id' => -3, 'is_cat' => true, 'first_id' => 1], @@ -1589,7 +1593,7 @@ LONG_STRING; ]; $this->assertEquals($exp, $test); // test 'include_header' with an empty result - $test = $this->h->dispatch(new Request("POST", "", json_encode($in[5]))); + $test = $this->req($in[5]); $exp = $this->respGood([ ['id' => -1, 'is_cat' => true, 'first_id' => 0], [], @@ -1597,14 +1601,14 @@ LONG_STRING; $this->assertEquals($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->h->dispatch(new Request("POST", "", json_encode($in[6]))); + $test = $this->req($in[6]); $exp = $this->respGood([ ['id' => 2112, 'is_cat' => false, 'first_id' => 0], [], ]); $this->assertEquals($exp, $test); // test 'include_header' with ascending order - $test = $this->h->dispatch(new Request("POST", "", json_encode($in[7]))); + $test = $this->req($in[7]); $exp = $this->outputHeadlines(1); $exp->payload['content'] = [ ['id' => -4, 'is_cat' => false, 'first_id' => 0], @@ -1613,7 +1617,7 @@ LONG_STRING; $this->assertEquals($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->h->dispatch(new Request("POST", "", json_encode($in[8]))); + $test = $this->req($in[8]); $exp = $this->outputHeadlines(1); $exp->payload['content'] = [ ['id' => 42, 'is_cat' => false, 'first_id' => 1867], @@ -1621,7 +1625,7 @@ LONG_STRING; ]; $this->assertEquals($exp, $test); // test 'include_header' with skip and ascending order - $test = $this->h->dispatch(new Request("POST", "", json_encode($in[9]))); + $test = $this->req($in[9]); $exp = $this->outputHeadlines(1); $exp->payload['content'] = [ ['id' => 42, 'is_cat' => false, 'first_id' => 0], @@ -1631,7 +1635,7 @@ LONG_STRING; // 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…"; - $test = $this->h->dispatch(new Request("POST", "", json_encode($in[10]))); + $test = $this->req($in[10]); $this->assertArrayHasKey("excerpt", $test->payload['content'][0]); $this->assertArrayHasKey("excerpt", $test->payload['content'][1]); $this->assertSame($exp1, $test->payload['content'][0]['excerpt']);