diff --git a/lib/Database.php b/lib/Database.php index 48bf2bd..3a2bc08 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -328,11 +328,11 @@ class Database { protected function folderValidateId(string $user, int $id = null, int $parent = null, bool $subject = false): array { if(is_null($id)) { - // if no ID is specified this is a no-op, unless a parent is specified, which is always a circular dependence + // if no ID is specified this is a no-op, unless a parent is specified, which is always a circular dependence (the root cannot be moved) if(!is_null($parent)) { - throw new Db\ExceptionInput("circularDependence", ["action" => $this->caller(), "field" => "parent", 'id' => $parent]); + throw new Db\ExceptionInput("circularDependence", ["action" => $this->caller(), "field" => "parent", 'id' => $parent]); // @codeCoverageIgnore } - return [name => null, parent => null]; + return ['name' => null, 'parent' => null]; } // check whether the folder exists and is owned by the user $f = $this->db->prepare("SELECT name,parent from arsse_folders where owner is ? and id is ?", "str", "int")->run($user, $id)->getRow(); diff --git a/tests/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php b/tests/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php index 1a03414..ebd46f2 100644 --- a/tests/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php +++ b/tests/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse; -/** @covers \JKingWeb\Arsse\Database */ +/** @covers \JKingWeb\Arsse\Database */ class TestDatabaseArticleSQLite3 extends Test\AbstractTest { use Test\Database\Setup; use Test\Database\DriverSQLite3; diff --git a/tests/Db/SQLite3/Database/TestDatabaseFeedSQLite3.php b/tests/Db/SQLite3/Database/TestDatabaseFeedSQLite3.php index 6af2982..7db96a3 100644 --- a/tests/Db/SQLite3/Database/TestDatabaseFeedSQLite3.php +++ b/tests/Db/SQLite3/Database/TestDatabaseFeedSQLite3.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse; -/** @covers \JKingWeb\Arsse\Database */ +/** @covers \JKingWeb\Arsse\Database */ class TestDatabaseFeedSQLite3 extends Test\AbstractTest { use Test\Database\Setup; use Test\Database\DriverSQLite3; diff --git a/tests/Db/SQLite3/Database/TestDatabaseFolderSQLite3.php b/tests/Db/SQLite3/Database/TestDatabaseFolderSQLite3.php index 02b64dc..448b046 100644 --- a/tests/Db/SQLite3/Database/TestDatabaseFolderSQLite3.php +++ b/tests/Db/SQLite3/Database/TestDatabaseFolderSQLite3.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse; -/** @covers \JKingWeb\Arsse\Database */ +/** @covers \JKingWeb\Arsse\Database */ class TestDatabaseFolderSQLite3 extends Test\AbstractTest { use Test\Database\Setup; use Test\Database\DriverSQLite3; diff --git a/tests/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php b/tests/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php index 87c22ec..e9e132b 100644 --- a/tests/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php +++ b/tests/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse; -/** @covers \JKingWeb\Arsse\Database */ +/** @covers \JKingWeb\Arsse\Database */ class TestDatabaseMetaSQLite3 extends Test\AbstractTest { use Test\Database\Setup; use Test\Database\DriverSQLite3; diff --git a/tests/Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php b/tests/Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php new file mode 100644 index 0000000..7075c3e --- /dev/null +++ b/tests/Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php @@ -0,0 +1,10 @@ + */ +class TestDatabaseMiscellanySQLite3 extends Test\AbstractTest { + use Test\Database\Setup; + use Test\Database\DriverSQLite3; + use Test\Database\SeriesMiscellany; +} \ No newline at end of file diff --git a/tests/Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php b/tests/Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php index 9992d8f..bf30662 100644 --- a/tests/Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php +++ b/tests/Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse; -/** @covers \JKingWeb\Arsse\Database */ +/** @covers \JKingWeb\Arsse\Database */ class TestDatabaseSubscriptionSQLite3 extends Test\AbstractTest { use Test\Database\Setup; use Test\Database\DriverSQLite3; diff --git a/tests/Db/SQLite3/Database/TestDatabaseUserSQLite3.php b/tests/Db/SQLite3/Database/TestDatabaseUserSQLite3.php index 5bf1a1b..dfba48b 100644 --- a/tests/Db/SQLite3/Database/TestDatabaseUserSQLite3.php +++ b/tests/Db/SQLite3/Database/TestDatabaseUserSQLite3.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse; -/** @covers \JKingWeb\Arsse\Database */ +/** @covers \JKingWeb\Arsse\Database */ class TestDatabaseUserSQLite3 extends Test\AbstractTest { use Test\Database\Setup; use Test\Database\DriverSQLite3; diff --git a/tests/docroot/Feed/Parsing/Valid.php b/tests/docroot/Feed/Parsing/Valid.php index 8e0a3ca..ca376cc 100644 --- a/tests/docroot/Feed/Parsing/Valid.php +++ b/tests/docroot/Feed/Parsing/Valid.php @@ -18,6 +18,8 @@ urn:uuid:43fb1908-42ec-11e7-b61b-2b118faca2f2 + + HLN http://example.com/2 diff --git a/tests/lib/Database/SeriesFeed.php b/tests/lib/Database/SeriesFeed.php index 50fe3c6..7545d5c 100644 --- a/tests/lib/Database/SeriesFeed.php +++ b/tests/lib/Database/SeriesFeed.php @@ -87,6 +87,7 @@ trait SeriesFeed { [4,1,'http://example.com/4','Article title 4','','2000-01-04 00:00:00','2000-01-04 00:00:00','

Article content 4

','804e517d623390e71497982c77cf6823180342ebcd2e7d5e32da1e55b09dd180','f3615c7f16336d3ea242d35cf3fc17dbc4ee3afb78376bf49da2dd7a5a25dec8','f11c2b4046f207579aeb9c69a8c20ca5461cef49756ccfa5ba5e2344266da3b3','ab2da63276acce431250b18d3d49b988b226a99c7faadf275c90b751aee05be9',$past], [5,1,'http://example.com/5','Article title 5','','2000-01-05 00:00:00','2000-01-05 00:00:00','

Article content 5

','db3e736c2c492f5def5c5da33ddcbea1824040e9ced2142069276b0a6e291a41','d40da96e39eea6c55948ccbe9b3d275b5f931298288dbe953990c5f496097022','834240f84501b5341d375414718204ec421561f3825d34c22bf9182203e42900','43b970ac6ec5f8a9647b2c7e4eed8b1d7f62e154a95eed748b0294c1256764ba',$past], [6,2,'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], + [7,5,'' ,'' ,'','2000-01-01 00:00:00','2000-01-01 00:00:00','' ,'205e986f4f8b3acfa281227beadb14f5e8c32c8dae4737f888c94c0df49c56f8','' ,'' ,'' ,$past], ] ], 'arsse_editions' => [ @@ -125,17 +126,21 @@ trait SeriesFeed { ], 'arsse_enclosures' => [ 'columns' => [ + 'article' => "int", 'url' => "str", 'type' => "str", ], 'rows' => [ + [7,'http://example.com/png','image/png'], ] ], 'arsse_categories' => [ 'columns' => [ + 'article' => "int", 'name' => "str", ], 'rows' => [ + [7,'Syrinx'] ] ], ]; @@ -167,9 +172,9 @@ trait SeriesFeed { ]); $state['arsse_articles']['rows'][2] = [3,1,'http://example.com/3','Article title 3 (updated)','','2000-01-03 00:00:00','2000-01-03 00:00:00','

Article content 3

','31a6594500a48b59fcc8a075ce82b946c9c3c782460d088bd7b8ef3ede97ad92','6cc99be662ef3486fef35a890123f18d74c29a32d714802d743c5b4ef713315a','b278380e984cefe63f0e412b88ffc9cb0befdfa06fdc00bace1da99a8daff406','d5faccc13bf8267850a1e8e61f95950a0f34167df2c8c58011c0aaa6367026ac',$now]; $state['arsse_articles']['rows'][3] = [4,1,'http://example.com/4','Article title 4','','2000-01-04 00:00:00','2000-01-04 00:00:01','

Article content 4

','804e517d623390e71497982c77cf6823180342ebcd2e7d5e32da1e55b09dd180','f3615c7f16336d3ea242d35cf3fc17dbc4ee3afb78376bf49da2dd7a5a25dec8','f11c2b4046f207579aeb9c69a8c20ca5461cef49756ccfa5ba5e2344266da3b3','ab2da63276acce431250b18d3d49b988b226a99c7faadf275c90b751aee05be9',$now]; - $state['arsse_articles']['rows'][] = [7,1,'http://example.com/6','Article title 6','','2000-01-06 00:00:00','2000-01-06 00:00:00','

Article content 6

','b3461ab8e8759eeb1d65a818c65051ec00c1dfbbb32a3c8f6999434e3e3b76ab','91d051a8e6749d014506848acd45e959af50bf876427c4f0e3a1ec0f04777b51','211d78b1a040d40d17e747a363cc283f58767b2e502630d8de9b8f1d5e941d18','5ed68ccb64243b8c1931241d2c9276274c3b1d87f223634aa7a1ab0141292ca7',$now]; + $state['arsse_articles']['rows'][] = [8,1,'http://example.com/6','Article title 6','','2000-01-06 00:00:00','2000-01-06 00:00:00','

Article content 6

','b3461ab8e8759eeb1d65a818c65051ec00c1dfbbb32a3c8f6999434e3e3b76ab','91d051a8e6749d014506848acd45e959af50bf876427c4f0e3a1ec0f04777b51','211d78b1a040d40d17e747a363cc283f58767b2e502630d8de9b8f1d5e941d18','5ed68ccb64243b8c1931241d2c9276274c3b1d87f223634aa7a1ab0141292ca7',$now]; $state['arsse_editions']['rows'] = array_merge($state['arsse_editions']['rows'], [ - [6,7,$now], + [6,8,$now], [7,3,$now], [8,4,$now], ]); @@ -194,6 +199,11 @@ trait SeriesFeed { $this->compareExpectations($state); } + function testUpdateAMissingFeed() { + $this->assertException("subjectMissing", "Db", "ExceptionInput"); + Arsse::$db->feedUpdate(2112); + } + function testUpdateAFeedThrowingExceptions() { $this->assertException("invalidUrl", "Feed"); Arsse::$db->feedUpdate(3, true); @@ -205,13 +215,17 @@ trait SeriesFeed { 'arsse_enclosures' => ["url","type"], 'arsse_categories' => ["name"], ]); - $state['arsse_enclosures']['rows'][] = ['http://example.com/text','text/plain']; - $state['arsse_categories']['rows'] = array_merge($state['arsse_categories']['rows'], [ + $state['arsse_enclosures']['rows'] = [ + ['http://example.com/svg','image/svg'], + ['http://example.com/text','text/plain'], + ]; + $state['arsse_categories']['rows'] = [ + ["HLN"], ["Aniki!"], ["Beams"], ["Bodybuilders"], ["Men"], - ]); + ]; $this->compareExpectations($state); } diff --git a/tests/lib/Database/SeriesFolder.php b/tests/lib/Database/SeriesFolder.php index 2d5f58a..4c5be19 100644 --- a/tests/lib/Database/SeriesFolder.php +++ b/tests/lib/Database/SeriesFolder.php @@ -225,6 +225,16 @@ trait SeriesFolder { $this->compareExpectations($state); } + function testRenameAFolderToTheEmptyString() { + $this->assertException("missing", "Db", "ExceptionInput"); + $this->assertTrue(Arsse::$db->folderPropertiesSet("john.doe@example.com", 6, ['name' => ""])); + } + + function testRenameAFolderToWhitespaceOnly() { + $this->assertException("whitespace", "Db", "ExceptionInput"); + $this->assertTrue(Arsse::$db->folderPropertiesSet("john.doe@example.com", 6, ['name' => " "])); + } + function testMoveAFolder() { $this->assertTrue(Arsse::$db->folderPropertiesSet("john.doe@example.com", 6, ['parent' => 5])); Phake::verify(Arsse::$user)->authorize("john.doe@example.com", "folderPropertiesSet"); diff --git a/tests/lib/Database/SeriesMiscellany.php b/tests/lib/Database/SeriesMiscellany.php new file mode 100644 index 0000000..eacf879 --- /dev/null +++ b/tests/lib/Database/SeriesMiscellany.php @@ -0,0 +1,28 @@ + Arsse::$lang->msg("Driver.Db.SQLite3.Name"), + ]; + $this->assertArraySubset($exp, Database::driverList()); + } + + function testInitializeDatabase() { + $d = new Database(); + $this->assertSame(Database::SCHEMA_VERSION, $d->driverSchemaVersion()); + } + + function testManuallyInitializeDatabase() { + $d = new Database(false); + $this->assertSame(0, $d->driverSchemaVersion()); + $this->assertTrue($d->driverSchemaUpdate()); + $this->assertSame(Database::SCHEMA_VERSION, $d->driverSchemaVersion()); + $this->assertFalse($d->driverSchemaUpdate()); + } +} \ No newline at end of file diff --git a/tests/lib/Database/SeriesSubscription.php b/tests/lib/Database/SeriesSubscription.php index 92e8a5b..74f70f8 100644 --- a/tests/lib/Database/SeriesSubscription.php +++ b/tests/lib/Database/SeriesSubscription.php @@ -264,6 +264,17 @@ trait SeriesSubscription { Arsse::$db->subscriptionList($this->user); } + function testGetThePropertiesOfAMissingSubscription() { + $this->assertException("subjectMissing", "Db", "ExceptionInput"); + Arsse::$db->subscriptionPropertiesGet($this->user, 2112); + } + + function testGetThePropertiesOfASubscriptionWithoutAuthority() { + Phake::when(Arsse::$user)->authorize->thenReturn(false); + $this->assertException("notAuthorized", "User", "ExceptionAuthz"); + Arsse::$db->subscriptionPropertiesGet($this->user, 1); + } + function testSetThePropertiesOfASubscription() { Arsse::$db->subscriptionPropertiesSet($this->user, 1,[ 'title' => "Ook Ook", @@ -290,6 +301,10 @@ trait SeriesSubscription { Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['folder' => 4]); } + function testMoveASubscriptionToTheRootFolder() { + $this->assertTrue(Arsse::$db->subscriptionPropertiesSet($this->user, 3, ['folder' => null])); + } + function testRenameASubscriptionToABlankTitle() { $this->assertException("missing", "Db", "ExceptionInput"); Arsse::$db->subscriptionPropertiesSet($this->user, 1, ['title' => ""]); diff --git a/tests/lib/Database/SeriesUser.php b/tests/lib/Database/SeriesUser.php index e91ce6b..59f071e 100644 --- a/tests/lib/Database/SeriesUser.php +++ b/tests/lib/Database/SeriesUser.php @@ -43,6 +43,11 @@ trait SeriesUser { $this->assertTrue(password_verify("secret", $hash)); } + function testGetThePasswordOfAMissingUser() { + $this->assertException("doesNotExist", "User"); + Arsse::$db->userPasswordGet("john.doe@example.org"); + } + function testGetAPasswordWithoutAuthority() { Phake::when(Arsse::$user)->authorize->thenReturn(false); $this->assertException("notAuthorized", "User", "ExceptionAuthz"); @@ -145,6 +150,12 @@ trait SeriesUser { Phake::verify(Arsse::$user)->authorize($user, "userPasswordSet"); $this->assertTrue(password_verify($pass, $hash), "Failed verifying password of $user '$pass' against hash '$hash'."); } + function testSetARandomPassword() { + $user = "john.doe@example.com"; + $this->assertEquals("", Arsse::$db->userPasswordGet($user)); + $pass = Arsse::$db->userPasswordSet($user); + $hash = Arsse::$db->userPasswordGet($user); + } function testSetThePasswordOfAMissingUser() { $this->assertException("doesNotExist", "User"); diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 872077b..c17cfd8 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -53,6 +53,7 @@ Db/SQLite3/TestDbUpdateSQLite3.php + Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php Db/SQLite3/Database/TestDatabaseMetaSQLite3.php Db/SQLite3/Database/TestDatabaseUserSQLite3.php Db/SQLite3/Database/TestDatabaseFolderSQLite3.php