From 88cf3c6dae2cbb66ba9042ea59d791479a5c7c68 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 23 Dec 2020 09:38:22 -0500 Subject: [PATCH] Test filter rule retrieval --- lib/Database.php | 2 +- tests/cases/Database/SeriesFeed.php | 36 +++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index 6663e0f..1d5405a 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -1197,7 +1197,7 @@ class Database { * - "block": The block rule; any article which matches this rule are hidden */ public function feedRulesGet(int $feedID): Db\Result { - return $this->db->prepare("SELECT owner, keep_rule as keep, block_rule as block from arsse_subscriptions where feed = ? and (coalesce(keep_rule, '') || coalesce(block_rule, '')) <> ''", "int")->run($feedID); + return $this->db->prepare("SELECT owner, coalesce(keep_rule, '') as keep, coalesce(block_rule, '') as block from arsse_subscriptions where feed = ? and (keep || block) <> '' order by owner", "int")->run($feedID); } /** Retrieves various identifiers for the latest $count articles in the given newsfeed. The identifiers are: diff --git a/tests/cases/Database/SeriesFeed.php b/tests/cases/Database/SeriesFeed.php index f79c8cc..8f17694 100644 --- a/tests/cases/Database/SeriesFeed.php +++ b/tests/cases/Database/SeriesFeed.php @@ -7,6 +7,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\TestCase\Database; use JKingWeb\Arsse\Arsse; +use JKingWeb\Arsse\Test\Result; trait SeriesFeed { protected function setUpSeriesFeed(): void { @@ -67,17 +68,19 @@ trait SeriesFeed { ], 'arsse_subscriptions' => [ 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", + 'id' => "int", + 'owner' => "str", + 'feed' => "int", + 'keep_rule' => "str", + 'block_rule' => "str", ], 'rows' => [ - [1,'john.doe@example.com',1], - [2,'john.doe@example.com',2], - [3,'john.doe@example.com',3], - [4,'john.doe@example.com',4], - [5,'john.doe@example.com',5], - [6,'jane.doe@example.com',1], + [1,'john.doe@example.com',1,null,'^Sport$'], + [2,'john.doe@example.com',2,null,null], + [3,'john.doe@example.com',3,'\w+',null], + [4,'john.doe@example.com',4,null,null], + [5,'john.doe@example.com',5,null,'and/or'], + [6,'jane.doe@example.com',1,'^(?i)[a-z]+','bluberry'], ], ], 'arsse_articles' => [ @@ -200,6 +203,21 @@ trait SeriesFeed { $this->assertResult([['id' => 1]], Arsse::$db->feedMatchIds(1, ['e433653cef2e572eee4215fa299a4a5af9137b2cefd6283c85bd69a32915beda'])); // this ID appears in both feed 1 and feed 2; only one result should be returned } + /** @dataProvider provideFilterRules */ + public function testGetRules(int $in, array $exp): void { + $this->assertResult($exp, Arsse::$db->feedRulesGet($in)); + } + + public function provideFilterRules(): iterable { + return [ + [1, [['owner' => "john.doe@example.com", 'keep' => "", 'block' => "^Sport$"], ['owner' => "jane.doe@example.com", 'keep' => "^(?i)[a-z]+", 'block' => "bluberry"]]], + [2, []], + [3, [['owner' => "john.doe@example.com", 'keep' => '\w+', 'block' => ""]]], + [4, []], + [5, [['owner' => "john.doe@example.com", 'keep' => "", 'block' => "and/or"]]], + ]; + } + public function testUpdateAFeed(): void { // update a valid feed with both new and changed items Arsse::$db->feedUpdate(1);