diff --git a/lib/Database.php b/lib/Database.php index bdb36b64..f8053ae9 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -991,12 +991,14 @@ class Database { * - "url": The URL of the icon * - "type": The Content-Type of the icon e.g. "image/png" * - "data": The icon itself, as a binary sring; if $withData is false this will be null + * + * If the subscription has no icon null is returned instead of an array * * @param string|null $user The user who owns the subscription being queried; using null here is supported for TT-RSS and SHOULD NOT be used elsewhere as it leaks information * @param int $subscription The numeric identifier of the subscription * @param bool $includeData Whether to include the binary data of the icon itself in the result */ - public function subscriptionIcon(?string $user, int $id, bool $includeData = true): array { + public function subscriptionIcon(?string $user, int $id, bool $includeData = true): ?array { $data = $includeData ? "i.data" : "null as data"; $q = new Query("SELECT i.id, i.url, i.type, $data from arsse_subscriptions as s join arsse_feeds as f on s.feed = f.id left join arsse_icons as i on f.icon = i.id"); $q->setWhere("s.id = ?", "int", $id); @@ -1006,6 +1008,8 @@ class Database { $out = $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getRow(); if (!$out) { throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "subscription", 'id' => $id]); + } elseif (!$out['id']) { + return null; } return $out; } diff --git a/tests/cases/Database/SeriesSubscription.php b/tests/cases/Database/SeriesSubscription.php index c009b600..e4a2b099 100644 --- a/tests/cases/Database/SeriesSubscription.php +++ b/tests/cases/Database/SeriesSubscription.php @@ -478,7 +478,7 @@ trait SeriesSubscription { $exp = "http://example.com/favicon.ico"; $this->assertSame($exp, Arsse::$db->subscriptionIcon(null, 1)['url']); $this->assertSame($exp, Arsse::$db->subscriptionIcon(null, 2)['url']); - $this->assertSame(null, Arsse::$db->subscriptionIcon(null, 3)['url']); + $this->assertSame(null, Arsse::$db->subscriptionIcon(null, 3)); } public function testRetrieveTheFaviconOfAMissingSubscription(): void { @@ -490,16 +490,15 @@ trait SeriesSubscription { $exp = "http://example.com/favicon.ico"; $user = "john.doe@example.com"; $this->assertSame($exp, Arsse::$db->subscriptionIcon($user, 1)['url']); - $this->assertSame(null, Arsse::$db->subscriptionIcon($user, 3)['url']); + $this->assertSame(null, Arsse::$db->subscriptionIcon($user, 3)); $user = "jane.doe@example.com"; $this->assertSame($exp, Arsse::$db->subscriptionIcon($user, 2)['url']); } public function testRetrieveTheFaviconOfASubscriptionOfTheWrongUser(): void { - $exp = "http://example.com/favicon.ico"; $user = "john.doe@example.com"; $this->assertException("subjectMissing", "Db", "ExceptionInput"); - $this->assertSame(null, Arsse::$db->subscriptionIcon($user, 2)['url']); + Arsse::$db->subscriptionIcon($user, 2); } public function testListTheTagsOfASubscription(): void {