mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Implement single-feed querying
This commit is contained in:
parent
a646ad77b7
commit
5a8a044a92
2 changed files with 28 additions and 3 deletions
|
@ -702,6 +702,18 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
||||||
return new Response($out);
|
return new Response($out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getFeed(array $path): ResponseInterface {
|
||||||
|
$tr = Arsse::$db->begin();
|
||||||
|
try {
|
||||||
|
$sub = Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, (int) $path[1]);
|
||||||
|
} catch (ExceptionInput $e) {
|
||||||
|
return new ErrorResponse("404", 404);
|
||||||
|
}
|
||||||
|
// compile the list of folders; the feed list includes folder names
|
||||||
|
$folders = $this->mapFolders();
|
||||||
|
return new Response($this->transformFeed($sub, $folders));
|
||||||
|
}
|
||||||
|
|
||||||
protected function createFeed(array $data): ResponseInterface {
|
protected function createFeed(array $data): ResponseInterface {
|
||||||
try {
|
try {
|
||||||
Arsse::$db->feedAdd($data['feed_url'], (string) $data['username'], (string) $data['password'], false, (bool) $data['crawler']);
|
Arsse::$db->feedAdd($data['feed_url'], (string) $data['username'], (string) $data['password'], false, (bool) $data['crawler']);
|
||||||
|
|
|
@ -564,9 +564,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListFeedsOfTheRootCategory(): void {
|
public function testListFeedsOfTheRootCategory(): void {
|
||||||
\Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([
|
\Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([['id' => 5, 'name' => "Cat Ook"],])));
|
||||||
['id' => 5, 'name' => "Cat Ook"],
|
|
||||||
])));
|
|
||||||
\Phake::when(Arsse::$db)->subscriptionList->thenReturn(new Result($this->v($this->feeds)));
|
\Phake::when(Arsse::$db)->subscriptionList->thenReturn(new Result($this->v($this->feeds)));
|
||||||
$exp = new Response($this->feedsOut);
|
$exp = new Response($this->feedsOut);
|
||||||
$this->assertMessage($exp, $this->req("GET", "/categories/1/feeds"));
|
$this->assertMessage($exp, $this->req("GET", "/categories/1/feeds"));
|
||||||
|
@ -580,6 +578,21 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
\Phake::verify(Arsse::$db)->subscriptionList(Arsse::$user->id, 2111, true);
|
\Phake::verify(Arsse::$db)->subscriptionList(Arsse::$user->id, 2111, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetAFeed(): void {
|
||||||
|
\Phake::when(Arsse::$db)->subscriptionPropertiesGet->thenReturn($this->v($this->feeds[0]))->thenReturn($this->v($this->feeds[1]));
|
||||||
|
\Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([['id' => 5, 'name' => "Cat Ook"],])));
|
||||||
|
$this->assertMessage(new Response($this->feedsOut[0]), $this->req("GET", "/feeds/1"));
|
||||||
|
\Phake::verify(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 1);
|
||||||
|
$this->assertMessage(new Response($this->feedsOut[1]), $this->req("GET", "/feeds/55"));
|
||||||
|
\Phake::verify(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 55);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAMissingFeed(): void {
|
||||||
|
\Phake::when(Arsse::$db)->subscriptionPropertiesGet->thenThrow(new ExceptionInput("subjectMissing"));
|
||||||
|
$this->assertMessage(new ErrorResponse("404", 404), $this->req("GET", "/feeds/1"));
|
||||||
|
\Phake::verify(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/** @dataProvider provideFeedCreations */
|
/** @dataProvider provideFeedCreations */
|
||||||
public function testCreateAFeed(array $in, $out1, $out2, $out3, $out4, ResponseInterface $exp): void {
|
public function testCreateAFeed(array $in, $out1, $out2, $out3, $out4, ResponseInterface $exp): void {
|
||||||
if ($out1 instanceof \Exception) {
|
if ($out1 instanceof \Exception) {
|
||||||
|
|
Loading…
Reference in a new issue