mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2025-01-08 17:02:41 +00:00
Fix most references to feedUpdate
This commit is contained in:
parent
7414d3844e
commit
ac38659e3a
9 changed files with 52 additions and 58 deletions
|
@ -105,7 +105,7 @@ USAGE_TEXT;
|
|||
}
|
||||
return 0;
|
||||
case "feed refresh":
|
||||
return (int) !Arsse::$db->feedUpdate((int) $args['<n>'], true);
|
||||
return (int) !Arsse::$db->subscriptionUpdate(null, (int) $args['<n>'], true);
|
||||
case "feed refresh-all":
|
||||
Arsse::$obj->get(Service::class)->watch(false);
|
||||
return 0;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"],
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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")],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue