@ -13,7 +13,8 @@ use JKingWeb\Arsse\Misc\Date;
use Phake;
trait SeriesArticle {
protected $data = [
protected function setUpSeriesArticle() {
$this->data = [
'arsse_users' => [
'columns' => [
'id' => 'str',
@ -260,7 +261,7 @@ trait SeriesArticle {
],
],
];
protected $ matches = [
$this-> matches = [
[
'id' => 101,
'url' => 'http://example.com/1',
@ -362,7 +363,7 @@ trait SeriesArticle {
'note' => "",
],
];
protected $ fields = [
$this-> fields = [
Database::LIST_MINIMAL => [
"id", "subscription", "feed", "modified_date", "marked_date", "unread", "starred", "edition", "edited_date",
],
@ -382,94 +383,94 @@ trait SeriesArticle {
"note",
],
];
public function setUpSeries() {
$this->checkTables = ['arsse_marks' => ["subscription","article","read","starred","modified","note"],];
$this->user = "john.doe@example.net";
}
protected function compareIds(array $exp, Context $c) {
$ids = array_column($ids = Arsse::$db->articleList($this->user, $c)->getAll(), "id");
sort($ids);
sort($exp);
$this->assertEquals($exp, $ids);
protected function tearDownSeriesArticle() {
unset($this->data, $this->matches, $this->fields, $this->checkTables, $this->user);
}
public function testListArticlesCheckingContext() {
$this->user = "john.doe@example.com";
$compareIds = function(array $exp, Context $c) {
$ids = array_column($ids = Arsse::$db->articleList("john.doe@example.com", $c)->getAll(), "id");
sort($ids);
sort($exp);
$this->assertEquals($exp, $ids);
};
// get all items for user
$exp = [1,2,3,4,5,6,7,8,19,20];
$this->compareIds($exp, new Context);
$this->compareIds($exp, (new Context)->articles(range(1, Database::LIMIT_ARTICLES * 3)));
$compareIds($exp, new Context);
$compareIds($exp, (new Context)->articles(range(1, Database::LIMIT_ARTICLES * 3)));
// get items from a folder tree
$this-> compareIds([5,6,7,8], (new Context)->folder(1));
$compareIds([5,6,7,8], (new Context)->folder(1));
// get items from a leaf folder
$this-> compareIds([7,8], (new Context)->folder(6));
$compareIds([7,8], (new Context)->folder(6));
// get items from a non-leaf folder without descending
$this-> compareIds([1,2,3,4], (new Context)->folderShallow(0));
$this-> compareIds([5,6], (new Context)->folderShallow(1));
$compareIds([1,2,3,4], (new Context)->folderShallow(0));
$compareIds([5,6], (new Context)->folderShallow(1));
// get items from a single subscription
$exp = [19,20];
$this-> compareIds($exp, (new Context)->subscription(5));
$compareIds($exp, (new Context)->subscription(5));
// get un/read items from a single subscription
$this-> compareIds([20], (new Context)->subscription(5)->unread(true));
$this-> compareIds([19], (new Context)->subscription(5)->unread(false));
$compareIds([20], (new Context)->subscription(5)->unread(true));
$compareIds([19], (new Context)->subscription(5)->unread(false));
// get starred articles
$this-> compareIds([1,20], (new Context)->starred(true));
$this-> compareIds([2,3,4,5,6,7,8,19], (new Context)->starred(false));
$this-> compareIds([1], (new Context)->starred(true)->unread(false));
$this-> compareIds([], (new Context)->starred(true)->unread(false)->subscription(5));
$compareIds([1,20], (new Context)->starred(true));
$compareIds([2,3,4,5,6,7,8,19], (new Context)->starred(false));
$compareIds([1], (new Context)->starred(true)->unread(false));
$compareIds([], (new Context)->starred(true)->unread(false)->subscription(5));
// get items relative to edition
$this-> compareIds([19], (new Context)->subscription(5)->latestEdition(999));
$this-> compareIds([19], (new Context)->subscription(5)->latestEdition(19));
$this-> compareIds([20], (new Context)->subscription(5)->oldestEdition(999));
$this-> compareIds([20], (new Context)->subscription(5)->oldestEdition(1001));
$compareIds([19], (new Context)->subscription(5)->latestEdition(999));
$compareIds([19], (new Context)->subscription(5)->latestEdition(19));
$compareIds([20], (new Context)->subscription(5)->oldestEdition(999));
$compareIds([20], (new Context)->subscription(5)->oldestEdition(1001));
// get items relative to article ID
$this-> compareIds([1,2,3], (new Context)->latestArticle(3));
$this-> compareIds([19,20], (new Context)->oldestArticle(19));
$compareIds([1,2,3], (new Context)->latestArticle(3));
$compareIds([19,20], (new Context)->oldestArticle(19));
// get items relative to (feed) modification date
$exp = [2,4,6,8,20];
$this-> compareIds($exp, (new Context)->modifiedSince("2005-01-01T00:00:00Z"));
$this-> compareIds($exp, (new Context)->modifiedSince("2010-01-01T00:00:00Z"));
$compareIds($exp, (new Context)->modifiedSince("2005-01-01T00:00:00Z"));
$compareIds($exp, (new Context)->modifiedSince("2010-01-01T00:00:00Z"));
$exp = [1,3,5,7,19];
$this-> compareIds($exp, (new Context)->notModifiedSince("2005-01-01T00:00:00Z"));
$this-> compareIds($exp, (new Context)->notModifiedSince("2000-01-01T00:00:00Z"));
$compareIds($exp, (new Context)->notModifiedSince("2005-01-01T00:00:00Z"));
$compareIds($exp, (new Context)->notModifiedSince("2000-01-01T00:00:00Z"));
// get items relative to (user) modification date (both marks and labels apply)
$this-> compareIds([8,19], (new Context)->markedSince("2014-01-01T00:00:00Z"));
$this-> compareIds([2,4,6,8,19,20], (new Context)->markedSince("2010-01-01T00:00:00Z"));
$this-> compareIds([1,2,3,4,5,6,7,20], (new Context)->notMarkedSince("2014-01-01T00:00:00Z"));
$this-> compareIds([1,3,5,7], (new Context)->notMarkedSince("2005-01-01T00:00:00Z"));
$compareIds([8,19], (new Context)->markedSince("2014-01-01T00:00:00Z"));
$compareIds([2,4,6,8,19,20], (new Context)->markedSince("2010-01-01T00:00:00Z"));
$compareIds([1,2,3,4,5,6,7,20], (new Context)->notMarkedSince("2014-01-01T00:00:00Z"));
$compareIds([1,3,5,7], (new Context)->notMarkedSince("2005-01-01T00:00:00Z"));
// paged results
$this-> compareIds([1], (new Context)->limit(1));
$this-> compareIds([2], (new Context)->limit(1)->oldestEdition(1+1));
$this-> compareIds([3], (new Context)->limit(1)->oldestEdition(2+1));
$this-> compareIds([4,5], (new Context)->limit(2)->oldestEdition(3+1));
$compareIds([1], (new Context)->limit(1));
$compareIds([2], (new Context)->limit(1)->oldestEdition(1+1));
$compareIds([3], (new Context)->limit(1)->oldestEdition(2+1));
$compareIds([4,5], (new Context)->limit(2)->oldestEdition(3+1));
// reversed results
$this-> compareIds([20], (new Context)->reverse(true)->limit(1));
$this-> compareIds([19], (new Context)->reverse(true)->limit(1)->latestEdition(1001-1));
$this-> compareIds([8], (new Context)->reverse(true)->limit(1)->latestEdition(19-1));
$this-> compareIds([7,6], (new Context)->reverse(true)->limit(2)->latestEdition(8-1));
$compareIds([20], (new Context)->reverse(true)->limit(1));
$compareIds([19], (new Context)->reverse(true)->limit(1)->latestEdition(1001-1));
$compareIds([8], (new Context)->reverse(true)->limit(1)->latestEdition(19-1));
$compareIds([7,6], (new Context)->reverse(true)->limit(2)->latestEdition(8-1));
// get articles by label ID
$this-> compareIds([1,19], (new Context)->label(1));
$this-> compareIds([1,5,20], (new Context)->label(2));
$compareIds([1,19], (new Context)->label(1));
$compareIds([1,5,20], (new Context)->label(2));
// get articles by label name
$this-> compareIds([1,19], (new Context)->labelName("Interesting"));
$this-> compareIds([1,5,20], (new Context)->labelName("Fascinating"));
$compareIds([1,19], (new Context)->labelName("Interesting"));
$compareIds([1,5,20], (new Context)->labelName("Fascinating"));
// get articles with any or no label
$this-> compareIds([1,5,8,19,20], (new Context)->labelled(true));
$this-> compareIds([2,3,4,6,7], (new Context)->labelled(false));
$compareIds([1,5,8,19,20], (new Context)->labelled(true));
$compareIds([2,3,4,6,7], (new Context)->labelled(false));
// get a specific article or edition
$this-> compareIds([20], (new Context)->article(20));
$this-> compareIds([20], (new Context)->edition(1001));
$compareIds([20], (new Context)->article(20));
$compareIds([20], (new Context)->edition(1001));
// get multiple specific articles or editions
$this-> compareIds([1,20], (new Context)->articles([1,20,50]));
$this-> compareIds([1,20], (new Context)->editions([1,1001,50]));
$compareIds([1,20], (new Context)->articles([1,20,50]));
$compareIds([1,20], (new Context)->editions([1,1001,50]));
// get articles base on whether or not they have notes
$this-> compareIds([1,3,4,5,6,7,8,19,20], (new Context)->annotated(false));
$this-> compareIds([2], (new Context)->annotated(true));
$compareIds([1,3,4,5,6,7,8,19,20], (new Context)->annotated(false));
$compareIds([2], (new Context)->annotated(true));
// get specific starred articles
$this-> compareIds([1], (new Context)->articles([1,2,3])->starred(true));
$this-> compareIds([2,3], (new Context)->articles([1,2,3])->starred(false));
$compareIds([1], (new Context)->articles([1,2,3])->starred(true));
$compareIds([2,3], (new Context)->articles([1,2,3])->starred(false));
}
public function testListArticlesOfAMissingFolder() {