diff --git a/tests/cases/Database/SeriesArticle.php b/tests/cases/Database/SeriesArticle.php index efd78e18..4dea4baf 100644 --- a/tests/cases/Database/SeriesArticle.php +++ b/tests/cases/Database/SeriesArticle.php @@ -18,11 +18,7 @@ trait SeriesArticle { protected function setUpSeriesArticle(): void { $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "", 1], ["john.doe@example.com", "", 2], @@ -32,11 +28,7 @@ trait SeriesArticle { ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'title' => "str", - ], + 'columns' => ["id", "url", "title"], 'rows' => [ [1,"http://example.com/1", "Feed 1"], [2,"http://example.com/2", "Feed 2"], @@ -54,12 +46,7 @@ trait SeriesArticle { ], ], 'arsse_folders' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'parent' => "int", - 'name' => "str", - ], + 'columns' => ["id", "owner", "parent", "name"], 'rows' => [ [1, "john.doe@example.com", null, "Technology"], [2, "john.doe@example.com", 1, "Software"], @@ -73,11 +60,7 @@ trait SeriesArticle { ], ], 'arsse_tags' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'name' => "str", - ], + 'columns' => ["id", "owner", "name"], 'rows' => [ [1, "john.doe@example.com", "Technology"], [2, "john.doe@example.com", "Software"], @@ -90,38 +73,27 @@ trait SeriesArticle { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", - 'folder' => "int", - 'title' => "str", - 'scrape' => "bool", - ], + 'columns' => ["id", "owner", "feed", "folder", "title", "scrape"], 'rows' => [ - [1, "john.doe@example.com",1, null,"Subscription 1",0], - [2, "john.doe@example.com",2, null,null,0], - [3, "john.doe@example.com",3, 1,"Subscription 3",0], - [4, "john.doe@example.com",4, 6,null,0], - [5, "john.doe@example.com",10, 5,"Subscription 5",0], - [6, "jane.doe@example.com",1, null,null,0], - [7, "jane.doe@example.com",10,null,"Subscription 7",0], - [8, "john.doe@example.org",11,null,null,0], - [9, "john.doe@example.org",12,null,"Subscription 9",0], - [10,"john.doe@example.org",13,null,null,0], + [1, "john.doe@example.com",1, null,"Subscription 1", 0], + [2, "john.doe@example.com",2, null,null, 0], + [3, "john.doe@example.com",3, 1,"Subscription 3", 0], + [4, "john.doe@example.com",4, 6,null, 0], + [5, "john.doe@example.com",10, 5,"Subscription 5", 0], + [6, "jane.doe@example.com",1, null,null, 0], + [7, "jane.doe@example.com",10,null,"Subscription 7", 0], + [8, "john.doe@example.org",11,null,null, 0], + [9, "john.doe@example.org",12,null,"Subscription 9", 0], + [10,"john.doe@example.org",13,null,null, 0], [11,"john.doe@example.net",10,null,"Subscription 11",0], - [12,"john.doe@example.net",2, 9,null,0], + [12,"john.doe@example.net",2, 9,null, 0], [13,"john.doe@example.net",3, 8,"Subscription 13",0], - [14,"john.doe@example.net",4, 7,null,0], - [15,"jill.doe@example.com",11,null,null,1], + [14,"john.doe@example.net",4, 7,null, 0], + [15,"jill.doe@example.com",11,null,null, 1], ], ], 'arsse_tag_members' => [ - 'columns' => [ - 'tag' => "int", - 'subscription' => "int", - 'assigned' => "bool", - ], + 'columns' => ["tag", "subscription", "assigned"], 'rows' => [ [1,3,1], [1,4,1], @@ -137,20 +109,8 @@ trait SeriesArticle { ], 'arsse_articles' => [ 'columns' => [ - 'id' => "int", - 'feed' => "int", - 'url' => "str", - 'title' => "str", - 'author' => "str", - 'published' => "datetime", - 'edited' => "datetime", - 'content' => "str", - 'guid' => "str", - 'url_title_hash' => "str", - 'url_content_hash' => "str", - 'title_content_hash' => "str", - 'modified' => "datetime", - 'content_scraped' => "str", + "id", "feed", "url", "title", "author", "published", "edited", "content", "guid", + "url_title_hash", "url_content_hash", "title_content_hash", "modified", "content_scraped" ], 'rows' => [ [1,1,null,"Title one", null,null,null,"First article", null,"","","","2000-01-01T00:00:00Z",null], @@ -181,11 +141,7 @@ trait SeriesArticle { ], ], 'arsse_enclosures' => [ - 'columns' => [ - 'article' => "int", - 'url' => "str", - 'type' => "str", - ], + 'columns' => ["article", "url", "type"], 'rows' => [ [102,"http://example.com/text","text/plain"], [103,"http://example.com/video","video/webm"], @@ -195,10 +151,7 @@ trait SeriesArticle { ], ], 'arsse_editions' => [ - 'columns' => [ - 'id' => "int", - 'article' => "int", - ], + 'columns' => ["id", "article"], 'rows' => [ [1,1], [2,2], @@ -234,15 +187,7 @@ trait SeriesArticle { ], ], 'arsse_marks' => [ - 'columns' => [ - 'subscription' => "int", - 'article' => "int", - 'read' => "bool", - 'starred' => "bool", - 'modified' => "datetime", - 'note' => "str", - 'hidden' => "bool", - ], + 'columns' => ["subscription", "article", "read", "starred", "modified", "note", "hidden"], 'rows' => [ [1, 1,1,1,'2000-01-01 00:00:00','',0], [5, 19,1,0,'2016-01-01 00:00:00','',0], @@ -263,10 +208,7 @@ trait SeriesArticle { ], ], 'arsse_categories' => [ // author-supplied categories - 'columns' => [ - 'article' => "int", - 'name' => "str", - ], + 'columns' => ["article", "name"], 'rows' => [ [19,"Fascinating"], [19,"Logical"], @@ -274,12 +216,8 @@ trait SeriesArticle { [20,"Logical"], ], ], - 'arsse_labels' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'name' => "str", - ], + 'arsse_labels' => [ // labels applied to articles + 'columns' => ["id", "owner", "name"], 'rows' => [ [1,"john.doe@example.com","Interesting"], [2,"john.doe@example.com","Fascinating"], @@ -288,13 +226,7 @@ trait SeriesArticle { ], ], 'arsse_label_members' => [ - 'columns' => [ - 'label' => "int", - 'article' => "int", - 'subscription' => "int", - 'assigned' => "bool", - 'modified' => "datetime", - ], + 'columns' => ["label", "article", "subscription", "assigned", "modified"], 'rows' => [ [1, 1,1,1,'2000-01-01 00:00:00'], [2, 1,1,1,'2000-01-01 00:00:00'], diff --git a/tests/cases/Database/SeriesCleanup.php b/tests/cases/Database/SeriesCleanup.php index d863a644..8850ecd2 100644 --- a/tests/cases/Database/SeriesCleanup.php +++ b/tests/cases/Database/SeriesCleanup.php @@ -27,23 +27,14 @@ trait SeriesCleanup { $faroff = (new Date("now + 1 hour", $tz))->format("Y-m-d H:i:s"); $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "",1], ["john.doe@example.com", "",2], ], ], 'arsse_sessions' => [ - 'columns' => [ - 'id' => "str", - 'created' => "datetime", - 'expires' => "datetime", - 'user' => "str", - ], + 'columns' => ["id", "created", "expires", "user"], 'rows' => [ ["a", $nowish, $faroff, "jane.doe@example.com"], // not expired and recently created, thus kept ["b", $nowish, $soon, "jane.doe@example.com"], // not expired and recently created, thus kept @@ -53,12 +44,7 @@ trait SeriesCleanup { ], ], 'arsse_tokens' => [ - 'columns' => [ - 'id' => "str", - 'class' => "str", - 'user' => "str", - 'expires' => "datetime", - ], + 'columns' => ["id", "class", "user", "expires"], 'rows' => [ ["80fa94c1a11f11e78667001e673b2560", "fever.login", "jane.doe@example.com", $faroff], ["27c6de8da13311e78667001e673b2560", "fever.login", "jane.doe@example.com", $weeksago], // expired @@ -67,11 +53,7 @@ trait SeriesCleanup { ], ], 'arsse_icons' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'orphaned' => "datetime", - ], + 'columns' => ["id", "url", "orphaned"], 'rows' => [ [1,'http://localhost:8000/Icon/PNG',$daybefore], [2,'http://localhost:8000/Icon/GIF',$daybefore], @@ -79,14 +61,7 @@ trait SeriesCleanup { ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'title' => "str", - 'orphaned' => "datetime", - 'size' => "int", - 'icon' => "int", - ], + 'columns' => ["id", "url", "title", "orphaned", "size", "icon"], 'rows' => [ [1,"http://example.com/1","",$daybefore,2,null], //latest two articles should be kept [2,"http://example.com/2","",$yesterday,0,2], @@ -95,11 +70,7 @@ trait SeriesCleanup { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", - ], + 'columns' => ["id", "owner", "feed"], 'rows' => [ // one feed previously marked for deletion has a subscription again, and so should not be deleted [1,'jane.doe@example.com',1], @@ -108,14 +79,7 @@ trait SeriesCleanup { ], ], 'arsse_articles' => [ - 'columns' => [ - 'id' => "int", - 'feed' => "int", - 'url_title_hash' => "str", - 'url_content_hash' => "str", - 'title_content_hash' => "str", - 'modified' => "datetime", - ], + 'columns' => ["id", "feed", "url_title_hash", "url_content_hash", "title_content_hash", "modified"], 'rows' => [ [1,1,"","","",$weeksago], // is the latest article, thus is kept [2,1,"","","",$weeksago], // is the second latest article, thus is kept @@ -129,10 +93,7 @@ trait SeriesCleanup { ], ], 'arsse_editions' => [ - 'columns' => [ - 'id' => "int", - 'article' => "int", - ], + 'columns' => ["id", "article"], 'rows' => [ [1,1], [2,2], @@ -143,14 +104,7 @@ trait SeriesCleanup { ], ], 'arsse_marks' => [ - 'columns' => [ - 'article' => "int", - 'subscription' => "int", - 'read' => "bool", - 'starred' => "bool", - 'hidden' => "bool", - 'modified' => "datetime", - ], + 'columns' => ["article", "subscription", "read", "starred", "hidden", "modified"], 'rows' => [ [3,1,0,1,0,$weeksago], [4,1,1,0,0,$daysago], diff --git a/tests/cases/Database/SeriesFeed.php b/tests/cases/Database/SeriesFeed.php index 5cc0d84c..67fb77a6 100644 --- a/tests/cases/Database/SeriesFeed.php +++ b/tests/cases/Database/SeriesFeed.php @@ -17,23 +17,14 @@ trait SeriesFeed { $now = gmdate("Y-m-d H:i:s", strtotime("now")); $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "",1], ["john.doe@example.com", "",2], ], ], 'arsse_icons' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'type' => "str", - 'data' => "blob", - ], + 'columns' => ["id", "url", "type", "data"], 'rows' => [ [1,'http://localhost:8000/Icon/PNG','image/png',base64_decode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMjHxIGmVAAAADUlEQVQYV2NgYGBgAAAABQABijPjAAAAAABJRU5ErkJggg==")], [2,'http://localhost:8000/Icon/GIF','image/gif',base64_decode("R0lGODlhAQABAIABAAAAAP///yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==")], @@ -42,17 +33,7 @@ trait SeriesFeed { ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'title' => "str", - 'err_count' => "int", - 'err_msg' => "str", - 'modified' => "datetime", - 'next_fetch' => "datetime", - 'size' => "int", - 'icon' => "int", - ], + 'columns' => ["id", "url", "title", "err_count", "err_msg", "modified", "next_fetch", "size", "icon"], 'rows' => [ [1,"http://localhost:8000/Feed/Matching/3","Ook",0,"",$past,$past,0,null], [2,"http://localhost:8000/Feed/Matching/1","Eek",5,"There was an error last time",$past,$future,0,null], @@ -67,13 +48,7 @@ trait SeriesFeed { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", - 'keep_rule' => "str", - 'block_rule' => "str", - ], + 'columns' => ["id", "owner", "feed", "keep_rule", "block_rule"], 'rows' => [ [1,'john.doe@example.com',1,null,'^Sport$'], [2,'john.doe@example.com',2,"",null], @@ -84,21 +59,7 @@ trait SeriesFeed { ], ], 'arsse_articles' => [ - 'columns' => [ - 'id' => "int", - 'feed' => "int", - 'url' => "str", - 'title' => "str", - 'author' => "str", - 'published' => "datetime", - 'edited' => "datetime", - 'content' => "str", - 'guid' => "str", - 'url_title_hash' => "str", - 'url_content_hash' => "str", - 'title_content_hash' => "str", - 'modified' => "datetime", - ], + 'columns' => ["id", "feed", "url", "title", "author", "published", "edited", "content", "guid", "url_title_hash", "url_content_hash", "title_content_hash", "modified"], 'rows' => [ [1,1,'http://example.com/1','Article title 1','','2000-01-01 00:00:00','2000-01-01 00:00:00','

Article content 1

','e433653cef2e572eee4215fa299a4a5af9137b2cefd6283c85bd69a32915beda','f5cb8bfc1c7396dc9816af212a3e2ac5221585c2a00bf7ccb6aabd95dcfcd6a6','fb0bc8f8cb08913dc5a497db700e327f1d34e4987402687d494a5891f24714d4','18fdd4fa93d693128c43b004399e5c9cea6c261ddfa002518d3669f55d8c2207',$past], [2,1,'http://example.com/2','Article title 2','','2000-01-02 00:00:00','2000-01-02 00:00:00','

Article content 2

','5be8a5a46ecd52ed132191c8d27fb1af6b3d4edc00234c5d9f8f0e10562ed3b7','0e86d2de822a174fe3c44a466953e63ca1f1a58a19cbf475fce0855d4e3d5153','13075894189c47ffcfafd1dfe7fbb539f7c74a69d35a399b3abf8518952714f9','2abd0a8cba83b8214a66c8f0293ba63e467d720540e29ff8ddcdab069d4f1c9e',$past], @@ -110,11 +71,7 @@ trait SeriesFeed { ], ], 'arsse_editions' => [ - 'columns' => [ - 'id' => "int", - 'article' => "int", - 'modified' => "datetime", - ], + 'columns' => ["id", "article", "modified"], 'rows' => [ [1,1,$past], [2,2,$past], @@ -124,14 +81,7 @@ trait SeriesFeed { ], ], 'arsse_marks' => [ - 'columns' => [ - 'article' => "int", - 'subscription' => "int", - 'read' => "bool", - 'starred' => "bool", - 'hidden' => "bool", - 'modified' => "datetime", - ], + 'columns' => ["article", "subscription", "read", "starred", "hidden", "modified"], 'rows' => [ // Jane's marks [1,6,1,0,0,$past], @@ -146,20 +96,13 @@ trait SeriesFeed { ], ], 'arsse_enclosures' => [ - 'columns' => [ - 'article' => "int", - 'url' => "str", - 'type' => "str", - ], + 'columns' => ["article", "url", "type"], 'rows' => [ [7,'http://example.com/png','image/png'], ], ], 'arsse_categories' => [ - 'columns' => [ - 'article' => "int", - 'name' => "str", - ], + 'columns' => ["article", "name"], 'rows' => [ [7,'Syrinx'], ], diff --git a/tests/cases/Database/SeriesFolder.php b/tests/cases/Database/SeriesFolder.php index 4c488ced..4e0eec4b 100644 --- a/tests/cases/Database/SeriesFolder.php +++ b/tests/cases/Database/SeriesFolder.php @@ -12,23 +12,14 @@ trait SeriesFolder { protected function setUpSeriesFolder(): void { $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "",1], ["john.doe@example.com", "",2], ], ], 'arsse_folders' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'parent' => "int", - 'name' => "str", - ], + 'columns' => ["id", "owner", "parent", "name"], /* Layout translates to: Jane Politics @@ -49,11 +40,7 @@ trait SeriesFolder { ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'title' => "str", - ], + 'columns' => ["id", "url", "title"], 'rows' => [ [1,"http://example.com/1", "Feed 1"], [2,"http://example.com/2", "Feed 2"], @@ -71,12 +58,7 @@ trait SeriesFolder { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", - 'folder' => "int", - ], + 'columns' => ["id", "owner", "feed", "folder"], 'rows' => [ [1, "john.doe@example.com",1, null], [2, "john.doe@example.com",2, null], diff --git a/tests/cases/Database/SeriesIcon.php b/tests/cases/Database/SeriesIcon.php index 667651f2..73b6cf4e 100644 --- a/tests/cases/Database/SeriesIcon.php +++ b/tests/cases/Database/SeriesIcon.php @@ -16,23 +16,14 @@ trait SeriesIcon { $now = gmdate("Y-m-d H:i:s", strtotime("now")); $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "",1], ["john.doe@example.com", "",2], ], ], 'arsse_icons' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'type' => "str", - 'data' => "blob", - ], + 'columns' => ["id", "url", "type", "data"], 'rows' => [ [1,'http://localhost:8000/Icon/PNG','image/png',base64_decode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMjHxIGmVAAAADUlEQVQYV2NgYGBgAAAABQABijPjAAAAAABJRU5ErkJggg==")], [2,'http://localhost:8000/Icon/GIF','image/gif',base64_decode("R0lGODlhAQABAIABAAAAAP///yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==")], @@ -41,17 +32,7 @@ trait SeriesIcon { ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'title' => "str", - 'err_count' => "int", - 'err_msg' => "str", - 'modified' => "datetime", - 'next_fetch' => "datetime", - 'size' => "int", - 'icon' => "int", - ], + 'columns' => ["id", "url", "title", "err_count", "err_msg", "modified", "next_fetch", "size", "icon"], 'rows' => [ [1,"http://localhost:8000/Feed/Matching/3","Ook",0,"",$past,$past,0,1], [2,"http://localhost:8000/Feed/Matching/1","Eek",5,"There was an error last time",$past,$future,0,2], @@ -61,11 +42,7 @@ trait SeriesIcon { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", - ], + 'columns' => ["id", "owner", "feed"], 'rows' => [ [1,'john.doe@example.com',1], [2,'john.doe@example.com',2], diff --git a/tests/cases/Database/SeriesLabel.php b/tests/cases/Database/SeriesLabel.php index 4a4fac66..d4ffa721 100644 --- a/tests/cases/Database/SeriesLabel.php +++ b/tests/cases/Database/SeriesLabel.php @@ -14,11 +14,7 @@ trait SeriesLabel { protected function setUpSeriesLabel(): void { $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "",1], ["john.doe@example.com", "",2], @@ -27,12 +23,7 @@ trait SeriesLabel { ], ], 'arsse_folders' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'parent' => "int", - 'name' => "str", - ], + 'columns' => ["id", "owner", "parent", "name"], 'rows' => [ [1, "john.doe@example.com", null, "Technology"], [2, "john.doe@example.com", 1, "Software"], @@ -46,10 +37,7 @@ trait SeriesLabel { ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - ], + 'columns' => ["id", "url"], 'rows' => [ [1,"http://example.com/1"], [2,"http://example.com/2"], @@ -67,12 +55,7 @@ trait SeriesLabel { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", - 'folder' => "int", - ], + 'columns' => ["id", "owner", "feed", "folder"], 'rows' => [ [1,"john.doe@example.com",1,null], [2,"john.doe@example.com",2,null], @@ -91,21 +74,7 @@ trait SeriesLabel { ], ], 'arsse_articles' => [ - 'columns' => [ - 'id' => "int", - 'feed' => "int", - 'url' => "str", - 'title' => "str", - 'author' => "str", - 'published' => "datetime", - 'edited' => "datetime", - 'content' => "str", - 'guid' => "str", - 'url_title_hash' => "str", - 'url_content_hash' => "str", - 'title_content_hash' => "str", - 'modified' => "datetime", - ], + 'columns' => ["id", "feed", "url", "title", "author", "published", "edited", "content", "guid", "url_title_hash", "url_content_hash", "title_content_hash", "modified"], 'rows' => [ [1,1,null,null,null,null,null,null,null,"","","","2000-01-01T00:00:00Z"], [2,1,null,null,null,null,null,null,null,"","","","2010-01-01T00:00:00Z"], @@ -135,11 +104,7 @@ trait SeriesLabel { ], ], 'arsse_enclosures' => [ - 'columns' => [ - 'article' => "int", - 'url' => "str", - 'type' => "str", - ], + 'columns' => ["article", "url", "type"], 'rows' => [ [102,"http://example.com/text","text/plain"], [103,"http://example.com/video","video/webm"], @@ -149,10 +114,7 @@ trait SeriesLabel { ], ], 'arsse_editions' => [ - 'columns' => [ - 'id' => "int", - 'article' => "int", - ], + 'columns' => ["id", "article"], 'rows' => [ [1,1], [2,2], @@ -188,14 +150,7 @@ trait SeriesLabel { ], ], 'arsse_marks' => [ - 'columns' => [ - 'subscription' => "int", - 'article' => "int", - 'read' => "bool", - 'starred' => "bool", - 'modified' => "datetime", - 'hidden' => "bool", - ], + 'columns' => ["subscription", "article", "read", "starred", "modified", "hidden"], 'rows' => [ [1, 1,1,1,'2000-01-01 00:00:00',0], [5, 19,1,0,'2000-01-01 00:00:00',0], @@ -213,11 +168,7 @@ trait SeriesLabel { ], ], 'arsse_labels' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'name' => "str", - ], + 'columns' => ["id", "owner", "name"], 'rows' => [ [1,"john.doe@example.com","Interesting"], [2,"john.doe@example.com","Fascinating"], @@ -226,12 +177,7 @@ trait SeriesLabel { ], ], 'arsse_label_members' => [ - 'columns' => [ - 'label' => "int", - 'article' => "int", - 'subscription' => "int", - 'assigned' => "bool", - ], + 'columns' => ["label", "article", "subscription", "assigned"], 'rows' => [ [1, 1,1,1], [2, 1,1,1], diff --git a/tests/cases/Database/SeriesMeta.php b/tests/cases/Database/SeriesMeta.php index b1d19743..aeac6b79 100644 --- a/tests/cases/Database/SeriesMeta.php +++ b/tests/cases/Database/SeriesMeta.php @@ -13,13 +13,10 @@ trait SeriesMeta { protected function setUpSeriesMeta(): void { $dataBare = [ 'arsse_meta' => [ - 'columns' => [ - 'key' => 'str', - 'value' => 'str', - ], + 'columns' => ["key", "value"], 'rows' => [ - //['schema_version', "".\JKingWeb\Arsse\Database::SCHEMA_VERSION], - ['album',"A Farewell to Kings"], + //['schema_version', "".\JKingWeb\Arsse\Database::SCHEMA_VERSION], + ['album',"A Farewell to Kings"], ], ], ]; diff --git a/tests/cases/Database/SeriesSession.php b/tests/cases/Database/SeriesSession.php index 1db319f8..ffbba56e 100644 --- a/tests/cases/Database/SeriesSession.php +++ b/tests/cases/Database/SeriesSession.php @@ -23,23 +23,14 @@ trait SeriesSession { $old = gmdate("Y-m-d H:i:s", strtotime("now - 2 days")); $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "",1], ["john.doe@example.com", "",2], ], ], 'arsse_sessions' => [ - 'columns' => [ - 'id' => "str", - 'user' => "str", - 'created' => "datetime", - 'expires' => "datetime", - ], + 'columns' => ["id", "user", "created", "expires"], 'rows' => [ ["80fa94c1a11f11e78667001e673b2560", "jane.doe@example.com", $past, $faroff], ["27c6de8da13311e78667001e673b2560", "jane.doe@example.com", $past, $past], // expired diff --git a/tests/cases/Database/SeriesSubscription.php b/tests/cases/Database/SeriesSubscription.php index 0b5f6512..0b279702 100644 --- a/tests/cases/Database/SeriesSubscription.php +++ b/tests/cases/Database/SeriesSubscription.php @@ -15,11 +15,7 @@ trait SeriesSubscription { public function setUpSeriesSubscription(): void { $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "", 1], ["john.doe@example.com", "", 2], @@ -28,12 +24,7 @@ trait SeriesSubscription { ], ], 'arsse_folders' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'parent' => "int", - 'name' => "str", - ], + 'columns' => ["id", "owner", "parent", "name"], 'rows' => [ [1, "john.doe@example.com", null, "Technology"], [2, "john.doe@example.com", 1, "Software"], @@ -44,27 +35,14 @@ trait SeriesSubscription { ], ], 'arsse_icons' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'data' => "blob", - ], + 'columns' => ["id", "url", "data"], 'rows' => [ [1,"http://example.com/favicon.ico", "ICON DATA"], [2,"http://example.net/favicon.ico", null], ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'title' => "str", - 'username' => "str", - 'password' => "str", - 'updated' => "datetime", - 'next_fetch' => "datetime", - 'icon' => "int", - ], + 'columns' => ["id", "url", "title", "username", "password", "updated", "next_fetch", "icon"], 'rows' => [ [1,"http://example.com/feed1", "Ook", "", "",strtotime("now"),strtotime("now"),null], [2,"http://example.com/feed2", "eek", "", "",strtotime("now - 1 hour"),strtotime("now - 1 hour"),1], @@ -73,18 +51,7 @@ trait SeriesSubscription { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", - 'title' => "str", - 'folder' => "int", - 'pinned' => "bool", - 'order_type' => "int", - 'keep_rule' => "str", - 'block_rule' => "str", - 'scrape' => "bool", - ], + 'columns' => ["id", "owner", "feed", "title", "folder", "pinned", "order_type", "keep_rule", "block_rule", "scrape"], 'rows' => [ [1,"john.doe@example.com",2,null,null,1,2,null,null,0], [2,"jane.doe@example.com",2,null,null,0,0,null,null,0], @@ -95,11 +62,7 @@ trait SeriesSubscription { ], ], 'arsse_tags' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'name' => "str", - ], + 'columns' => ["id", "owner", "name"], 'rows' => [ [1,"john.doe@example.com","Interesting"], [2,"john.doe@example.com","Fascinating"], @@ -108,11 +71,7 @@ trait SeriesSubscription { ], ], 'arsse_tag_members' => [ - 'columns' => [ - 'tag' => "int", - 'subscription' => "int", - 'assigned' => "bool", - ], + 'columns' => ["tag", "subscription", "assigned"], 'rows' => [ [1,1,1], [1,3,0], @@ -122,14 +81,7 @@ trait SeriesSubscription { ], ], 'arsse_articles' => [ - 'columns' => [ - 'id' => "int", - 'feed' => "int", - 'url_title_hash' => "str", - 'url_content_hash' => "str", - 'title_content_hash' => "str", - 'title' => "str", - ], + 'columns' => ["id", "feed", "url_title_hash", "url_content_hash", "title_content_hash", "title"], 'rows' => [ [1,2,"","","","Title 1"], [2,2,"","","","Title 2"], @@ -142,10 +94,7 @@ trait SeriesSubscription { ], ], 'arsse_editions' => [ - 'columns' => [ - 'id' => "int", - 'article' => "int", - ], + 'columns' => ["id", "article"], 'rows' => [ [1,1], [2,2], @@ -158,10 +107,7 @@ trait SeriesSubscription { ], ], 'arsse_categories' => [ - 'columns' => [ - 'article' => "int", - 'name' => "str", - ], + 'columns' => ["article", "name"], 'rows' => [ [1,"A"], [2,"B"], @@ -173,13 +119,7 @@ trait SeriesSubscription { ], ], 'arsse_marks' => [ - 'columns' => [ - 'article' => "int", - 'subscription' => "int", - 'read' => "bool", - 'starred' => "bool", - 'hidden' => "bool", - ], + 'columns' => ["article", "subscription", "read", "starred", "hidden"], 'rows' => [ [1,2,1,0,0], [2,2,1,0,0], diff --git a/tests/cases/Database/SeriesTag.php b/tests/cases/Database/SeriesTag.php index 1f2ea9cd..47c9fa7c 100644 --- a/tests/cases/Database/SeriesTag.php +++ b/tests/cases/Database/SeriesTag.php @@ -13,11 +13,7 @@ trait SeriesTag { protected function setUpSeriesTag(): void { $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "",1], ["john.doe@example.com", "",2], @@ -26,11 +22,7 @@ trait SeriesTag { ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'title' => "str", - ], + 'columns' => ["id", "url", "title"], 'rows' => [ [1,"http://example.com/1",""], [2,"http://example.com/2",""], @@ -48,12 +40,7 @@ trait SeriesTag { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'feed' => "int", - 'title' => "str", - ], + 'columns' => ["id", "owner", "feed", "title"], 'rows' => [ [1, "john.doe@example.com", 1,"Lord of Carrots"], [2, "john.doe@example.com", 2,null], @@ -72,11 +59,7 @@ trait SeriesTag { ], ], 'arsse_tags' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'name' => "str", - ], + 'columns' => ["id", "owner", "name"], 'rows' => [ [1,"john.doe@example.com","Interesting"], [2,"john.doe@example.com","Fascinating"], @@ -85,11 +68,7 @@ trait SeriesTag { ], ], 'arsse_tag_members' => [ - 'columns' => [ - 'tag' => "int", - 'subscription' => "int", - 'assigned' => "bool", - ], + 'columns' => ["tag", "subscription", "assigned"], 'rows' => [ [1,1,1], [1,3,0], diff --git a/tests/cases/Database/SeriesToken.php b/tests/cases/Database/SeriesToken.php index 7a14ed0d..ab90244e 100644 --- a/tests/cases/Database/SeriesToken.php +++ b/tests/cases/Database/SeriesToken.php @@ -17,24 +17,14 @@ trait SeriesToken { $old = gmdate("Y-m-d H:i:s", strtotime("now - 2 days")); $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["jane.doe@example.com", "",1], ["john.doe@example.com", "",2], ], ], 'arsse_tokens' => [ - 'columns' => [ - 'id' => "str", - 'class' => "str", - 'user' => "str", - 'expires' => "datetime", - 'data' => "str", - ], + 'columns' => ["id", "class", "user", "expires", "data"], 'rows' => [ ["80fa94c1a11f11e78667001e673b2560", "fever.login", "jane.doe@example.com", $faroff, null], ["27c6de8da13311e78667001e673b2560", "fever.login", "jane.doe@example.com", $past, null], // expired diff --git a/tests/cases/Database/SeriesUser.php b/tests/cases/Database/SeriesUser.php index 031e5161..2caba860 100644 --- a/tests/cases/Database/SeriesUser.php +++ b/tests/cases/Database/SeriesUser.php @@ -12,12 +12,7 @@ trait SeriesUser { protected function setUpSeriesUser(): void { $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - 'admin' => 'bool', - ], + 'columns' => ["id", "password", "num", "admin"], 'rows' => [ ["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW', 1, 1], // password is hash of "secret" ["jane.doe@example.com", "", 2, 0], @@ -25,11 +20,7 @@ trait SeriesUser { ], ], 'arsse_user_meta' => [ - 'columns' => [ - 'owner' => "str", - 'key' => "str", - 'value' => "str", - ], + 'columns' => ["owner", "key", "value"], 'rows' => [ ["admin@example.net", "lang", "en"], ["admin@example.net", "tz", "America/Toronto"], diff --git a/tests/cases/ImportExport/TestImportExport.php b/tests/cases/ImportExport/TestImportExport.php index ae0c7a4a..a6d6194b 100644 --- a/tests/cases/ImportExport/TestImportExport.php +++ b/tests/cases/ImportExport/TestImportExport.php @@ -41,23 +41,14 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { Arsse::$db->driverSchemaUpdate(); $this->data = [ 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'num' => 'int', - ], + 'columns' => ["id", "password", "num"], 'rows' => [ ["john.doe@example.com", "", 1], ["jane.doe@example.com", "", 2], ], ], 'arsse_folders' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'parent' => "int", - 'name' => "str", - ], + 'columns' => ["id", "owner", "parent", "name"], 'rows' => [ [1, "john.doe@example.com", null, "Science"], [2, "john.doe@example.com", 1, "Rocketry"], @@ -68,11 +59,7 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { ], ], 'arsse_feeds' => [ - 'columns' => [ - 'id' => "int", - 'url' => "str", - 'title' => "str", - ], + 'columns' => ["id", "url", "title"], 'rows' => [ [1, "http://localhost:8000/Import/nasa-jpl", "NASA JPL"], [2, "http://localhost:8000/Import/torstar", "Toronto Star"], @@ -83,13 +70,7 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { ], ], 'arsse_subscriptions' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'folder' => "int", - 'feed' => "int", - 'title' => "str", - ], + 'columns' => ["id", "owner", "folder", "feed", "title"], 'rows' => [ [1, "john.doe@example.com", 2, 1, "NASA JPL"], [2, "john.doe@example.com", 5, 2, "Toronto Star"], @@ -100,11 +81,7 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { ], ], 'arsse_tags' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'name' => "str", - ], + 'columns' => ["id", "owner", "name"], 'rows' => [ [1, "john.doe@example.com", "canada"], [2, "john.doe@example.com", "frequent"], @@ -115,11 +92,7 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { ], ], 'arsse_tag_members' => [ - 'columns' => [ - 'tag' => "int", - 'subscription' => "int", - 'assigned' => "bool", - ], + 'columns' => ["tag", "subscription", "assigned"], 'rows' => [ [1, 2, 1], [1, 4, 1], diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index f498a543..5d7776ea 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -387,14 +387,33 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { return $value; } + /** Inserts into the database test data in the following format: + * + * ```php + * $data = [ + * 'some_table' => [ + * 'columns' => ["id", "name"], + * 'rows' => [ + * [1,"Dupond"], + * [2,"Dupont"], + * ] + * ], + * 'other_table' => [ + * ... + * ] + * ]; + * ``` + */ public function primeDatabase(Driver $drv, array $data): bool { $tr = $drv->begin(); foreach ($data as $table => $info) { $cols = array_map(function($v) { return '"'.str_replace('"', '""', $v).'"'; - }, array_keys($info['columns'])); + }, $info['columns']); $cols = implode(",", $cols); - $bindings = array_values($info['columns']); + $bindings = array_map(function($c) use ($table) { + return self::COL_DEFS[$table][$c]; + }, $info['columns']); $params = implode(",", array_fill(0, sizeof($info['columns']), "?")); $s = $drv->prepareArray("INSERT INTO $table($cols) values($params)", $bindings); foreach ($info['rows'] as $row) { @@ -433,16 +452,15 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { // serialize the rows of the actual output $cols = implode(",", array_map(function($v) { return '"'.str_replace('"', '""', $v).'"'; - }, array_keys($info['columns']))); + }, $info['columns'])); $data = $drv->prepare("SELECT $cols from $table")->run()->getAll(); - $types = $info['columns']; $act = []; $extra = []; foreach ($data as $r) { $row = []; foreach ($r as $c => $v) { // account for dates which might be off by one second - if ($types[$c] === "datetime") { + if (self::COL_DEFS[$table][$c] === "datetime") { if (array_search($v, $dates, true) === false) { $v = Date::transform(Date::sub("PT1S", $v), "sql"); if (array_search($v, $dates, true) === false) { @@ -490,23 +508,22 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { $out = []; foreach ($tableSpecs as $table => $columns) { // make sure the source has the table we want - $this->assertArrayHasKey($table, $source, "Source for expectations does not contain requested table $table."); + if (!isset($source[$table])) { + throw new Exception("Source for expectations does not contain requested table $table."); + } + // fill the output, particularly the correct number of (empty) rows + $rows = sizeof($source[$table]['rows']); $out[$table] = [ - 'columns' => [], - 'rows' => array_fill(0, sizeof($source[$table]['rows']), []), + 'columns' => $columns, + 'rows' => array_fill(0, $rows, []), ]; - // make sure the source has all the columns we want for the table - $cols = array_flip($columns); - $cols = array_intersect_key($cols, $source[$table]['columns']); - $this->assertSame(array_keys($cols), $columns, "Source for table $table does not contain all requested columns"); - // get a map of source value offsets and keys - $targets = array_flip(array_keys($source[$table]['columns'])); - foreach ($cols as $key => $order) { - // fill the column-spec - $out[$table]['columns'][$key] = $source[$table]['columns'][$key]; - foreach ($source[$table]['rows'] as $index => $row) { - // fill each row column-wise with re-ordered values - $out[$table]['rows'][$index][$order] = $row[$targets[$key]]; + // fill the rows with the requested data, column-wise + foreach ($columns as $c) { + if (($index = array_search($c, $source[$table]['columns'], true)) === false) { + throw new exception("Expected column $table.$c is not present in test data"); + } + for ($a = 0; $a < $rows; $a++) { + $out[$table]['rows'][$a][] = $source[$table]['rows'][$a][$index]; } } }