2017-05-11 02:01:00 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-05-11 02:01:00 +00:00
|
|
|
declare(strict_types=1);
|
2018-11-23 15:01:17 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\Database;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2020-01-24 20:54:08 +00:00
|
|
|
use GuzzleHttp\Exception\ClientException;
|
2017-07-17 11:47:57 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
2017-05-11 02:01:00 +00:00
|
|
|
use JKingWeb\Arsse\Test\Database;
|
|
|
|
use JKingWeb\Arsse\Feed\Exception as FeedException;
|
2022-10-07 22:38:17 +00:00
|
|
|
use JKingWeb\Arsse\Misc\Date;
|
2017-05-11 02:01:00 +00:00
|
|
|
|
|
|
|
trait SeriesSubscription {
|
2023-02-12 23:30:19 +00:00
|
|
|
protected static $drv;
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function setUpSeriesSubscription(): void {
|
2018-11-25 05:03:56 +00:00
|
|
|
$this->data = [
|
|
|
|
'arsse_users' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
'columns' => ["id", "password", "num"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2020-12-20 16:55:36 +00:00
|
|
|
["jane.doe@example.com", "", 1],
|
|
|
|
["john.doe@example.com", "", 2],
|
2020-12-22 21:13:12 +00:00
|
|
|
["jill.doe@example.com", "", 3],
|
2021-01-16 04:02:33 +00:00
|
|
|
["jack.doe@example.com", "", 4],
|
2018-11-25 05:03:56 +00:00
|
|
|
],
|
2017-06-18 16:24:19 +00:00
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
'arsse_folders' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
'columns' => ["id", "owner", "parent", "name"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2018-11-25 05:03:56 +00:00
|
|
|
[1, "john.doe@example.com", null, "Technology"],
|
|
|
|
[2, "john.doe@example.com", 1, "Software"],
|
|
|
|
[3, "john.doe@example.com", 1, "Rocketry"],
|
|
|
|
[4, "jane.doe@example.com", null, "Politics"],
|
|
|
|
[5, "john.doe@example.com", null, "Politics"],
|
|
|
|
[6, "john.doe@example.com", 2, "Politics"],
|
2020-03-01 20:16:50 +00:00
|
|
|
],
|
2017-06-18 16:24:19 +00:00
|
|
|
],
|
2020-11-04 23:34:22 +00:00
|
|
|
'arsse_icons' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
'columns' => ["id", "url", "data"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2021-03-06 00:31:11 +00:00
|
|
|
[1,"http://example.com/favicon.ico", "ICON DATA"],
|
|
|
|
[2,"http://example.net/favicon.ico", null],
|
2020-11-04 23:34:22 +00:00
|
|
|
],
|
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
'arsse_subscriptions' => [
|
2022-10-07 22:38:17 +00:00
|
|
|
'columns' => ["id", "owner", "url", "feed_title", "updated", "next_fetch", "icon", "title", "folder", "pinned", "order_type", "keep_rule", "block_rule", "scrape", "deleted", "modified"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2022-10-07 22:38:17 +00:00
|
|
|
[1, "john.doe@example.com", "http://example.com/feed2", "eek", Date::transform("now - 1 hour", "sql"), Date::transform("now - 1 hour", "sql"), 1, null, null, 1, 2, null, null, 0, 0, Date::transform("now - 1 hour", "sql")],
|
|
|
|
[2, "jane.doe@example.com", "http://example.com/feed2", "eek", Date::transform("now - 1 hour", "sql"), Date::transform("now - 1 hour", "sql"), 1, null, null, 0, 0, null, null, 0, 0, Date::transform("now - 1 hour", "sql")],
|
|
|
|
[3, "john.doe@example.com", "http://example.com/feed3", "Ack", Date::transform("now + 1 hour", "sql"), Date::transform("now + 1 hour", "sql"), 2, "Ook", 2, 0, 1, null, null, 0, 0, Date::transform("now - 1 hour", "sql")],
|
|
|
|
[4, "jill.doe@example.com", "http://example.com/feed2", "eek", Date::transform("now - 1 hour", "sql"), Date::transform("now - 1 hour", "sql"), 1, null, null, 0, 0, null, null, 0, 0, Date::transform("now - 1 hour", "sql")],
|
|
|
|
[5, "jack.doe@example.com", "http://example.com/feed2", "eek", Date::transform("now - 1 hour", "sql"), Date::transform("now - 1 hour", "sql"), 1, null, null, 1, 2, "", "3|E", 0, 0, Date::transform("now - 1 hour", "sql")],
|
|
|
|
[6, "john.doe@example.com", "http://example.com/feed4", "Foo", Date::transform("now + 1 hour", "sql"), Date::transform("now + 1 hour", "sql"), null, "Bar", 3, 0, 0, null, null, 0, 0, Date::transform("now - 1 hour", "sql")],
|
|
|
|
[7, "john.doe@example.com", "http://example.com/feed1", "ook", Date::transform("now + 6 hour", "sql"), Date::transform("now - 1 hour", "sql"), null, null, null, 0, 0, null, null, 0, 1, Date::transform("now - 1 hour", "sql")],
|
2020-03-01 20:16:50 +00:00
|
|
|
],
|
2017-05-15 03:03:48 +00:00
|
|
|
],
|
2019-03-07 03:15:41 +00:00
|
|
|
'arsse_tags' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
'columns' => ["id", "owner", "name"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2019-03-07 03:15:41 +00:00
|
|
|
[1,"john.doe@example.com","Interesting"],
|
|
|
|
[2,"john.doe@example.com","Fascinating"],
|
|
|
|
[3,"jane.doe@example.com","Boring"],
|
|
|
|
[4,"john.doe@example.com","Lonely"],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'arsse_tag_members' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
'columns' => ["tag", "subscription", "assigned"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2019-03-07 03:15:41 +00:00
|
|
|
[1,1,1],
|
|
|
|
[1,3,0],
|
|
|
|
[2,1,1],
|
|
|
|
[2,3,1],
|
|
|
|
[3,2,1],
|
|
|
|
],
|
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
'arsse_articles' => [
|
2022-10-04 20:46:23 +00:00
|
|
|
'columns' => ["id", "subscription", "url_title_hash", "url_content_hash", "title_content_hash", "title", "read", "starred", "hidden"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2022-10-04 20:46:23 +00:00
|
|
|
[1, 1, "", "", "", "Title 1", 1, 0, 0],
|
|
|
|
[2, 1, "", "", "", "Title 2", 0, 0, 0],
|
|
|
|
[3, 1, "", "", "", "Title 3", 0, 0, 0],
|
|
|
|
[4, 1, "", "", "", "Title 4", 0, 0, 0],
|
|
|
|
[5, 1, "", "", "", "Title 5", 0, 0, 0],
|
|
|
|
[6, 2, "", "", "", "Title 1", 1, 0, 0],
|
|
|
|
[7, 2, "", "", "", "Title 2", 1, 0, 0],
|
|
|
|
[8, 2, "", "", "", "Title 3", 1, 0, 0],
|
|
|
|
[9, 2, "", "", "", "Title 4", 1, 0, 0],
|
|
|
|
[10, 2, "", "", "", "Title 5", 1, 0, 0],
|
|
|
|
[11, 4, "", "", "", "Title 1", 0, 0, 0],
|
|
|
|
[12, 4, "", "", "", "Title 2", 0, 0, 0],
|
|
|
|
[13, 4, "", "", "", "Title 3", 0, 0, 0],
|
|
|
|
[14, 4, "", "", "", "Title 4", 0, 0, 0],
|
|
|
|
[15, 4, "", "", "", "Title 5", 0, 0, 0],
|
|
|
|
[16, 5, "", "", "", "Title 1", 1, 0, 0],
|
|
|
|
[17, 5, "", "", "", "Title 2", 0, 0, 0],
|
|
|
|
[18, 5, "", "", "", "Title 3", 1, 0, 1],
|
|
|
|
[19, 5, "", "", "", "Title 4", 0, 0, 0],
|
|
|
|
[20, 5, "", "", "", "Title 5", 0, 0, 1],
|
|
|
|
[21, 3, "", "", "", "Title 6", 0, 0, 0],
|
|
|
|
[22, 3, "", "", "", "Title 7", 1, 0, 0],
|
|
|
|
[23, 3, "", "", "", "Title 8", 0, 0, 0],
|
2021-01-16 04:02:33 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'arsse_editions' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
'columns' => ["id", "article"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2022-10-04 20:46:23 +00:00
|
|
|
[1, 1],
|
|
|
|
[2, 2],
|
|
|
|
[3, 3],
|
|
|
|
[4, 4],
|
|
|
|
[5, 5],
|
|
|
|
[6, 6],
|
|
|
|
[7, 7],
|
|
|
|
[8, 8],
|
|
|
|
[9, 9],
|
|
|
|
[10, 10],
|
|
|
|
[11, 11],
|
|
|
|
[12, 12],
|
|
|
|
[13, 13],
|
|
|
|
[14, 14],
|
|
|
|
[15, 15],
|
|
|
|
[16, 16],
|
|
|
|
[17, 17],
|
|
|
|
[18, 18],
|
|
|
|
[19, 19],
|
|
|
|
[20, 20],
|
|
|
|
[21, 21],
|
|
|
|
[22, 22],
|
|
|
|
[23, 23],
|
2021-01-16 04:02:33 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'arsse_categories' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
'columns' => ["article", "name"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2022-10-04 20:46:23 +00:00
|
|
|
[1, "A"],
|
|
|
|
[2, "B"],
|
|
|
|
[4, "D"],
|
|
|
|
[5, "E"],
|
|
|
|
[6, "A"],
|
|
|
|
[7, "B"],
|
|
|
|
[9, "D"],
|
|
|
|
[10, "E"],
|
|
|
|
[11, "A"],
|
|
|
|
[12, "B"],
|
|
|
|
[14, "D"],
|
|
|
|
[15, "E"],
|
|
|
|
[16, "A"],
|
|
|
|
[17, "B"],
|
|
|
|
[19, "D"],
|
|
|
|
[20, "E"],
|
|
|
|
[21, "F"],
|
|
|
|
[22, "G"],
|
|
|
|
[23, "H"],
|
2020-03-01 20:16:50 +00:00
|
|
|
],
|
2017-05-17 02:19:40 +00:00
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
];
|
2017-05-18 17:21:17 +00:00
|
|
|
$this->user = "john.doe@example.com";
|
2017-05-11 02:01:00 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
protected function tearDownSeriesSubscription(): void {
|
2018-11-25 05:03:56 +00:00
|
|
|
unset($this->data, $this->user);
|
|
|
|
}
|
|
|
|
|
2022-10-07 22:38:17 +00:00
|
|
|
public function testReserveASubscription(): void {
|
|
|
|
$url = "http://example.com/feed5";
|
|
|
|
$exp = $this->nextID("arsse_subscriptions");
|
|
|
|
$act = Arsse::$db->subscriptionReserve($this->user, $url, "", "", false);
|
|
|
|
$this->assertSame($exp, $act);
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_subscriptions' => ["id", "owner", "url", "deleted", "modified"]]);
|
|
|
|
$state['arsse_subscriptions']['rows'][] = [$exp, $this->user, $url, 1, Date::transform("now", "sql")];
|
|
|
|
$this->compareExpectations(static::$drv, $state);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReserveADeletedSubscription(): void {
|
2017-05-11 02:01:00 +00:00
|
|
|
$url = "http://example.com/feed1";
|
2022-10-07 22:38:17 +00:00
|
|
|
$exp = 7;
|
|
|
|
$act = Arsse::$db->subscriptionReserve($this->user, $url, "", "", false);
|
|
|
|
$this->assertSame($exp, $act);
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_subscriptions' => ["id", "owner", "url", "deleted", "modified"]]);
|
|
|
|
$state['arsse_subscriptions']['rows'][6] = [$exp, $this->user, $url, 1, Date::transform("now", "sql")];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-05-11 02:01:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 22:38:17 +00:00
|
|
|
public function testReserveASubscriptionWithPassword(): void {
|
|
|
|
$url = "http://john:secret@example.com/feed5";
|
|
|
|
$exp = $this->nextID("arsse_subscriptions");
|
|
|
|
$act = Arsse::$db->subscriptionReserve($this->user, "http://example.com/feed5", "john", "secret", false);
|
|
|
|
$this->assertSame($exp, $act);
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_subscriptions' => ["id", "owner", "url", "deleted", "modified"]]);
|
|
|
|
$state['arsse_subscriptions']['rows'][] = [$exp, $this->user, $url, 1, Date::transform("now", "sql")];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-05-11 02:01:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 22:38:17 +00:00
|
|
|
public function testReserveADuplicateSubscription(): void {
|
|
|
|
$url = "http://example.com/feed2";
|
|
|
|
$this->assertException("constraintViolation", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionReserve($this->user, $url, "", "", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReserveASubscriptionWithDiscovery(): void {
|
|
|
|
$exp = $this->nextID("arsse_subscriptions");
|
|
|
|
$act = Arsse::$db->subscriptionReserve($this->user, "http://localhost:8000/Feed/Discovery/Valid");
|
|
|
|
$this->assertSame($exp, $act);
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_subscriptions' => ["id", "owner", "url", "deleted", "modified"]]);
|
|
|
|
$state['arsse_subscriptions']['rows'][] = [$exp, $this->user, "http://localhost:8000/Feed/Discovery/Feed", 1, Date::transform("now", "sql")];
|
|
|
|
$this->compareExpectations(static::$drv, $state);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRevealASubscription(): void {
|
|
|
|
$url = "http://example.com/feed1";
|
|
|
|
$this->assertNull(Arsse::$db->subscriptionReveal($this->user, 1, 7));
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_subscriptions' => ["id", "owner", "url", "deleted", "modified"]]);
|
|
|
|
$state['arsse_subscriptions']['rows'][6] = [7, $this->user, $url, 0, Date::transform("now", "sql")];
|
|
|
|
$this->compareExpectations(static::$drv, $state);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddASubscription(): void {
|
|
|
|
$url = "http://example.org/feed5";
|
|
|
|
$id = $this->nextID("arsse_subscriptions");
|
2021-02-27 20:24:02 +00:00
|
|
|
$db = $this->partialMock(Database::class, static::$drv);
|
2022-10-07 22:38:17 +00:00
|
|
|
$db->subscriptionUpdate->returns(true);
|
|
|
|
$db->subscriptionPropertiesSet->returns(true);
|
2021-02-27 20:24:02 +00:00
|
|
|
Arsse::$db = $db->get();
|
2022-10-07 22:38:17 +00:00
|
|
|
try {
|
|
|
|
$this->assertSame($id, Arsse::$db->subscriptionAdd($this->user, $url, "", "", false, ['order_type' => 2]));
|
|
|
|
} finally {
|
|
|
|
$db->subscriptionUpdate->calledWith($this->user, $id, true);
|
|
|
|
$db->subscriptionPropertiesSet->calledWith($this->user, $id, ['order_type' => 2]);
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_subscriptions' => ["id", "owner", "url", "deleted", "modified"]]);
|
|
|
|
$state['arsse_subscriptions']['rows'][] = [$id, $this->user, $url, 0, Date::transform("now", "sql")];
|
|
|
|
$this->compareExpectations(static::$drv, $state);
|
|
|
|
}
|
2017-10-02 19:42:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddASubscriptionToAnInvalidFeed(): void {
|
2022-10-07 22:38:17 +00:00
|
|
|
$url = "http://example.org/feed5";
|
|
|
|
$id = $this->nextID("arsse_subscriptions");
|
2021-02-27 20:24:02 +00:00
|
|
|
$db = $this->partialMock(Database::class, static::$drv);
|
2022-10-07 22:38:17 +00:00
|
|
|
$db->subscriptionUpdate->throws(new FeedException("", ['url' => $url], $this->mockGuzzleException(ClientException::class, "", 404)));
|
|
|
|
$db->subscriptionPropertiesSet->returns(true);
|
2021-02-27 20:24:02 +00:00
|
|
|
Arsse::$db = $db->get();
|
2019-09-03 23:04:23 +00:00
|
|
|
$this->assertException("invalidUrl", "Feed");
|
2017-05-11 02:01:00 +00:00
|
|
|
try {
|
2022-10-07 22:38:17 +00:00
|
|
|
Arsse::$db->subscriptionAdd($this->user, $url, "", "", false, ['order_type' => 2]);
|
2019-09-03 23:04:23 +00:00
|
|
|
} finally {
|
2022-10-07 22:38:17 +00:00
|
|
|
$db->subscriptionUpdate->calledWith($this->user, $id, true);
|
|
|
|
$db->subscriptionPropertiesSet->calledWith($this->user, $id, ['order_type' => 2]);
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_subscriptions' => ["id", "owner", "url", "deleted", "modified"]]);
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-05-11 02:01:00 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-11 22:00:35 +00:00
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRemoveASubscription(): void {
|
2017-07-17 11:47:57 +00:00
|
|
|
$this->assertTrue(Arsse::$db->subscriptionRemove($this->user, 1));
|
2022-10-07 22:38:17 +00:00
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_subscriptions' => ["id", "owner", "url", "deleted", "modified"]]);
|
|
|
|
$state['arsse_subscriptions']['rows'][0] = [1, $this->user, "http://example.com/feed2", 1, Date::transform("now", "sql")];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-05-12 03:20:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRemoveAMissingSubscription(): void {
|
2017-05-21 14:10:36 +00:00
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionRemove($this->user, 2112);
|
2017-05-12 03:20:10 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 22:38:17 +00:00
|
|
|
public function testRemoveADeletedSubscription(): void {
|
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionRemove($this->user, 7);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRemoveAnInvalidSubscription(): void {
|
2017-09-28 14:16:24 +00:00
|
|
|
$this->assertException("typeViolation", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionRemove($this->user, -1);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRemoveASubscriptionForTheWrongOwner(): void {
|
2017-05-18 17:21:17 +00:00
|
|
|
$this->user = "jane.doe@example.com";
|
2017-05-21 14:10:36 +00:00
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionRemove($this->user, 1);
|
2017-05-12 03:20:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testListSubscriptions(): void {
|
2017-05-15 03:03:48 +00:00
|
|
|
$exp = [
|
|
|
|
[
|
2021-01-28 19:55:18 +00:00
|
|
|
'url' => "http://example.com/feed2",
|
|
|
|
'title' => "eek",
|
|
|
|
'folder' => null,
|
|
|
|
'top_folder' => null,
|
|
|
|
'folder_name' => null,
|
|
|
|
'top_folder_name' => null,
|
|
|
|
'unread' => 4,
|
|
|
|
'pinned' => 1,
|
|
|
|
'order_type' => 2,
|
2021-03-06 00:31:11 +00:00
|
|
|
'icon_url' => "http://example.com/favicon.ico",
|
|
|
|
'icon_id' => 1,
|
2017-05-15 03:03:48 +00:00
|
|
|
],
|
|
|
|
[
|
2021-01-28 19:55:18 +00:00
|
|
|
'url' => "http://example.com/feed3",
|
|
|
|
'title' => "Ook",
|
|
|
|
'folder' => 2,
|
|
|
|
'top_folder' => 1,
|
|
|
|
'folder_name' => "Software",
|
|
|
|
'top_folder_name' => "Technology",
|
|
|
|
'unread' => 2,
|
|
|
|
'pinned' => 0,
|
|
|
|
'order_type' => 1,
|
2021-03-06 00:31:11 +00:00
|
|
|
'icon_url' => "http://example.net/favicon.ico",
|
|
|
|
'icon_id' => null,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'url' => "http://example.com/feed4",
|
|
|
|
'title' => "Bar",
|
|
|
|
'folder' => 3,
|
|
|
|
'top_folder' => 1,
|
|
|
|
'folder_name' => "Rocketry",
|
|
|
|
'top_folder_name' => "Technology",
|
|
|
|
'unread' => 0,
|
|
|
|
'pinned' => 0,
|
|
|
|
'order_type' => 0,
|
|
|
|
'icon_url' => null,
|
|
|
|
'icon_id' => null,
|
2017-05-15 03:03:48 +00:00
|
|
|
],
|
|
|
|
];
|
2017-12-08 00:39:32 +00:00
|
|
|
$this->assertResult($exp, Arsse::$db->subscriptionList($this->user));
|
2017-07-17 11:47:57 +00:00
|
|
|
$this->assertArraySubset($exp[0], Arsse::$db->subscriptionPropertiesGet($this->user, 1));
|
|
|
|
$this->assertArraySubset($exp[1], Arsse::$db->subscriptionPropertiesGet($this->user, 3));
|
2020-12-20 16:55:36 +00:00
|
|
|
// test that an absence of marks does not corrupt unread count
|
|
|
|
$exp = [
|
|
|
|
[
|
|
|
|
'url' => "http://example.com/feed2",
|
|
|
|
'title' => "eek",
|
|
|
|
'folder' => null,
|
|
|
|
'top_folder' => null,
|
|
|
|
'unread' => 5,
|
|
|
|
'pinned' => 0,
|
|
|
|
'order_type' => 0,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$this->assertResult($exp, Arsse::$db->subscriptionList("jill.doe@example.com"));
|
2017-05-15 03:03:48 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testListSubscriptionsInAFolder(): void {
|
2017-10-31 22:09:16 +00:00
|
|
|
$exp = [
|
|
|
|
[
|
|
|
|
'url' => "http://example.com/feed2",
|
2017-12-07 23:05:34 +00:00
|
|
|
'title' => "eek",
|
2017-10-31 22:09:16 +00:00
|
|
|
'folder' => null,
|
|
|
|
'top_folder' => null,
|
|
|
|
'unread' => 4,
|
|
|
|
'pinned' => 1,
|
|
|
|
'order_type' => 2,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$this->assertResult($exp, Arsse::$db->subscriptionList($this->user, null, false));
|
|
|
|
}
|
|
|
|
|
2021-03-06 00:31:11 +00:00
|
|
|
public function testListSubscriptionsWithRecursion(): void {
|
2017-05-15 03:03:48 +00:00
|
|
|
$exp = [
|
|
|
|
[
|
2017-05-18 17:21:17 +00:00
|
|
|
'url' => "http://example.com/feed3",
|
|
|
|
'title' => "Ook",
|
|
|
|
'folder' => 2,
|
2017-06-01 22:12:08 +00:00
|
|
|
'top_folder' => 1,
|
2017-05-18 17:21:17 +00:00
|
|
|
'unread' => 2,
|
|
|
|
'pinned' => 0,
|
|
|
|
'order_type' => 1,
|
2017-05-15 03:03:48 +00:00
|
|
|
],
|
|
|
|
];
|
2017-07-17 11:47:57 +00:00
|
|
|
$this->assertResult($exp, Arsse::$db->subscriptionList($this->user, 2));
|
2017-05-18 17:21:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testListSubscriptionsInAMissingFolder(): void {
|
2017-05-18 17:21:17 +00:00
|
|
|
$this->assertException("idMissing", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionList($this->user, 4);
|
2017-05-18 17:21:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testCountSubscriptions(): void {
|
2021-03-06 00:31:11 +00:00
|
|
|
$this->assertSame(3, Arsse::$db->subscriptionCount($this->user));
|
2017-10-03 16:43:46 +00:00
|
|
|
$this->assertSame(1, Arsse::$db->subscriptionCount($this->user, 2));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testCountSubscriptionsInAMissingFolder(): void {
|
2017-10-03 16:43:46 +00:00
|
|
|
$this->assertException("idMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionCount($this->user, 4);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testGetThePropertiesOfAMissingSubscription(): void {
|
2017-07-23 03:08:08 +00:00
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionPropertiesGet($this->user, 2112);
|
|
|
|
}
|
|
|
|
|
2022-10-07 22:38:17 +00:00
|
|
|
public function testGetThePropertiesOfADeletedSubscription(): void {
|
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionPropertiesGet($this->user, 7);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testGetThePropertiesOfAnInvalidSubscription(): void {
|
2017-09-28 14:16:24 +00:00
|
|
|
$this->assertException("typeViolation", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionPropertiesGet($this->user, -1);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testSetThePropertiesOfASubscription(): void {
|
2022-10-07 22:38:17 +00:00
|
|
|
$this->markTestIncomplete();
|
2017-08-29 14:50:31 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, [
|
2020-03-01 20:16:50 +00:00
|
|
|
'title' => "Ook Ook",
|
|
|
|
'folder' => 3,
|
|
|
|
'pinned' => false,
|
2021-01-17 00:06:20 +00:00
|
|
|
'scrape' => true,
|
2017-05-18 17:21:17 +00:00
|
|
|
'order_type' => 0,
|
2021-01-14 17:42:33 +00:00
|
|
|
'keep_rule' => "ook",
|
|
|
|
'block_rule' => "eek",
|
2017-05-18 17:21:17 +00:00
|
|
|
]);
|
|
|
|
$state = $this->primeExpectations($this->data, [
|
2022-10-07 22:38:17 +00:00
|
|
|
'arsse_subscriptions' => ['id','owner','feed_title', 'title','folder','pinned','order_type','keep_rule','block_rule','scrape'],
|
2017-05-18 17:21:17 +00:00
|
|
|
]);
|
2022-10-07 22:38:17 +00:00
|
|
|
$state['arsse_subscriptions']['rows'][0] = [1,"john.doe@example.com","eek","Ook Ook",3,0,0,"ook","eek",1];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-08-29 14:50:31 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, [
|
2021-01-14 17:42:33 +00:00
|
|
|
'title' => null,
|
|
|
|
'keep_rule' => null,
|
|
|
|
'block_rule' => null,
|
2017-05-18 17:21:17 +00:00
|
|
|
]);
|
2022-10-07 22:38:17 +00:00
|
|
|
$state['arsse_subscriptions']['rows'][0] = [1,"john.doe@example.com","eek",null,3,0,0,null,null,1];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-10-05 21:42:12 +00:00
|
|
|
// making no changes is a valid result
|
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['unhinged' => true]);
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-05-18 17:21:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testMoveASubscriptionToAMissingFolder(): void {
|
2017-05-18 17:21:17 +00:00
|
|
|
$this->assertException("idMissing", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['folder' => 4]);
|
2017-05-21 14:10:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testMoveASubscriptionToTheRootFolder(): void {
|
2017-07-23 03:08:08 +00:00
|
|
|
$this->assertTrue(Arsse::$db->subscriptionPropertiesSet($this->user, 3, ['folder' => null]));
|
|
|
|
}
|
|
|
|
|
2021-01-14 17:42:33 +00:00
|
|
|
/** @dataProvider provideInvalidSubscriptionProperties */
|
|
|
|
public function testSetThePropertiesOfASubscriptionToInvalidValues(array $data, string $exp): void {
|
|
|
|
$this->assertException($exp, "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, $data);
|
2017-05-21 14:10:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 17:42:33 +00:00
|
|
|
public function provideInvalidSubscriptionProperties(): iterable {
|
|
|
|
return [
|
|
|
|
'Empty title' => [['title' => ""], "missing"],
|
|
|
|
'Whitespace title' => [['title' => " "], "whitespace"],
|
|
|
|
'Non-string title' => [['title' => []], "typeViolation"],
|
|
|
|
'Non-string keep rule' => [['keep_rule' => 0], "typeViolation"],
|
|
|
|
'Invalid keep rule' => [['keep_rule' => "*"], "invalidValue"],
|
|
|
|
'Non-string block rule' => [['block_rule' => 0], "typeViolation"],
|
|
|
|
'Invalid block rule' => [['block_rule' => "*"], "invalidValue"],
|
|
|
|
];
|
2017-05-21 14:10:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRenameASubscriptionToZero(): void {
|
2017-07-17 11:47:57 +00:00
|
|
|
$this->assertTrue(Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['title' => 0]));
|
2017-05-18 17:21:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testSetThePropertiesOfAMissingSubscription(): void {
|
2017-05-21 14:10:36 +00:00
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 2112, ['folder' => null]);
|
2017-05-18 17:21:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testSetThePropertiesOfAnInvalidSubscription(): void {
|
2017-09-28 14:16:24 +00:00
|
|
|
$this->assertException("typeViolation", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, -1, ['folder' => null]);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRetrieveTheFaviconOfASubscription(): void {
|
2017-11-10 17:02:59 +00:00
|
|
|
$exp = "http://example.com/favicon.ico";
|
2020-11-06 15:27:30 +00:00
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionIcon(null, 1)['url']);
|
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionIcon(null, 2)['url']);
|
2021-03-06 00:31:11 +00:00
|
|
|
$this->assertSame(null, Arsse::$db->subscriptionIcon(null, 6));
|
2020-11-06 15:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRetrieveTheFaviconOfAMissingSubscription(): void {
|
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionIcon(null, -2112);
|
2017-11-10 17:02:59 +00:00
|
|
|
}
|
2018-10-26 18:40:20 +00:00
|
|
|
|
2022-10-07 22:38:17 +00:00
|
|
|
public function testRetrieveTheFaviconOfADeletedSubscription(): void {
|
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionIcon(null, 7);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRetrieveTheFaviconOfASubscriptionWithUser(): void {
|
2018-10-26 18:40:20 +00:00
|
|
|
$exp = "http://example.com/favicon.ico";
|
|
|
|
$user = "john.doe@example.com";
|
2020-11-06 15:27:30 +00:00
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionIcon($user, 1)['url']);
|
2021-03-06 00:31:11 +00:00
|
|
|
$this->assertSame(null, Arsse::$db->subscriptionIcon($user, 6));
|
2018-10-26 18:40:20 +00:00
|
|
|
$user = "jane.doe@example.com";
|
2020-11-06 15:27:30 +00:00
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionIcon($user, 2)['url']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRetrieveTheFaviconOfASubscriptionOfTheWrongUser(): void {
|
|
|
|
$user = "john.doe@example.com";
|
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
2021-01-26 17:03:26 +00:00
|
|
|
Arsse::$db->subscriptionIcon($user, 2);
|
2018-10-26 18:40:20 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testListTheTagsOfASubscription(): void {
|
2019-03-07 03:15:41 +00:00
|
|
|
$this->assertEquals([1,2], Arsse::$db->subscriptionTagsGet("john.doe@example.com", 1));
|
|
|
|
$this->assertEquals([2], Arsse::$db->subscriptionTagsGet("john.doe@example.com", 3));
|
|
|
|
$this->assertEquals(["Fascinating","Interesting"], Arsse::$db->subscriptionTagsGet("john.doe@example.com", 1, true));
|
|
|
|
$this->assertEquals(["Fascinating"], Arsse::$db->subscriptionTagsGet("john.doe@example.com", 3, true));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testListTheTagsOfAMissingSubscription(): void {
|
2019-03-07 03:15:41 +00:00
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionTagsGet($this->user, 101);
|
|
|
|
}
|
|
|
|
|
2022-10-07 22:38:17 +00:00
|
|
|
public function testListTheTagsOfADeletedSubscription(): void {
|
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionTagsGet($this->user, 7);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testGetRefreshTimeOfASubscription(): void {
|
2019-03-26 20:51:44 +00:00
|
|
|
$user = "john.doe@example.com";
|
|
|
|
$this->assertTime(strtotime("now + 1 hour"), Arsse::$db->subscriptionRefreshed($user));
|
|
|
|
$this->assertTime(strtotime("now - 1 hour"), Arsse::$db->subscriptionRefreshed($user, 1));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testGetRefreshTimeOfAMissingSubscription(): void {
|
2019-03-26 20:51:44 +00:00
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
2022-10-07 22:38:17 +00:00
|
|
|
Arsse::$db->subscriptionRefreshed("john.doe@example.com", 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetRefreshTimeOfADeletedSubscription(): void {
|
|
|
|
$this->assertException("subjectMissing", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionRefreshed("john.doe@example.com", 7);
|
2019-03-26 20:51:44 +00:00
|
|
|
}
|
2021-01-16 04:02:33 +00:00
|
|
|
|
|
|
|
public function testSetTheFilterRulesOfASubscriptionCheckingMarks(): void {
|
2022-10-07 22:38:17 +00:00
|
|
|
$this->markTestIncomplete();
|
2021-01-16 04:02:33 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet("jack.doe@example.com", 5, ['keep_rule' => "1|B|3|D", 'block_rule' => "4"]);
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_marks' => ['article', 'subscription', 'hidden']]);
|
|
|
|
$state['arsse_marks']['rows'][9][2] = 0;
|
|
|
|
$state['arsse_marks']['rows'][10][2] = 1;
|
|
|
|
$this->compareExpectations(static::$drv, $state);
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|