mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
PDO tests and fixes; improves #72
This commit is contained in:
parent
4b46d654bb
commit
4bada691e9
18 changed files with 212 additions and 12 deletions
|
@ -45,7 +45,7 @@ class RoboFile extends \Robo\Tasks {
|
||||||
* See help for the "test" task for more details.
|
* See help for the "test" task for more details.
|
||||||
*/
|
*/
|
||||||
public function testQuick(array $args): Result {
|
public function testQuick(array $args): Result {
|
||||||
return $this->test(array_merge(["--exclude-group","slow"], $args));
|
return $this->test(array_merge(["--exclude-group", "slow,optional"], $args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Produces a code coverage report
|
/** Produces a code coverage report
|
||||||
|
|
|
@ -415,7 +415,7 @@ class Database {
|
||||||
return $f;
|
return $f;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function folderValidateMove(string $user, int $id = null, $parent = null, string $name = null) {
|
protected function folderValidateMove(string $user, $id = null, $parent = null, string $name = null) {
|
||||||
$errData = ["action" => $this->caller(), "field" => "parent", 'id' => $parent];
|
$errData = ["action" => $this->caller(), "field" => "parent", 'id' => $parent];
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
// the root cannot be moved
|
// the root cannot be moved
|
||||||
|
@ -467,7 +467,7 @@ class Database {
|
||||||
return $parent;
|
return $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function folderValidateName($name, bool $checkDuplicates = false, int $parent = null): bool {
|
protected function folderValidateName($name, bool $checkDuplicates = false, $parent = null): bool {
|
||||||
$info = ValueInfo::str($name);
|
$info = ValueInfo::str($name);
|
||||||
if ($info & (ValueInfo::NULL | ValueInfo::EMPTY)) {
|
if ($info & (ValueInfo::NULL | ValueInfo::EMPTY)) {
|
||||||
throw new Db\ExceptionInput("missing", ["action" => $this->caller(), "field" => "name"]);
|
throw new Db\ExceptionInput("missing", ["action" => $this->caller(), "field" => "name"]);
|
||||||
|
@ -572,7 +572,7 @@ class Database {
|
||||||
// add a suitable WHERE condition
|
// add a suitable WHERE condition
|
||||||
$q->setWhere("folder in (select folder from folders)");
|
$q->setWhere("folder in (select folder from folders)");
|
||||||
}
|
}
|
||||||
return $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getValue();
|
return (int) $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subscriptionRemove(string $user, $id): bool {
|
public function subscriptionRemove(string $user, $id): bool {
|
||||||
|
@ -1102,7 +1102,7 @@ class Database {
|
||||||
$q = $this->articleQuery($user, $context);
|
$q = $this->articleQuery($user, $context);
|
||||||
$q->pushCTE("selected_articles");
|
$q->pushCTE("selected_articles");
|
||||||
$q->setBody("SELECT count(*) from selected_articles");
|
$q->setBody("SELECT count(*) from selected_articles");
|
||||||
return $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getValue();
|
return (int) $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseArticleSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesArticle;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseCleanupSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesCleanup;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseFeedSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesFeed;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseFolderSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesFolder;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseLabelSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesLabel;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseMetaSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesMeta;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseMiscellanySQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesMiscellany;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseSessionSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesSession;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseSubscriptionSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesSubscription;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \JKingWeb\Arsse\Database<extended>
|
||||||
|
* @group optional */
|
||||||
|
class TestDatabaseUserSQLite3PDO extends Test\AbstractTest {
|
||||||
|
use Test\Database\Setup;
|
||||||
|
use Test\Database\DriverSQLite3PDO;
|
||||||
|
use Test\Database\SeriesUser;
|
||||||
|
}
|
|
@ -32,6 +32,8 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
||||||
public function approximateTime($exp, $act) {
|
public function approximateTime($exp, $act) {
|
||||||
if (is_null($act)) {
|
if (is_null($act)) {
|
||||||
return null;
|
return null;
|
||||||
|
} elseif (is_null($exp)) {
|
||||||
|
return $act;
|
||||||
}
|
}
|
||||||
$target = Date::normalize($exp)->getTimeStamp();
|
$target = Date::normalize($exp)->getTimeStamp();
|
||||||
$value = Date::normalize($act)->getTimeStamp();
|
$value = Date::normalize($act)->getTimeStamp();
|
||||||
|
|
24
tests/lib/Database/DriverSQLite3PDO.php
Normal file
24
tests/lib/Database/DriverSQLite3PDO.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
/** @license MIT
|
||||||
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||||
|
* See LICENSE and AUTHORS files for details */
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\Arsse\Test\Database;
|
||||||
|
|
||||||
|
use JKingWeb\Arsse\Arsse;
|
||||||
|
use JKingWeb\Arsse\Db\SQLite3\PDODriver;
|
||||||
|
|
||||||
|
trait DriverSQLite3PDO {
|
||||||
|
public function setUpDriver() {
|
||||||
|
if (!PDODriver::requirementsMet()) {
|
||||||
|
$this->markTestSkipped("PDO-SQLite extension not loaded");
|
||||||
|
}
|
||||||
|
Arsse::$conf->dbSQLite3File = ":memory:";
|
||||||
|
$this->drv = new PDODriver();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nextID(string $table): int {
|
||||||
|
return (int) $this->drv->query("SELECT (case when max(id) then max(id) else 0 end)+1 from $table")->getValue();
|
||||||
|
}
|
||||||
|
}
|
|
@ -888,8 +888,8 @@ trait SeriesArticle {
|
||||||
public function testFetchStarredCounts() {
|
public function testFetchStarredCounts() {
|
||||||
$exp1 = ['total' => 2, 'unread' => 1, 'read' => 1];
|
$exp1 = ['total' => 2, 'unread' => 1, 'read' => 1];
|
||||||
$exp2 = ['total' => 0, 'unread' => 0, 'read' => 0];
|
$exp2 = ['total' => 0, 'unread' => 0, 'read' => 0];
|
||||||
$this->assertSame($exp1, Arsse::$db->articleStarred("john.doe@example.com"));
|
$this->assertEquals($exp1, Arsse::$db->articleStarred("john.doe@example.com"));
|
||||||
$this->assertSame($exp2, Arsse::$db->articleStarred("jane.doe@example.com"));
|
$this->assertEquals($exp2, Arsse::$db->articleStarred("jane.doe@example.com"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFetchStarredCountsWithoutAuthority() {
|
public function testFetchStarredCountsWithoutAuthority() {
|
||||||
|
|
|
@ -256,9 +256,9 @@ trait SeriesFeed {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListStaleFeeds() {
|
public function testListStaleFeeds() {
|
||||||
$this->assertSame([1,3,4], Arsse::$db->feedListStale());
|
$this->assertEquals([1,3,4], Arsse::$db->feedListStale());
|
||||||
Arsse::$db->feedUpdate(3);
|
Arsse::$db->feedUpdate(3);
|
||||||
Arsse::$db->feedUpdate(4);
|
Arsse::$db->feedUpdate(4);
|
||||||
$this->assertSame([1], Arsse::$db->feedListStale());
|
$this->assertEquals([1], Arsse::$db->feedListStale());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use JKingWeb\Arsse\User\Driver as UserDriver;
|
||||||
use JKingWeb\Arsse\Arsse;
|
use JKingWeb\Arsse\Arsse;
|
||||||
use JKingWeb\Arsse\Conf;
|
use JKingWeb\Arsse\Conf;
|
||||||
use JKingWeb\Arsse\User;
|
use JKingWeb\Arsse\User;
|
||||||
|
use JKingWeb\Arsse\Misc\ValueInfo;
|
||||||
use JKingWeb\Arsse\Test\Database;
|
use JKingWeb\Arsse\Test\Database;
|
||||||
use JKingWeb\Arsse\Db\Result;
|
use JKingWeb\Arsse\Db\Result;
|
||||||
use Phake;
|
use Phake;
|
||||||
|
@ -90,8 +91,19 @@ trait Setup {
|
||||||
$row = array_combine($cols, $row);
|
$row = array_combine($cols, $row);
|
||||||
foreach($data as $index => $test) {
|
foreach($data as $index => $test) {
|
||||||
foreach ($test as $col => $value) {
|
foreach ($test as $col => $value) {
|
||||||
if ($types[$col]=="datetime") {
|
switch ($types[$col]) {
|
||||||
$test[$col] = $this->approximateTime($row[$col], $value);
|
case "datetime":
|
||||||
|
$test[$col] = $this->approximateTime($row[$col], $value);
|
||||||
|
break;
|
||||||
|
case "int":
|
||||||
|
$test[$col] = ValueInfo::normalize($value, ValueInfo::T_INT | ValueInfo::M_DROP | valueInfo::M_NULL);
|
||||||
|
break;
|
||||||
|
case "float":
|
||||||
|
$test[$col] = ValueInfo::normalize($value, ValueInfo::T_FLOAT | ValueInfo::M_DROP | valueInfo::M_NULL);
|
||||||
|
break;
|
||||||
|
case "bool":
|
||||||
|
$test[$col] = (int) ValueInfo::normalize($value, ValueInfo::T_BOOL | ValueInfo::M_DROP | valueInfo::M_NULL);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($row===$test) {
|
if($row===$test) {
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
<file>cases/Db/SQLite3PDO/TestDbDriverSQLite3PDO.php</file>
|
<file>cases/Db/SQLite3PDO/TestDbDriverSQLite3PDO.php</file>
|
||||||
<file>cases/Db/SQLite3PDO/TestDbUpdateSQLite3PDO.php</file>
|
<file>cases/Db/SQLite3PDO/TestDbUpdateSQLite3PDO.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="Database functions">
|
<testsuite name="Database functions">
|
||||||
<file>cases/Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php</file>
|
<file>cases/Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php</file>
|
||||||
<file>cases/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php</file>
|
<file>cases/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php</file>
|
||||||
<file>cases/Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
|
<file>cases/Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
|
||||||
|
@ -69,6 +69,16 @@
|
||||||
<file>cases/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php</file>
|
<file>cases/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php</file>
|
||||||
<file>cases/Db/SQLite3/Database/TestDatabaseLabelSQLite3.php</file>
|
<file>cases/Db/SQLite3/Database/TestDatabaseLabelSQLite3.php</file>
|
||||||
<file>cases/Db/SQLite3/Database/TestDatabaseCleanupSQLite3.php</file>
|
<file>cases/Db/SQLite3/Database/TestDatabaseCleanupSQLite3.php</file>
|
||||||
|
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseMiscellanySQLite3PDO.php</file>
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseUserSQLite3PDO.php</file>
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseSessionSQLite3PDO.php</file>
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseFolderSQLite3PDO.php</file>
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseFeedSQLite3PDO.php</file>
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseSubscriptionSQLite3PDO.php</file>
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseArticleSQLite3PDO.php</file>
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseLabelSQLite3PDO.php</file>
|
||||||
|
<file>cases/Db/SQLite3PDO/Database/TestDatabaseCleanupSQLite3PDO.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="Controllers">
|
<testsuite name="Controllers">
|
||||||
<testsuite name="NCNv1">
|
<testsuite name="NCNv1">
|
||||||
|
|
Loading…
Reference in a new issue