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
|
|
|
|
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;
|
|
|
|
|
|
|
|
trait SeriesSubscription {
|
2020-01-20 18:52:48 +00:00
|
|
|
public function setUpSeriesSubscription(): void {
|
2018-11-25 05:03:56 +00:00
|
|
|
$this->data = [
|
|
|
|
'arsse_users' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => 'str',
|
|
|
|
'password' => 'str',
|
|
|
|
],
|
|
|
|
'rows' => [
|
2019-03-09 21:23:56 +00:00
|
|
|
["jane.doe@example.com", ""],
|
|
|
|
["john.doe@example.com", ""],
|
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' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'owner' => "str",
|
|
|
|
'parent' => "int",
|
|
|
|
'name' => "str",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[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"],
|
|
|
|
]
|
2017-06-18 16:24:19 +00:00
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
'arsse_feeds' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'url' => "str",
|
|
|
|
'title' => "str",
|
|
|
|
'username' => "str",
|
|
|
|
'password' => "str",
|
2019-03-26 20:51:44 +00:00
|
|
|
'updated' => "datetime",
|
2018-11-25 05:03:56 +00:00
|
|
|
'next_fetch' => "datetime",
|
|
|
|
'favicon' => "str",
|
|
|
|
],
|
|
|
|
'rows' => [] // filled in the series setup
|
2017-05-11 02:01:00 +00:00
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
'arsse_subscriptions' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'owner' => "str",
|
|
|
|
'feed' => "int",
|
|
|
|
'title' => "str",
|
|
|
|
'folder' => "int",
|
|
|
|
'pinned' => "bool",
|
|
|
|
'order_type' => "int",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[1,"john.doe@example.com",2,null,null,1,2],
|
|
|
|
[2,"jane.doe@example.com",2,null,null,0,0],
|
|
|
|
[3,"john.doe@example.com",3,"Ook",2,0,1],
|
|
|
|
]
|
2017-05-15 03:03:48 +00:00
|
|
|
],
|
2019-03-07 03:15:41 +00:00
|
|
|
'arsse_tags' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'owner' => "str",
|
|
|
|
'name' => "str",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[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' => [
|
|
|
|
'columns' => [
|
|
|
|
'tag' => "int",
|
|
|
|
'subscription' => "int",
|
|
|
|
'assigned' => "bool",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[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' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'feed' => "int",
|
|
|
|
'url_title_hash' => "str",
|
|
|
|
'url_content_hash' => "str",
|
|
|
|
'title_content_hash' => "str",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[1,2,"","",""],
|
|
|
|
[2,2,"","",""],
|
|
|
|
[3,2,"","",""],
|
|
|
|
[4,2,"","",""],
|
|
|
|
[5,2,"","",""],
|
|
|
|
[6,3,"","",""],
|
|
|
|
[7,3,"","",""],
|
|
|
|
[8,3,"","",""],
|
|
|
|
]
|
2017-05-17 02:19:40 +00:00
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
'arsse_marks' => [
|
|
|
|
'columns' => [
|
|
|
|
'article' => "int",
|
|
|
|
'subscription' => "int",
|
|
|
|
'read' => "bool",
|
|
|
|
'starred' => "bool",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[1,2,1,0],
|
|
|
|
[2,2,1,0],
|
|
|
|
[3,2,1,0],
|
|
|
|
[4,2,1,0],
|
|
|
|
[5,2,1,0],
|
|
|
|
[1,1,1,0],
|
|
|
|
[7,3,1,0],
|
|
|
|
[8,3,0,0],
|
|
|
|
]
|
2017-05-17 02:19:40 +00:00
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
];
|
2017-06-18 16:48:29 +00:00
|
|
|
$this->data['arsse_feeds']['rows'] = [
|
2019-03-26 20:51:44 +00:00
|
|
|
[1,"http://example.com/feed1", "Ook", "", "",strtotime("now"),strtotime("now"),''],
|
|
|
|
[2,"http://example.com/feed2", "eek", "", "",strtotime("now - 1 hour"),strtotime("now - 1 hour"),'http://example.com/favicon.ico'],
|
|
|
|
[3,"http://example.com/feed3", "Ack", "", "",strtotime("now + 1 hour"),strtotime("now + 1 hour"),''],
|
2017-05-11 02:01:00 +00:00
|
|
|
];
|
|
|
|
// initialize a partial mock of the Database object to later manipulate the feedUpdate method
|
2019-09-05 14:03:32 +00:00
|
|
|
Arsse::$db = \Phake::partialMock(Database::class, static::$drv);
|
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);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddASubscriptionToAnExistingFeed(): void {
|
2017-05-11 02:01:00 +00:00
|
|
|
$url = "http://example.com/feed1";
|
|
|
|
$subID = $this->nextID("arsse_subscriptions");
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$db)->feedUpdate->thenReturn(true);
|
2017-08-29 14:50:31 +00:00
|
|
|
$this->assertSame($subID, Arsse::$db->subscriptionAdd($this->user, $url));
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionAdd");
|
|
|
|
\Phake::verify(Arsse::$db, \Phake::times(0))->feedUpdate(1, true);
|
2017-05-11 02:01:00 +00:00
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_feeds' => ['id','url','username','password'],
|
|
|
|
'arsse_subscriptions' => ['id','owner','feed'],
|
|
|
|
]);
|
2017-05-18 17:21:17 +00:00
|
|
|
$state['arsse_subscriptions']['rows'][] = [$subID,$this->user,1];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-05-11 02:01:00 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddASubscriptionToANewFeed(): void {
|
2017-05-11 02:01:00 +00:00
|
|
|
$url = "http://example.org/feed1";
|
|
|
|
$feedID = $this->nextID("arsse_feeds");
|
|
|
|
$subID = $this->nextID("arsse_subscriptions");
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$db)->feedUpdate->thenReturn(true);
|
2017-10-02 19:42:15 +00:00
|
|
|
$this->assertSame($subID, Arsse::$db->subscriptionAdd($this->user, $url, "", "", false));
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionAdd");
|
|
|
|
\Phake::verify(Arsse::$db)->feedUpdate($feedID, true);
|
2017-05-11 02:01:00 +00:00
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_feeds' => ['id','url','username','password'],
|
|
|
|
'arsse_subscriptions' => ['id','owner','feed'],
|
|
|
|
]);
|
|
|
|
$state['arsse_feeds']['rows'][] = [$feedID,$url,"",""];
|
2017-05-18 17:21:17 +00:00
|
|
|
$state['arsse_subscriptions']['rows'][] = [$subID,$this->user,$feedID];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-05-11 02:01:00 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddASubscriptionToANewFeedViaDiscovery(): void {
|
2017-10-02 19:42:15 +00:00
|
|
|
$url = "http://localhost:8000/Feed/Discovery/Valid";
|
|
|
|
$discovered = "http://localhost:8000/Feed/Discovery/Feed";
|
|
|
|
$feedID = $this->nextID("arsse_feeds");
|
|
|
|
$subID = $this->nextID("arsse_subscriptions");
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$db)->feedUpdate->thenReturn(true);
|
2017-10-02 19:42:15 +00:00
|
|
|
$this->assertSame($subID, Arsse::$db->subscriptionAdd($this->user, $url, "", "", true));
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionAdd");
|
|
|
|
\Phake::verify(Arsse::$db)->feedUpdate($feedID, true);
|
2017-10-02 19:42:15 +00:00
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_feeds' => ['id','url','username','password'],
|
|
|
|
'arsse_subscriptions' => ['id','owner','feed'],
|
|
|
|
]);
|
|
|
|
$state['arsse_feeds']['rows'][] = [$feedID,$discovered,"",""];
|
|
|
|
$state['arsse_subscriptions']['rows'][] = [$subID,$this->user,$feedID];
|
2019-06-21 22:52:27 +00:00
|
|
|
$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 {
|
2017-05-11 02:01:00 +00:00
|
|
|
$url = "http://example.org/feed1";
|
|
|
|
$feedID = $this->nextID("arsse_feeds");
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$db)->feedUpdate->thenThrow(new FeedException($url, new \PicoFeed\Client\InvalidUrlException()));
|
2019-09-03 23:04:23 +00:00
|
|
|
$this->assertException("invalidUrl", "Feed");
|
2017-05-11 02:01:00 +00:00
|
|
|
try {
|
2017-10-02 19:42:15 +00:00
|
|
|
Arsse::$db->subscriptionAdd($this->user, $url, "", "", false);
|
2019-09-03 23:04:23 +00:00
|
|
|
} finally {
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionAdd");
|
|
|
|
\Phake::verify(Arsse::$db)->feedUpdate($feedID, true);
|
2017-05-11 02:01:00 +00:00
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_feeds' => ['id','url','username','password'],
|
|
|
|
'arsse_subscriptions' => ['id','owner','feed'],
|
|
|
|
]);
|
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 testAddADuplicateSubscription(): void {
|
2017-05-11 22:00:35 +00:00
|
|
|
$url = "http://example.com/feed2";
|
|
|
|
$this->assertException("constraintViolation", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionAdd($this->user, $url);
|
2017-05-11 22:00:35 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddADuplicateSubscriptionWithEquivalentUrl(): void {
|
2019-09-03 23:04:23 +00:00
|
|
|
$url = "http://EXAMPLE.COM/feed2";
|
|
|
|
$this->assertException("constraintViolation", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionAdd($this->user, $url);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddADuplicateSubscriptionViaRedirection(): void {
|
2019-08-06 18:17:56 +00:00
|
|
|
$url = "http://localhost:8000/Feed/Parsing/Valid";
|
|
|
|
Arsse::$db->subscriptionAdd($this->user, $url);
|
|
|
|
$subID = $this->nextID("arsse_subscriptions");
|
|
|
|
$url = "http://localhost:8000/Feed/Fetching/RedirectionDuplicate";
|
|
|
|
$this->assertSame($subID, Arsse::$db->subscriptionAdd($this->user, $url));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddASubscriptionWithoutAuthority(): void {
|
2017-05-11 22:00:35 +00:00
|
|
|
$url = "http://example.com/feed1";
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2017-05-11 22:00:35 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionAdd($this->user, $url);
|
2017-05-11 22:00:35 +00:00
|
|
|
}
|
2017-05-12 03:20:10 +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));
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionRemove");
|
2017-05-12 03:20:10 +00:00
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_feeds' => ['id','url','username','password'],
|
|
|
|
'arsse_subscriptions' => ['id','owner','feed'],
|
|
|
|
]);
|
|
|
|
array_shift($state['arsse_subscriptions']['rows']);
|
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
|
|
|
}
|
|
|
|
|
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 testRemoveASubscriptionWithoutAuthority(): void {
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2017-05-12 03:20:10 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionRemove($this->user, 1);
|
2017-05-12 03:20:10 +00:00
|
|
|
}
|
2017-05-15 03:03:48 +00:00
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testListSubscriptions(): void {
|
2017-05-15 03:03:48 +00:00
|
|
|
$exp = [
|
|
|
|
[
|
2017-05-18 17:21:17 +00:00
|
|
|
'url' => "http://example.com/feed2",
|
2017-12-07 23:05:34 +00:00
|
|
|
'title' => "eek",
|
2017-05-18 17:21:17 +00:00
|
|
|
'folder' => null,
|
2017-06-01 22:12:08 +00:00
|
|
|
'top_folder' => null,
|
2017-05-18 17:21:17 +00:00
|
|
|
'unread' => 4,
|
|
|
|
'pinned' => 1,
|
|
|
|
'order_type' => 2,
|
2017-05-15 03:03:48 +00:00
|
|
|
],
|
|
|
|
[
|
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-12-08 00:39:32 +00:00
|
|
|
$this->assertResult($exp, Arsse::$db->subscriptionList($this->user));
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionList");
|
2017-07-17 11:47:57 +00:00
|
|
|
$this->assertArraySubset($exp[0], Arsse::$db->subscriptionPropertiesGet($this->user, 1));
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionPropertiesGet");
|
2017-07-17 11:47:57 +00:00
|
|
|
$this->assertArraySubset($exp[1], Arsse::$db->subscriptionPropertiesGet($this->user, 3));
|
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));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testListSubscriptionsWithoutRecursion(): 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 testListSubscriptionsWithoutAuthority(): void {
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2017-05-18 17:21:17 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionList($this->user);
|
2017-05-18 17:21:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testCountSubscriptions(): void {
|
2017-10-03 16:43:46 +00:00
|
|
|
$this->assertSame(2, Arsse::$db->subscriptionCount($this->user));
|
|
|
|
$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 testCountSubscriptionsWithoutAuthority(): void {
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2017-10-03 16:43:46 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
|
|
|
Arsse::$db->subscriptionCount($this->user);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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 testGetThePropertiesOfASubscriptionWithoutAuthority(): void {
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2017-07-23 03:08:08 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
|
|
|
Arsse::$db->subscriptionPropertiesGet($this->user, 1);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testSetThePropertiesOfASubscription(): void {
|
2017-08-29 14:50:31 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, [
|
2017-05-18 17:21:17 +00:00
|
|
|
'title' => "Ook Ook",
|
|
|
|
'folder' => 3,
|
|
|
|
'pinned' => false,
|
|
|
|
'order_type' => 0,
|
|
|
|
]);
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionPropertiesSet");
|
2017-05-18 17:21:17 +00:00
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_feeds' => ['id','url','username','password','title'],
|
|
|
|
'arsse_subscriptions' => ['id','owner','feed','title','folder','pinned','order_type'],
|
|
|
|
]);
|
|
|
|
$state['arsse_subscriptions']['rows'][0] = [1,"john.doe@example.com",2,"Ook Ook",3,0,0];
|
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, [
|
2017-05-21 14:10:36 +00:00
|
|
|
'title' => null,
|
2017-05-18 17:21:17 +00:00
|
|
|
]);
|
|
|
|
$state['arsse_subscriptions']['rows'][0] = [1,"john.doe@example.com",2,null,3,0,0];
|
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]));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRenameASubscriptionToABlankTitle(): void {
|
2017-05-21 14:10:36 +00:00
|
|
|
$this->assertException("missing", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['title' => ""]);
|
2017-05-21 14:10:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRenameASubscriptionToAWhitespaceTitle(): void {
|
2017-05-21 14:10:36 +00:00
|
|
|
$this->assertException("whitespace", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['title' => " "]);
|
2017-05-21 14:10:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRenameASubscriptionToFalse(): void {
|
2017-09-28 14:16:24 +00:00
|
|
|
$this->assertException("typeViolation", "Db", "ExceptionInput");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['title' => false]);
|
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 testRenameASubscriptionToAnArray(): void {
|
2017-09-26 20:45:41 +00:00
|
|
|
$this->assertException("typeViolation", "Db", "ExceptionInput");
|
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['title' => []]);
|
|
|
|
}
|
|
|
|
|
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 testSetThePropertiesOfASubscriptionWithoutAuthority(): void {
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2017-05-18 17:21:17 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['folder' => null]);
|
2017-05-15 03:03:48 +00:00
|
|
|
}
|
2017-11-10 17:02:59 +00:00
|
|
|
|
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";
|
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionFavicon(1));
|
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionFavicon(2));
|
2017-11-30 03:42:50 +00:00
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(3));
|
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(4));
|
2017-11-10 17:02:59 +00:00
|
|
|
// authorization shouldn't have any bearing on this function
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2017-11-10 17:02:59 +00:00
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionFavicon(1));
|
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionFavicon(2));
|
2017-11-30 03:42:50 +00:00
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(3));
|
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(4));
|
2017-11-10 17:02:59 +00:00
|
|
|
// invalid IDs should simply return an empty string
|
2017-11-30 03:42:50 +00:00
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(-2112));
|
2017-11-10 17:02:59 +00:00
|
|
|
}
|
2018-10-26 18:40:20 +00:00
|
|
|
|
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";
|
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionFavicon(1, $user));
|
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(2, $user));
|
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(3, $user));
|
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(4, $user));
|
|
|
|
$user = "jane.doe@example.com";
|
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(1, $user));
|
|
|
|
$this->assertSame($exp, Arsse::$db->subscriptionFavicon(2, $user));
|
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(3, $user));
|
|
|
|
$this->assertSame('', Arsse::$db->subscriptionFavicon(4, $user));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRetrieveTheFaviconOfASubscriptionWithUserWithoutAuthority(): void {
|
2018-10-26 18:40:20 +00:00
|
|
|
$exp = "http://example.com/favicon.ico";
|
|
|
|
$user = "john.doe@example.com";
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2018-10-26 18:40:20 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
|
|
|
Arsse::$db->subscriptionFavicon(-2112, $user);
|
|
|
|
}
|
2019-03-07 03:15:41 +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);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testListTheTagsOfASubscriptionWithoutAuthority(): void {
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2019-03-07 03:15:41 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
|
|
|
Arsse::$db->subscriptionTagsGet("john.doe@example.com", 1);
|
|
|
|
}
|
2019-03-26 20:51:44 +00:00
|
|
|
|
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");
|
|
|
|
$this->assertTime(strtotime("now - 1 hour"), Arsse::$db->subscriptionRefreshed("john.doe@example.com", 2));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testGetRefreshTimeOfASubscriptionWithoutAuthority(): void {
|
2019-09-05 14:03:32 +00:00
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(false);
|
2019-03-26 20:51:44 +00:00
|
|
|
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
|
|
|
$this->assertTime(strtotime("now + 1 hour"), Arsse::$db->subscriptionRefreshed("john.doe@example.com"));
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|