1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Add Database::articleCategoriesGet()

This method retrieves author-supplied categories for articles, used in TTRSS
This commit is contained in:
J. King 2017-11-21 09:22:58 -05:00
parent e729cedeca
commit faf00d63ba
2 changed files with 51 additions and 0 deletions

View file

@ -1162,6 +1162,20 @@ class Database {
}
}
public function articleCategoriesGet(string $user, $id): array {
if (!Arsse::$user->authorize($user, __FUNCTION__)) {
throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
}
$id = $this->articleValidateId($user, $id)['article'];
$out = $this->db->prepare("SELECT name from arsse_categories where article is ? order by name", "int")->run($id)->getAll();
if (!$out) {
return $out;
} else {
// flatten the result
return array_column($out, "name");
}
}
public function articleCleanup(): bool {
$query = $this->db->prepare(
"WITH target_feed(id,subs) as (".

View file

@ -215,6 +215,18 @@ trait SeriesArticle {
[1, 2,0,0,'2010-01-01 00:00:00','Some Note'],
]
],
'arsse_categories' => [ // author-supplied categories
'columns' => [
'article' => "int",
'name' => "str",
],
'rows' => [
[19,"Fascinating"],
[19,"Logical"],
[20,"Interesting"],
[20,"Logical"],
],
],
'arsse_labels' => [
'columns' => [
'id' => "int",
@ -907,9 +919,34 @@ trait SeriesArticle {
$this->assertEquals([], Arsse::$db->articleLabelsGet("john.doe@example.com", 2, true));
}
public function testListTheLabelsOfAMissingArticle() {
$this->assertException("subjectMissing", "Db", "ExceptionInput");
Arsse::$db->articleLabelsGet($this->user, 101);
}
public function testListTheLabelsOfAnArticleWithoutAuthority() {
Phake::when(Arsse::$user)->authorize->thenReturn(false);
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
Arsse::$db->articleLabelsGet("john.doe@example.com", 1);
}
public function testListTheCategoriesOfAnArticle() {
$exp = ["Fascinating", "Logical"];
$this->assertSame($exp, Arsse::$db->articleCategoriesGet($this->user, 19));
$exp = ["Interesting", "Logical"];
$this->assertSame($exp, Arsse::$db->articleCategoriesGet($this->user, 20));
$exp = [];
$this->assertSame($exp, Arsse::$db->articleCategoriesGet($this->user, 4));
}
public function testListTheCategoriesOfAMissingArticle() {
$this->assertException("subjectMissing", "Db", "ExceptionInput");
Arsse::$db->articleCategoriesGet($this->user, 101);
}
public function testListTheCategoriesOfAnArticleWithoutAuthority() {
Phake::when(Arsse::$user)->authorize->thenReturn(false);
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
Arsse::$db->articleCategoriesGet($this->user, 19);
}
}