From ac38659e3a176d8690314b7cc88afe4123346040 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 30 Dec 2022 12:41:12 -0500 Subject: [PATCH] Fix most references to feedUpdate --- lib/CLI.php | 2 +- lib/REST/NextcloudNews/V1_2.php | 2 +- lib/REST/TinyTinyRSS/API.php | 2 +- lib/Service/Serial/Driver.php | 2 +- tests/cases/CLI/TestCLI.php | 6 ++-- tests/cases/Database/SeriesFeed.php | 30 ++++++++-------- tests/cases/REST/NextcloudNews/TestV1_2.php | 38 ++++++++++----------- tests/cases/REST/TinyTinyRSS/TestAPI.php | 22 +++++------- tests/cases/Service/TestSerial.php | 6 ++-- 9 files changed, 52 insertions(+), 58 deletions(-) diff --git a/lib/CLI.php b/lib/CLI.php index 9e9993e3..618d9e22 100644 --- a/lib/CLI.php +++ b/lib/CLI.php @@ -105,7 +105,7 @@ USAGE_TEXT; } return 0; case "feed refresh": - return (int) !Arsse::$db->feedUpdate((int) $args[''], true); + return (int) !Arsse::$db->subscriptionUpdate(null, (int) $args[''], true); case "feed refresh-all": Arsse::$obj->get(Service::class)->watch(false); return 0; diff --git a/lib/REST/NextcloudNews/V1_2.php b/lib/REST/NextcloudNews/V1_2.php index bfcf80f8..7594ca35 100644 --- a/lib/REST/NextcloudNews/V1_2.php +++ b/lib/REST/NextcloudNews/V1_2.php @@ -377,7 +377,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler { return HTTP::respEmpty(403); } try { - Arsse::$db->feedUpdate($data['feedId']); + Arsse::$db->subscriptionUpdate($data['userId'], $data['feedId']); } catch (ExceptionInput $e) { switch ($e->getCode()) { case 10239: // feed does not exist diff --git a/lib/REST/TinyTinyRSS/API.php b/lib/REST/TinyTinyRSS/API.php index 71261000..a3db7eb7 100644 --- a/lib/REST/TinyTinyRSS/API.php +++ b/lib/REST/TinyTinyRSS/API.php @@ -946,7 +946,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { throw new Exception("INCORRECT_USAGE"); } try { - Arsse::$db->feedUpdate((int) Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, $data['feed_id'])['feed']); + Arsse::$db->subscriptionUpdate(Arsse::$user->id, $data['feed_id']); } catch (ExceptionInput $e) { throw new Exception("FEED_NOT_FOUND"); } diff --git a/lib/Service/Serial/Driver.php b/lib/Service/Serial/Driver.php index dc2c74f0..2c5e7300 100644 --- a/lib/Service/Serial/Driver.php +++ b/lib/Service/Serial/Driver.php @@ -31,7 +31,7 @@ class Driver implements \JKingWeb\Arsse\Service\Driver { public function exec(): int { while (sizeof($this->queue)) { $id = array_shift($this->queue); - Arsse::$db->feedUpdate($id); + Arsse::$db->subscriptionUpdate(null, $id); } return Arsse::$conf->serviceQueueWidth - sizeof($this->queue); } diff --git a/tests/cases/CLI/TestCLI.php b/tests/cases/CLI/TestCLI.php index a17ecbb5..8ee897dc 100644 --- a/tests/cases/CLI/TestCLI.php +++ b/tests/cases/CLI/TestCLI.php @@ -118,11 +118,11 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { /** @dataProvider provideFeedUpdates */ public function testRefreshAFeed(string $cmd, int $exitStatus, string $output): void { - $this->dbMock->feedUpdate->with(1, true)->returns(true); - $this->dbMock->feedUpdate->with(2, true)->throws(new \JKingWeb\Arsse\Feed\Exception("", ['url' => "http://example.com/"], $this->mockGuzzleException(ClientException::class, "", 404))); + $this->dbMock->subscriptionUpdate->with(null, 1, true)->returns(true); + $this->dbMock->subscriptionUpdate->with(null, 2, true)->throws(new \JKingWeb\Arsse\Feed\Exception("", ['url' => "http://example.com/"], $this->mockGuzzleException(ClientException::class, "", 404))); $this->assertConsole($cmd, $exitStatus, $output); $this->cli->loadConf->called(); - $this->dbMock->feedUpdate->called(); + $this->dbMock->subscriptionUpdate->called(); } public function provideFeedUpdates(): iterable { diff --git a/tests/cases/Database/SeriesFeed.php b/tests/cases/Database/SeriesFeed.php index 87c1c0eb..864205c9 100644 --- a/tests/cases/Database/SeriesFeed.php +++ b/tests/cases/Database/SeriesFeed.php @@ -149,7 +149,7 @@ trait SeriesFeed { public function testUpdateAFeed(): void { // update a valid feed with both new and changed items - Arsse::$db->feedUpdate(1); + Arsse::$db->subscriptionUpdate(null, 1); $now = gmdate("Y-m-d H:i:s"); $state = $this->primeExpectations($this->data, [ 'arsse_articles' => ["id", "feed","url","title","author","published","edited","content","guid","url_title_hash","url_content_hash","title_content_hash","modified"], @@ -172,9 +172,9 @@ trait SeriesFeed { $state['arsse_feeds']['rows'][0] = [1,6]; $this->compareExpectations(static::$drv, $state); // update a valid feed which previously had an error - Arsse::$db->feedUpdate(2); + Arsse::$db->subscriptionUpdate(null, 2); // update an erroneous feed which previously had no errors - Arsse::$db->feedUpdate(3); + Arsse::$db->subscriptionUpdate(null, 3); $state = $this->primeExpectations($this->data, [ 'arsse_feeds' => ["id","err_count","err_msg"], ]); @@ -182,29 +182,29 @@ trait SeriesFeed { $state['arsse_feeds']['rows'][2] = [3,1,'Feed URL "http://localhost:8000/Feed/Fetching/Error?code=404" is invalid']; $this->compareExpectations(static::$drv, $state); // update the bad feed again, twice - Arsse::$db->feedUpdate(3); - Arsse::$db->feedUpdate(3); + Arsse::$db->subscriptionUpdate(null, 3); + Arsse::$db->subscriptionUpdate(null, 3); $state['arsse_feeds']['rows'][2] = [3,3,'Feed URL "http://localhost:8000/Feed/Fetching/Error?code=404" is invalid']; $this->compareExpectations(static::$drv, $state); } public function testUpdateAMissingFeed(): void { $this->assertException("subjectMissing", "Db", "ExceptionInput"); - Arsse::$db->feedUpdate(2112); + Arsse::$db->subscriptionUpdate(null, 2112); } public function testUpdateAnInvalidFeed(): void { $this->assertException("typeViolation", "Db", "ExceptionInput"); - Arsse::$db->feedUpdate(-1); + Arsse::$db->subscriptionUpdate(null, -1); } public function testUpdateAFeedThrowingExceptions(): void { $this->assertException("invalidUrl", "Feed"); - Arsse::$db->feedUpdate(3, true); + Arsse::$db->subscriptionUpdate(null, 3, true); } public function testUpdateAFeedWithEnclosuresAndCategories(): void { - Arsse::$db->feedUpdate(5); + Arsse::$db->subscriptionUpdate(null, 5); $state = $this->primeExpectations($this->data, [ 'arsse_enclosures' => ["url","type"], 'arsse_categories' => ["name"], @@ -225,13 +225,13 @@ trait SeriesFeed { public function testListStaleFeeds(): void { $this->assertEquals([1,3,4], Arsse::$db->feedListStale()); - Arsse::$db->feedUpdate(3); - Arsse::$db->feedUpdate(4); + Arsse::$db->subscriptionUpdate(null, 3); + Arsse::$db->subscriptionUpdate(null, 4); $this->assertEquals([1], Arsse::$db->feedListStale()); } public function testCheckIconDuringFeedUpdate(): void { - Arsse::$db->feedUpdate(6); + Arsse::$db->subscriptionUpdate(null, 6); $state = $this->primeExpectations($this->data, [ 'arsse_icons' => ["id","url","type","data"], 'arsse_feeds' => ["id", "icon"], @@ -240,7 +240,7 @@ trait SeriesFeed { } public function testAssignIconDuringFeedUpdate(): void { - Arsse::$db->feedUpdate(7); + Arsse::$db->subscriptionUpdate(null, 7); $state = $this->primeExpectations($this->data, [ 'arsse_icons' => ["id","url","type","data"], 'arsse_feeds' => ["id", "icon"], @@ -250,7 +250,7 @@ trait SeriesFeed { } public function testChangeIconDuringFeedUpdate(): void { - Arsse::$db->feedUpdate(8); + Arsse::$db->subscriptionUpdate(null, 8); $state = $this->primeExpectations($this->data, [ 'arsse_icons' => ["id","url","type","data"], 'arsse_feeds' => ["id", "icon"], @@ -260,7 +260,7 @@ trait SeriesFeed { } public function testAddIconDuringFeedUpdate(): void { - Arsse::$db->feedUpdate(9); + Arsse::$db->subscriptionUpdate(null, 9); $state = $this->primeExpectations($this->data, [ 'arsse_icons' => ["id","url","type","data"], 'arsse_feeds' => ["id", "icon"], diff --git a/tests/cases/REST/NextcloudNews/TestV1_2.php b/tests/cases/REST/NextcloudNews/TestV1_2.php index 8b7f4d8a..5a1e2e9a 100644 --- a/tests/cases/REST/NextcloudNews/TestV1_2.php +++ b/tests/cases/REST/NextcloudNews/TestV1_2.php @@ -637,32 +637,32 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest { $this->dbMock->feedListStale->never()->called(); } - public function testUpdateAFeed(): void { - $in = [ - ['feedId' => 42], // valid - ['feedId' => 2112], // feed does not exist - ['feedId' => "ook"], // invalid ID - ['feedId' => -1], // invalid ID - ['feed' => 42], // invalid input + /** @dataProvider provideFeedUpdates */ + public function testUpdateAFeed(array $in, int $exp): void { + $this->dbMock->subscriptionUpdate->with("ook", 42)->returns(true); + $this->dbMock->subscriptionUpdate->with("eek", 2112)->throws(new ExceptionInput("subjectMissing")); + $this->dbMock->subscriptionUpdate->with(null, $this->anything())->throws(new ExceptionInput("subjectMissing")); + $this->dbMock->subscriptionUpdate->with($this->anything(), $this->lessThan(1))->throws(new ExceptionInput("typeViolation")); + $exp = HTTP::respEmpty($exp); + $this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in))); + } + + public function provideFeedUpdates(): iterable { + return [ + 'Valid input' => [['userId' => "ook", 'feedId' => 42], 204], + 'Missing feed' => [['userId' => "eek", 'feedId' => 2112], 404], + 'String ID' => [['userId' => "ook", 'feedId' => "ook"], 422], + 'Negative ID' => [['userId' => "ook", 'feedId' => -1], 422], + 'Bad input 1' => [['userId' => "ook", 'feed' => 42], 422], + 'Bad input 2' => [['user' => "ook", 'feedId' => 42], 404], ]; - $this->dbMock->feedUpdate->with(42)->returns(true); - $this->dbMock->feedUpdate->with(2112)->throws(new ExceptionInput("subjectMissing")); - $this->dbMock->feedUpdate->with($this->lessThan(1))->throws(new ExceptionInput("typeViolation")); - $exp = HTTP::respEmpty(204); - $this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[0]))); - $exp = HTTP::respEmpty(404); - $this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[1]))); - $exp = HTTP::respEmpty(422); - $this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[2]))); - $this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[3]))); - $this->assertMessage($exp, $this->req("GET", "/feeds/update", json_encode($in[4]))); } public function testUpdateAFeedWithoutAuthority(): void { $this->userMock->propertiesGet->returns(['admin' => false]); $exp = HTTP::respEmpty(403); $this->assertMessage($exp, $this->req("GET", "/feeds/update", ['feedId' => 42])); - $this->dbMock->feedUpdate->never()->called(); + $this->dbMock->subscriptionUpdate->never()->called(); } /** @dataProvider provideArticleQueries */ diff --git a/tests/cases/REST/TinyTinyRSS/TestAPI.php b/tests/cases/REST/TinyTinyRSS/TestAPI.php index 99ca29d4..8c1c0a34 100644 --- a/tests/cases/REST/TinyTinyRSS/TestAPI.php +++ b/tests/cases/REST/TinyTinyRSS/TestAPI.php @@ -841,30 +841,24 @@ LONG_STRING; } /** @dataProvider provideFeedUpdates */ - public function testUpdateAFeed(array $in, ?array $data, $out, ?int $id, ResponseInterface $exp): void { + public function testUpdateAFeed(array $in, ?array $data, $out, ResponseInterface $exp): void { $in = array_merge(['op' => "updateFeed", 'sid' => "PriestsOfSyrinx"], $in); $action = ($out instanceof \Exception) ? "throws" : "returns"; - $this->dbMock->subscriptionPropertiesGet->$action($out); - $this->dbMock->feedUpdate->returns(true); + $this->dbMock->subscriptionUpdate->$action($out); $this->assertMessage($exp, $this->req($in)); if ($data !== null) { - $this->dbMock->subscriptionPropertiesGet->calledWith(...$data); + $this->dbMock->subscriptionUpdate->calledWith(...$data); } else { - $this->dbMock->subscriptionPropertiesGet->never()->called(); - } - if ($id !== null) { - $this->dbMock->feedUpdate->calledWith($id); - } else { - $this->dbMock->feedUpdate->never()->called(); + $this->dbMock->subscriptionUpdate->never()->called(); } } public function provideFeedUpdates(): iterable { return [ - [['feed_id' => 1], [$this->userId, 1], $this->v(['id' => 1, 'feed' => 11]), 11, $this->respGood(['status' => "OK"])], - [['feed_id' => 2], [$this->userId, 2], new ExceptionInput("subjectMissing"), null, $this->respErr("FEED_NOT_FOUND")], - [['feed_id' => -1], null, null, null, $this->respErr("INCORRECT_USAGE")], - [[], null, null, null, $this->respErr("INCORRECT_USAGE")], + [['feed_id' => 1], [$this->userId, 1], true, $this->respGood(['status' => "OK"])], + [['feed_id' => 2], [$this->userId, 2], new ExceptionInput("subjectMissing"), $this->respErr("FEED_NOT_FOUND")], + [['feed_id' => -1], null, null, $this->respErr("INCORRECT_USAGE")], + [[], null, null, $this->respErr("INCORRECT_USAGE")], ]; } diff --git a/tests/cases/Service/TestSerial.php b/tests/cases/Service/TestSerial.php index 321e150e..760f9698 100644 --- a/tests/cases/Service/TestSerial.php +++ b/tests/cases/Service/TestSerial.php @@ -41,8 +41,8 @@ class TestSerial extends \JKingWeb\Arsse\Test\AbstractTest { $d = new Driver; $d->queue(1, 4, 3); $this->assertSame(Arsse::$conf->serviceQueueWidth, $d->exec()); - $this->dbMock->feedUpdate->calledWith(1); - $this->dbMock->feedUpdate->calledWith(4); - $this->dbMock->feedUpdate->calledWith(3); + $this->dbMock->subscriptionUpdate->calledWith(null, 1); + $this->dbMock->subscriptionUpdate->calledWith(null, 4); + $this->dbMock->subscriptionUpdate->calledWith(null, 3); } }