J. King
5 years ago
45 changed files with 446 additions and 161 deletions
@ -1,3 +1,3 @@ |
|||||
Presently installing and setting up The Arsse is a manual process. We hope to have pre-configured installation packages available for various operating systems eventually, but for now the pages in this section should help get you up and running. |
Presently installing and setting up The Arsse is a manual process. We hope to have pre-configured installation packages available for various operating systems eventually, but for now the pages in this section should help get you up and running. |
||||
|
|
||||
Though The Arsse itself makes no assumptions about the operating system which hosts it, we use and have the most experience with Debian; the instructions contained here therefore are for Debian systems will will probably either not work with other systems or not be consistent with their conventions. Nevertheless, they should still serve as a useful guide. |
Though The Arsse itself makes no assumptions about the operating system which hosts it, we use and have the most experience with Debian; the instructions contained here therefore are for Debian systems and will probably either not work with other systems or not be consistent with their conventions. Nevertheless, they should still serve as a useful guide. |
||||
|
@ -0,0 +1,115 @@ |
|||||
|
<?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\TestCase\Misc; |
||||
|
|
||||
|
use JKingWeb\Arsse\Misc\Query; |
||||
|
use JKingWeb\Arsse\Misc\ValueInfo; |
||||
|
|
||||
|
/** @covers \JKingWeb\Arsse\Misc\Query */ |
||||
|
class TestQuery extends \JKingWeb\Arsse\Test\AbstractTest { |
||||
|
public function testBasicQuery() { |
||||
|
$q = new Query("select * from table where a = ?", "int", 3); |
||||
|
$this->assertSame("select * from table where a = ?", $q->getQuery()); |
||||
|
$this->assertSame(["int"], $q->getTypes()); |
||||
|
$this->assertSame([3], $q->getValues()); |
||||
|
} |
||||
|
|
||||
|
public function testWhereQuery() { |
||||
|
// simple where clause |
||||
|
$q = (new Query("select * from table"))->setWhere("a = ?", "int", 3); |
||||
|
$this->assertSame("select * from table WHERE a = ?", $q->getQuery()); |
||||
|
$this->assertSame(["int"], $q->getTypes()); |
||||
|
$this->assertSame([3], $q->getValues()); |
||||
|
// compound where clause |
||||
|
$q = (new Query("select * from table"))->setWhere("a = ?", "int", 3)->setWhere("b = ?", "str", 4); |
||||
|
$this->assertSame("select * from table WHERE a = ? AND b = ?", $q->getQuery()); |
||||
|
$this->assertSame(["int", "str"], $q->getTypes()); |
||||
|
$this->assertSame([3, 4], $q->getValues()); |
||||
|
// negative where clause |
||||
|
$q = (new Query("select * from table"))->setWhereNot("a = ?", "int", 3); |
||||
|
$this->assertSame("select * from table WHERE NOT (a = ?)", $q->getQuery()); |
||||
|
$this->assertSame(["int"], $q->getTypes()); |
||||
|
$this->assertSame([3], $q->getValues()); |
||||
|
// compound negative where clause |
||||
|
$q = (new Query("select * from table"))->setWhereNot("a = ?", "int", 3)->setWhereNot("b = ?", "str", 4); |
||||
|
$this->assertSame("select * from table WHERE NOT (a = ? OR b = ?)", $q->getQuery()); |
||||
|
$this->assertSame(["int", "str"], $q->getTypes()); |
||||
|
$this->assertSame([3, 4], $q->getValues()); |
||||
|
// mixed where clause |
||||
|
$q = (new Query("select * from table"))->setWhereNot("a = ?", "int", 1)->setWhere("b = ?", "str", 2)->setWhereNot("c = ?", "int", 3)->setWhere("d = ?", "str", 4); |
||||
|
$this->assertSame("select * from table WHERE b = ? AND d = ? AND NOT (a = ? OR c = ?)", $q->getQuery()); |
||||
|
$this->assertSame(["str", "str", "int", "int"], $q->getTypes()); |
||||
|
$this->assertSame([2, 4, 1, 3], $q->getValues()); |
||||
|
} |
||||
|
|
||||
|
public function testGroupedQuery() { |
||||
|
$q = (new Query("select col1, col2, count(*) as count from table"))->setGroup("col1", "col2"); |
||||
|
$this->assertSame("select col1, col2, count(*) as count from table GROUP BY col1, col2", $q->getQuery()); |
||||
|
$this->assertSame([], $q->getTypes()); |
||||
|
$this->assertSame([], $q->getValues()); |
||||
|
} |
||||
|
|
||||
|
public function testOrderedQuery() { |
||||
|
$q = (new Query("select col1, col2, col3 from table"))->setOrder("col1 desc", "col2")->setOrder("col3 asc"); |
||||
|
$this->assertSame("select col1, col2, col3 from table ORDER BY col1 desc, col2, col3 asc", $q->getQuery()); |
||||
|
$this->assertSame([], $q->getTypes()); |
||||
|
$this->assertSame([], $q->getValues()); |
||||
|
} |
||||
|
|
||||
|
public function testLimitedQuery() { |
||||
|
// no offset |
||||
|
$q = (new Query("select * from table"))->setLimit(5); |
||||
|
$this->assertSame("select * from table LIMIT 5", $q->getQuery()); |
||||
|
$this->assertSame([], $q->getTypes()); |
||||
|
$this->assertSame([], $q->getValues()); |
||||
|
// with offset |
||||
|
$q = (new Query("select * from table"))->setLimit(5, 10); |
||||
|
$this->assertSame("select * from table LIMIT 5 OFFSET 10", $q->getQuery()); |
||||
|
$this->assertSame([], $q->getTypes()); |
||||
|
$this->assertSame([], $q->getValues()); |
||||
|
// no limit with offset |
||||
|
$q = (new Query("select * from table"))->setLimit(0, 10); |
||||
|
$this->assertSame("select * from table LIMIT -1 OFFSET 10", $q->getQuery()); |
||||
|
$this->assertSame([], $q->getTypes()); |
||||
|
$this->assertSame([], $q->getValues()); |
||||
|
} |
||||
|
|
||||
|
public function testQueryWithCommonTableExpression() { |
||||
|
$q = (new Query("select * from table where a in (select * from cte where a = ?)", "int", 1))->setCTE("cte", "select * from other_table where a = ? and b = ?", ["str", "str"], [2, 3]); |
||||
|
$this->assertSame("WITH RECURSIVE cte as (select * from other_table where a = ? and b = ?) select * from table where a in (select * from cte where a = ?)", $q->getQuery()); |
||||
|
$this->assertSame(["str", "str", "int"], $q->getTypes()); |
||||
|
$this->assertSame([2, 3, 1], $q->getValues()); |
||||
|
// multiple CTEs |
||||
|
$q = (new Query("select * from table where a in (select * from cte1 join cte2 using (a) where a = ?)", "int", 1))->setCTE("cte1", "select * from other_table where a = ? and b = ?", ["str", "str"], [2, 3])->setCTE("cte2", "select * from other_table where c between ? and ?", ["datetime", "datetime"], [4, 5]); |
||||
|
$this->assertSame("WITH RECURSIVE cte1 as (select * from other_table where a = ? and b = ?), cte2 as (select * from other_table where c between ? and ?) select * from table where a in (select * from cte1 join cte2 using (a) where a = ?)", $q->getQuery()); |
||||
|
$this->assertSame(["str", "str", "datetime", "datetime", "int"], $q->getTypes()); |
||||
|
$this->assertSame([2, 3, 4, 5, 1], $q->getValues()); |
||||
|
} |
||||
|
|
||||
|
public function testQueryWithPushedCommonTableExpression() { |
||||
|
$q = (new Query("select * from table1"))->setWhere("a between ? and ?", ["datetime", "datetime"], [1, 2]) |
||||
|
->setCTE("cte1", "select * from table2 where a = ? and b = ?", ["str", "str"], [3, 4]) |
||||
|
->pushCTE("cte2") |
||||
|
->setBody("select * from table3 join cte1 using (a) join cte2 using (a) where a = ?", "int", 5); |
||||
|
$this->assertSame("WITH RECURSIVE cte1 as (select * from table2 where a = ? and b = ?), cte2 as (select * from table1 WHERE a between ? and ?) select * from table3 join cte1 using (a) join cte2 using (a) where a = ?", $q->getQuery()); |
||||
|
$this->assertSame(["str", "str", "datetime", "datetime", "int"], $q->getTypes()); |
||||
|
$this->assertSame([3, 4, 1, 2, 5], $q->getValues()); |
||||
|
} |
||||
|
|
||||
|
public function testComplexQuery() { |
||||
|
$q = (new query("select *, ? as const from table", "datetime", 1)) |
||||
|
->setWhereNot("b = ?", "bool", 2) |
||||
|
->setGroup("col1", "col2") |
||||
|
->setWhere("a = ?", "str", 3) |
||||
|
->setLimit(4, 5) |
||||
|
->setOrder("col3") |
||||
|
->setCTE("cte", "select ? as const", "int", 6); |
||||
|
$this->assertSame("WITH RECURSIVE cte as (select ? as const) select *, ? as const from table WHERE a = ? AND NOT (b = ?) GROUP BY col1, col2 ORDER BY col3 LIMIT 4 OFFSET 5", $q->getQuery()); |
||||
|
$this->assertSame(["int", "datetime", "str", "bool"], $q->getTypes()); |
||||
|
$this->assertSame([6, 1, 3, 2], $q->getValues()); |
||||
|
} |
||||
|
} |
@ -0,0 +1,47 @@ |
|||||
|
<?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\TestCase\Service; |
||||
|
|
||||
|
use JKingWeb\Arsse\Arsse; |
||||
|
use JKingWeb\Arsse\Database; |
||||
|
use JKingWeb\Arsse\Service\Driver as DriverInterface; |
||||
|
use JKingWeb\Arsse\Service\Serial\Driver; |
||||
|
|
||||
|
/** @covers \JKingWeb\Arsse\Service\Serial\Driver */ |
||||
|
class TestSerial extends \JKingWeb\Arsse\Test\AbstractTest { |
||||
|
public function setUp() { |
||||
|
self::clearData(); |
||||
|
self::setConf(); |
||||
|
Arsse::$db = \Phake::mock(Database::class); |
||||
|
} |
||||
|
|
||||
|
public function testConstruct() { |
||||
|
$this->assertTrue(Driver::requirementsMet()); |
||||
|
$this->assertInstanceOf(DriverInterface::class, new Driver); |
||||
|
} |
||||
|
|
||||
|
public function testFetchDriverName() { |
||||
|
$this->assertTrue(strlen(Driver::driverName()) > 0); |
||||
|
} |
||||
|
|
||||
|
public function testEnqueueFeeds() { |
||||
|
$d = new Driver; |
||||
|
$this->assertSame(3, $d->queue(1, 2, 3)); |
||||
|
$this->assertSame(5, $d->queue(4, 5)); |
||||
|
$this->assertSame(5, $d->clean()); |
||||
|
$this->assertSame(1, $d->queue(5)); |
||||
|
} |
||||
|
|
||||
|
public function testRefreshFeeds() { |
||||
|
$d = new Driver; |
||||
|
$d->queue(1, 4, 3); |
||||
|
$this->assertSame(Arsse::$conf->serviceQueueWidth, $d->exec()); |
||||
|
\Phake::verify(Arsse::$db)->feedUpdate(1); |
||||
|
\Phake::verify(Arsse::$db)->feedUpdate(4); |
||||
|
\Phake::verify(Arsse::$db)->feedUpdate(3); |
||||
|
} |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
<?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\TestCase\Service; |
||||
|
|
||||
|
use JKingWeb\Arsse\Arsse; |
||||
|
use JKingWeb\Arsse\Database; |
||||
|
use JKingWeb\Arsse\Service\Driver as DriverInterface; |
||||
|
use JKingWeb\Arsse\Service\Subprocess\Driver; |
||||
|
|
||||
|
/** @covers \JKingWeb\Arsse\Service\Subprocess\Driver */ |
||||
|
class TestSubprocess extends \JKingWeb\Arsse\Test\AbstractTest { |
||||
|
public function setUp() { |
||||
|
self::clearData(); |
||||
|
self::setConf(); |
||||
|
} |
||||
|
|
||||
|
public function testConstruct() { |
||||
|
$this->assertTrue(Driver::requirementsMet()); |
||||
|
$this->assertInstanceOf(DriverInterface::class, new Driver); |
||||
|
} |
||||
|
|
||||
|
public function testFetchDriverName() { |
||||
|
$this->assertTrue(strlen(Driver::driverName()) > 0); |
||||
|
} |
||||
|
|
||||
|
public function testEnqueueFeeds() { |
||||
|
$d = new Driver; |
||||
|
$this->assertSame(3, $d->queue(1, 2, 3)); |
||||
|
$this->assertSame(5, $d->queue(4, 5)); |
||||
|
$this->assertSame(5, $d->clean()); |
||||
|
$this->assertSame(1, $d->queue(5)); |
||||
|
} |
||||
|
|
||||
|
public function testRefreshFeeds() { |
||||
|
$d = \Phake::partialMock(Driver::class); |
||||
|
\Phake::when($d)->execCmd->thenReturnCallback(function(string $cmd) { |
||||
|
// FIXME: Does this work in Windows? |
||||
|
return popen("echo ".escapeshellarg($cmd), "r"); |
||||
|
}); |
||||
|
$this->assertSame(3, $d->queue(1, 4, 3)); |
||||
|
$this->assertSame(Arsse::$conf->serviceQueueWidth, $d->exec()); |
||||
|
\Phake::verify($d, \Phake::times(3))->execCmd; |
||||
|
} |
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
<?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\TestCase; |
||||
|
|
||||
|
use JKingWeb\Arsse\Arsse; |
||||
|
use JKingWeb\Arsse\Conf; |
||||
|
use JKingWeb\Arsse\Lang; |
||||
|
use JKingWeb\Arsse\User; |
||||
|
use JKingWeb\Arsse\Database; |
||||
|
use JKingWeb\Arsse\Service; |
||||
|
|
||||
|
/** @covers \JKingWeb\Arsse\Arsse */ |
||||
|
class TestArsse extends \JKingWeb\Arsse\Test\AbstractTest { |
||||
|
public function setUp() { |
||||
|
self::clearData(false); |
||||
|
} |
||||
|
public function tearDown() { |
||||
|
self::clearData(); |
||||
|
} |
||||
|
|
||||
|
public function testLoadExistingData() { |
||||
|
$lang = Arsse::$lang = \Phake::mock(Lang::class); |
||||
|
$db = Arsse::$db = \Phake::mock(Database::class); |
||||
|
$user = Arsse::$user = \Phake::mock(User::class); |
||||
|
$conf1 = Arsse::$conf = \Phake::mock(Conf::class); |
||||
|
$conf2 = (new Conf)->import(['lang' => "test"]); |
||||
|
Arsse::load($conf2); |
||||
|
$this->assertSame($conf2, Arsse::$conf); |
||||
|
$this->assertSame($lang, Arsse::$lang); |
||||
|
$this->assertSame($db, Arsse::$db); |
||||
|
$this->assertSame($user, Arsse::$user); |
||||
|
\Phake::verify($lang)->set("test"); |
||||
|
} |
||||
|
|
||||
|
public function testLoadNewData() { |
||||
|
if (!\JKingWeb\Arsse\Db\SQLite3\Driver::requirementsMet() && !\JKingWeb\Arsse\Db\SQLite3\PDODriver::requirementsMet()) { |
||||
|
$this->markTestSkipped("A functional SQLite interface is required for this test"); |
||||
|
} |
||||
|
$conf = (new Conf)->import(['dbSQLite3File' => ":memory:"]); |
||||
|
Arsse::load($conf); |
||||
|
$this->assertInstanceOf(Conf::class, Arsse::$conf); |
||||
|
$this->assertInstanceOf(Lang::class, Arsse::$lang); |
||||
|
$this->assertInstanceOf(Database::class, Arsse::$db); |
||||
|
$this->assertInstanceOf(User::class, Arsse::$user); |
||||
|
} |
||||
|
} |
@ -1,15 +0,0 @@ |
|||||
<?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\Lang; |
|
||||
|
|
||||
use Webmozart\Glob\Glob; |
|
||||
|
|
||||
class TestLang extends \JKingWeb\Arsse\Lang { |
|
||||
protected function globFiles(string $path): array { |
|
||||
return Glob::glob($this->path."*.php"); |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,13 @@ |
|||||
|
<?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; |
||||
|
|
||||
|
class Service extends \JKingWeb\Arsse\Service { |
||||
|
public function __construct(\JKingWeb\Arsse\Service\Driver $drv) { |
||||
|
$this->drv = $drv; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue