@ -114,10 +114,10 @@ trait SeriesArticle {
[1,1,null,"Title one", null,null,null,"First article", null,"","","","2000-01-01T00:00:00Z"],
[2,1,null,"Title two", null,null,null,"Second article",null,"","","","2010-01-01T00:00:00Z"],
[3,2,null,"Title three",null,null,null,"Third article", null,"","","","2000-01-01T00:00:00Z"],
[4,2,null,null,null ,null,null,null,null,"","","","2010-01-01T00:00:00Z"],
[5,3,null,null,null ,null,null,null,null,"","","","2000-01-01T00:00:00Z"],
[6,3,null,null,null ,null,null,null,null,"","","","2010-01-01T00:00:00Z"],
[7,4,null,null,null ,null,null,null,null,"","","","2000-01-01T00:00:00Z"],
[4,2,null,null,"John Doe" ,null,null,null,null,"","","","2010-01-01T00:00:00Z"],
[5,3,null,null,"John Doe" ,null,null,null,null,"","","","2000-01-01T00:00:00Z"],
[6,3,null,null,"Jane Doe" ,null,null,null,null,"","","","2010-01-01T00:00:00Z"],
[7,4,null,null,"Jane Doe" ,null,null,null,null,"","","","2000-01-01T00:00:00Z"],
[8,4,null,null,null,null,null,null,null,"","","","2010-01-01T00:00:00Z"],
[9,5,null,null,null,null,null,null,null,"","","","2000-01-01T00:00:00Z"],
[10,5,null,null,null,null,null,null,null,"","","","2010-01-01T00:00:00Z"],
@ -414,94 +414,76 @@ trait SeriesArticle {
$this->assertEquals($exp, Arsse::$db->editionArticle(...range(1, 1001)));
}
public function testListArticlesCheckingContext() {
$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];
$compareIds($exp, new Context);
$compareIds($exp, (new Context)->articles(range(1, Database::LIMIT_ARTICLES * 3)));
// get items from a folder tree
$compareIds([5,6,7,8], (new Context)->folder(1));
// get items from a leaf folder
$compareIds([7,8], (new Context)->folder(6));
// get items from a non-leaf folder without descending
$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];
$compareIds($exp, (new Context)->subscription(5));
// get un/read items from a single subscription
$compareIds([20], (new Context)->subscription(5)->unread(true));
$compareIds([19], (new Context)->subscription(5)->unread(false));
// get starred articles
$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
$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
$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];
$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];
$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)
$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
$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
$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
$compareIds([1,19], (new Context)->label(1));
$compareIds([1,5,20], (new Context)->label(2));
// get articles by label name
$compareIds([1,19], (new Context)->labelName("Interesting"));
$compareIds([1,5,20], (new Context)->labelName("Fascinating"));
// get articles with any or no label
$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
$compareIds([20], (new Context)->article(20));
$compareIds([20], (new Context)->edition(1001));
// get multiple specific articles or editions
$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
$compareIds([1,3,4,5,6,7,8,19,20], (new Context)->annotated(false));
$compareIds([2], (new Context)->annotated(true));
// get specific starred articles
$compareIds([1], (new Context)->articles([1,2,3])->starred(true));
$compareIds([2,3], (new Context)->articles([1,2,3])->starred(false));
// get items that match search terms
$compareIds([1,2,3], (new Context)->searchTerms(["Article"]));
$compareIds([1], (new Context)->searchTerms(["one", "first"]));
// get items that match search terms in note
$compareIds([2], (new Context)->annotationTerms(["some"]));
$compareIds([2], (new Context)->annotationTerms(["some", "note"]));
$compareIds([2], (new Context)->annotationTerms(["some note"]));
$compareIds([], (new Context)->annotationTerms(["some", "sauce"]));
/** @dataProvider provideContextMatches */
public function testListArticlesCheckingContext(Context $c, array $exp) {
$ids = array_column($ids = Arsse::$db->articleList("john.doe@example.com", $c)->getAll(), "id");
sort($ids);
sort($exp);
$this->assertEquals($exp, $ids);
}
public function provideContextMatches() {
return [
"Blank context" => [new Context, [1,2,3,4,5,6,7,8,19,20]],
"Folder tree" => [(new Context)->folder(1), [5,6,7,8]],
"Leaf folder" => [(new Context)->folder(6), [7,8]],
"Root folder only" => [(new Context)->folderShallow(0), [1,2,3,4]],
"Shallow folder" => [(new Context)->folderShallow(1), [5,6]],
"Subscription" => [(new Context)->subscription(5), [19,20]],
"Unread" => [(new Context)->subscription(5)->unread(true), [20]],
"Read" => [(new Context)->subscription(5)->unread(false), [19]],
"Starred" => [(new Context)->starred(true), [1,20]],
"Unstarred" => [(new Context)->starred(false), [2,3,4,5,6,7,8,19]],
"Starred and Read" => [(new Context)->starred(true)->unread(false), [1]],
"Starred and Read in subscription" => [(new Context)->starred(true)->unread(false)->subscription(5), []],
"Annotated" => [(new Context)->annotated(true), [2]],
"Not annotated" => [(new Context)->annotated(false), [1,3,4,5,6,7,8,19,20]],
"Labelled" => [(new Context)->labelled(true), [1,5,8,19,20]],
"Not labelled" => [(new Context)->labelled(false), [2,3,4,6,7]],
"Not after edition 999" => [(new Context)->subscription(5)->latestEdition(999), [19]],
"Not after edition 19" => [(new Context)->subscription(5)->latestEdition(19), [19]],
"Not before edition 999" => [(new Context)->subscription(5)->oldestEdition(999), [20]],
"Not before edition 1001" => [(new Context)->subscription(5)->oldestEdition(1001), [20]],
"Not after article 3" => [(new Context)->latestArticle(3), [1,2,3]],
"Not before article 19" => [(new Context)->oldestArticle(19), [19,20]],
"Modified by author since 2005" => [(new Context)->modifiedSince("2005-01-01T00:00:00Z"), [2,4,6,8,20]],
"Modified by author since 2010" => [(new Context)->modifiedSince("2010-01-01T00:00:00Z"), [2,4,6,8,20]],
"Not modified by author since 2005" => [(new Context)->notModifiedSince("2005-01-01T00:00:00Z"), [1,3,5,7,19]],
"Not modified by author since 2000" => [(new Context)->notModifiedSince("2000-01-01T00:00:00Z"), [1,3,5,7,19]],
"Marked or labelled since 2014" => [(new Context)->markedSince("2014-01-01T00:00:00Z"), [8,19]],
"Marked or labelled since 2010" => [(new Context)->markedSince("2010-01-01T00:00:00Z"), [2,4,6,8,19,20]],
"Not marked or labelled since 2014" => [(new Context)->notMarkedSince("2014-01-01T00:00:00Z"), [1,2,3,4,5,6,7,20]],
"Not marked or labelled since 2005" => [(new Context)->notMarkedSince("2005-01-01T00:00:00Z"), [1,3,5,7]],
"Paged results" => [(new Context)->limit(2)->oldestEdition(4), [4,5]],
"Reversed paged results" => [(new Context)->limit(2)->latestEdition(7)->reverse(true), [7,6]],
"With label ID 1" => [(new Context)->label(1), [1,19]],
"With label ID 2" => [(new Context)->label(2), [1,5,20]],
"With label 'Interesting'" => [(new Context)->labelName("Interesting"), [1,19]],
"With label 'Fascinating'" => [(new Context)->labelName("Fascinating"), [1,5,20]],
"Article ID 20" => [(new Context)->article(20), [20]],
"Edition ID 1001" => [(new Context)->edition(1001), [20]],
"Multiple articles" => [(new Context)->articles([1,20,50]), [1,20]],
"Multiple starred articles" => [(new Context)->articles([1,2,3])->starred(true), [1]],
"Multiple unstarred articles" => [(new Context)->articles([1,2,3])->starred(false), [2,3]],
"Multiple articles" => [(new Context)->articles([1,20,50]), [1,20]],
"Multiple editions" => [(new Context)->editions([1,1001,50]), [1,20]],
"150 articles" => [(new Context)->articles(range(1, Database::LIMIT_ARTICLES * 3)), [1,2,3,4,5,6,7,8,19,20]],
"Search title or content 1" => [(new Context)->searchTerms(["Article"]), [1,2,3]],
"Search title or content 2" => [(new Context)->searchTerms(["one", "first"]), [1]],
"Search title or content 3" => [(new Context)->searchTerms(["one first"]), []],
"Search title 1" => [(new Context)->titleTerms(["two"]), [2]],
"Search title 2" => [(new Context)->titleTerms(["title two"]), [2]],
"Search title 3" => [(new Context)->titleTerms(["two", "title"]), [2]],
"Search title 4" => [(new Context)->titleTerms(["two title"]), []],
"Search note 1" => [(new Context)->annotationTerms(["some"]), [2]],
"Search note 2" => [(new Context)->annotationTerms(["some Note"]), [2]],
"Search note 3" => [(new Context)->annotationTerms(["note", "some"]), [2]],
"Search note 4" => [(new Context)->annotationTerms(["some", "sauce"]), []],
"Search author 1" => [(new Context)->authorTerms(["doe"]), [4,5,6,7]],
"Search author 2" => [(new Context)->authorTerms(["jane doe"]), [6,7]],
"Search author 3" => [(new Context)->authorTerms(["doe", "jane"]), [6,7]],
"Search author 4" => [(new Context)->authorTerms(["doe jane"]), []],
];
}
public function testListArticlesOfAMissingFolder() {