Browse Source

Fix up the simpler database functions

redup
J. King 2 years ago
parent
commit
b24a76b744
  1. 12
      lib/Database.php
  2. 10
      tests/cases/Database/AbstractTest.php
  3. 42
      tests/cases/Database/SeriesFolder.php
  4. 27
      tests/cases/Database/SeriesIcon.php
  5. 56
      tests/cases/Database/SeriesTag.php
  6. 2
      tests/phpunit.dist.xml

12
lib/Database.php

@ -81,10 +81,12 @@ class Database {
public function checkSchemaVersion(bool $initialize = false): void {
$ver = $this->db->schemaVersion();
if ($initialize && $ver < self::SCHEMA_VERSION) {
$this->db->schemaUpdate(self::SCHEMA_VERSION);
} elseif ($ver != self::SCHEMA_VERSION) {
throw new Db\Exception("updateSchemaChange");
if ($initialize) {
if ($ver < self::SCHEMA_VERSION) {
$this->db->schemaUpdate(self::SCHEMA_VERSION);
} elseif ($ver != self::SCHEMA_VERSION) {
throw new Db\Exception("updateSchemaChange");
}
}
}
@ -1459,7 +1461,7 @@ class Database {
* @param string $user The user whose subscription icons are to be retrieved
*/
public function iconList(string $user): Db\Result {
return $this->db->prepare("SELECT distinct i.id, i.url, i.type, i.data from arsse_icons as i join arsse_feeds as f on i.id = f.icon join arsse_subscriptions as s on s.feed = f.id where s.owner = ?", "str")->run($user);
return $this->db->prepare("SELECT distinct i.id, i.url, i.type, i.data from arsse_icons as i join arsse_subscriptions as s on s.icon = i.id where s.owner = ?", "str")->run($user);
}
/** Deletes orphaned icons from the database

10
tests/cases/Database/AbstractTest.php

@ -17,13 +17,13 @@ abstract class AbstractTest extends \JKingWeb\Arsse\Test\AbstractTest {
use SeriesSession;
use SeriesToken;
use SeriesFolder;
use SeriesFeed;
//use SeriesFeed;
use SeriesIcon;
use SeriesSubscription;
use SeriesLabel;
//use SeriesSubscription;
//use SeriesLabel;
use SeriesTag;
use SeriesArticle;
use SeriesCleanup;
//use SeriesArticle;
//use SeriesCleanup;
/** @var \JKingWeb\Arsse\Db\Driver */
protected static $drv;

42
tests/cases/Database/SeriesFolder.php

@ -39,38 +39,20 @@ trait SeriesFolder {
[6, "john.doe@example.com", 2, "Politics"],
],
],
'arsse_feeds' => [
'columns' => ["id", "url", "title"],
'rows' => [
[1,"http://example.com/1", "Feed 1"],
[2,"http://example.com/2", "Feed 2"],
[3,"http://example.com/3", "Feed 3"],
[4,"http://example.com/4", "Feed 4"],
[5,"http://example.com/5", "Feed 5"],
[6,"http://example.com/6", "Feed 6"],
[7,"http://example.com/7", "Feed 7"],
[8,"http://example.com/8", "Feed 8"],
[9,"http://example.com/9", "Feed 9"],
[10,"http://example.com/10", "Feed 10"],
[11,"http://example.com/11", "Feed 11"],
[12,"http://example.com/12", "Feed 12"],
[13,"http://example.com/13", "Feed 13"],
],
],
'arsse_subscriptions' => [
'columns' => ["id", "owner", "feed", "folder"],
'columns' => ["id", "owner", "url", "title", "folder"],
'rows' => [
[1, "john.doe@example.com",1, null],
[2, "john.doe@example.com",2, null],
[3, "john.doe@example.com",3, 1],
[4, "john.doe@example.com",4, 6],
[5, "john.doe@example.com",5, 5],
[6, "john.doe@example.com",10, 5],
[7, "jane.doe@example.com",1, null],
[8, "jane.doe@example.com",10,null],
[9, "jane.doe@example.com",2, 4],
[10,"jane.doe@example.com",3, 4],
[11,"jane.doe@example.com",4, 4],
[1, "john.doe@example.com","http://example.com/1", "Feed 1", null],
[2, "john.doe@example.com","http://example.com/2", "Feed 2", null],
[3, "john.doe@example.com","http://example.com/3", "Feed 3", 1],
[4, "john.doe@example.com","http://example.com/4", "Feed 4", 6],
[5, "john.doe@example.com","http://example.com/5", "Feed 5", 5],
[6, "john.doe@example.com","http://example.com/10", "Feed 10", 5],
[7, "jane.doe@example.com","http://example.com/1", "Feed 1", null],
[8, "jane.doe@example.com","http://example.com/10", "Feed 10",null],
[9, "jane.doe@example.com","http://example.com/2", "Feed 2", 4],
[10,"jane.doe@example.com","http://example.com/3", "Feed 3", 4],
[11,"jane.doe@example.com","http://example.com/4", "Feed 4", 4],
],
],
];

27
tests/cases/Database/SeriesIcon.php

@ -11,9 +11,6 @@ use JKingWeb\Arsse\Arsse;
trait SeriesIcon {
protected function setUpSeriesIcon(): void {
// set up the test data
$past = gmdate("Y-m-d H:i:s", strtotime("now - 1 minute"));
$future = gmdate("Y-m-d H:i:s", strtotime("now + 1 minute"));
$now = gmdate("Y-m-d H:i:s", strtotime("now"));
$this->data = [
'arsse_users' => [
'columns' => ["id", "password", "num"],
@ -31,25 +28,15 @@ trait SeriesIcon {
[4,'http://localhost:8000/Icon/SVG2','image/svg+xml','<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect width="900" height="600" fill="#ED2939"/><rect width="600" height="600" fill="#fff"/><rect width="300" height="600" fill="#002395"/></svg>'],
],
],
'arsse_feeds' => [
'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],
[3,"http://localhost:8000/Feed/Fetching/Error?code=404","Ack",0,"",$past,$now,0,3],
[4,"http://localhost:8000/Feed/NextFetch/NotModified?t=".time(),"Ooook",0,"",$past,$past,0,null],
[5,"http://localhost:8000/Feed/Parsing/Valid","Ooook",0,"",$past,$future,0,2],
],
],
'arsse_subscriptions' => [
'columns' => ["id", "owner", "feed"],
'columns' => ["id", "owner", "url", "title", "icon"],
'rows' => [
[1,'john.doe@example.com',1],
[2,'john.doe@example.com',2],
[3,'john.doe@example.com',3],
[4,'john.doe@example.com',4],
[5,'john.doe@example.com',5],
[6,'jane.doe@example.com',5],
[1,'john.doe@example.com',"http://localhost:8000/Feed/Matching/3", "Ook", 1],
[2,'john.doe@example.com',"http://localhost:8000/Feed/Matching/1", "Eek", 2],
[3,'john.doe@example.com',"http://localhost:8000/Feed/Fetching/Error?code=404", "Ack", 3],
[4,'john.doe@example.com',"http://localhost:8000/Feed/NextFetch/NotModified?t=".time(), "Ooook", null],
[5,'john.doe@example.com',"http://localhost:8000/Feed/Parsing/Valid", "Ooook", 2],
[6,'jane.doe@example.com',"http://localhost:8000/Feed/Parsing/Valid", "Ooook", 2],
],
],
];

56
tests/cases/Database/SeriesTag.php

@ -15,47 +15,29 @@ trait SeriesTag {
'arsse_users' => [
'columns' => ["id", "password", "num"],
'rows' => [
["jane.doe@example.com", "",1],
["john.doe@example.com", "",2],
["john.doe@example.org", "",3],
["john.doe@example.net", "",4],
],
],
'arsse_feeds' => [
'columns' => ["id", "url", "title"],
'rows' => [
[1,"http://example.com/1",""],
[2,"http://example.com/2",""],
[3,"http://example.com/3","Feed Title"],
[4,"http://example.com/4",""],
[5,"http://example.com/5","Feed Title"],
[6,"http://example.com/6",""],
[7,"http://example.com/7",""],
[8,"http://example.com/8",""],
[9,"http://example.com/9",""],
[10,"http://example.com/10",""],
[11,"http://example.com/11",""],
[12,"http://example.com/12",""],
[13,"http://example.com/13",""],
["jane.doe@example.com", "", 1],
["john.doe@example.com", "", 2],
["john.doe@example.org", "", 3],
["john.doe@example.net", "", 4],
],
],
'arsse_subscriptions' => [
'columns' => ["id", "owner", "feed", "title"],
'columns' => ["id", "owner", "url", "feed_title", "title"],
'rows' => [
[1, "john.doe@example.com", 1,"Lord of Carrots"],
[2, "john.doe@example.com", 2,null],
[3, "john.doe@example.com", 3,"Subscription Title"],
[4, "john.doe@example.com", 4,null],
[5, "john.doe@example.com",10,null],
[6, "jane.doe@example.com", 1,null],
[7, "jane.doe@example.com",10,null],
[8, "john.doe@example.org",11,null],
[9, "john.doe@example.org",12,null],
[10,"john.doe@example.org",13,null],
[11,"john.doe@example.net",10,null],
[12,"john.doe@example.net", 2,null],
[13,"john.doe@example.net", 3,null],
[14,"john.doe@example.net", 4,null],
[1, "john.doe@example.com", "http://example.com/1", "", "Lord of Carrots"],
[2, "john.doe@example.com", "http://example.com/2", "", null],
[3, "john.doe@example.com", "http://example.com/3", "Feed Title", "Subscription Title"],
[4, "john.doe@example.com", "http://example.com/4", "", null],
[5, "john.doe@example.com", "http://example.com/10", "", null],
[6, "jane.doe@example.com", "http://example.com/1", "", null],
[7, "jane.doe@example.com", "http://example.com/10", "", null],
[8, "john.doe@example.org", "http://example.com/11", "", null],
[9, "john.doe@example.org", "http://example.com/12", "", null],
[10, "john.doe@example.org", "http://example.com/13", "", null],
[11, "john.doe@example.net", "http://example.com/10", "", null],
[12, "john.doe@example.net", "http://example.com/2", "", null],
[13, "john.doe@example.net", "http://example.com/3", "Feed Title", null],
[14, "john.doe@example.net", "http://example.com/4", "", null],
],
],
'arsse_tags' => [

2
tests/phpunit.dist.xml

@ -81,7 +81,7 @@
<file>cases/Db/SQLite3PDO/TestCreation.php</file>
<file>cases/Db/SQLite3PDO/TestDriver.php</file>
<file>cases/Db/SQLite3PDO/TestUpdate.php</file>
<!--<file>cases/Db/SQLite3PDO/TestDatabase.php</file>-->
<file>cases/Db/SQLite3PDO/TestDatabase.php</file>
</testsuite>
<testsuite name="PostgreSQL">
<file>cases/Db/PostgreSQL/TestResult.php</file>

Loading…
Cancel
Save