Browse Source

Reorganize tests into namespaces

microsub
J. King 6 years ago
parent
commit
59fee52074
  1. 5
      tests/cases/Conf/TestConf.php
  2. 14
      tests/cases/Db/SQLite3/Database/TestArticle.php
  3. 14
      tests/cases/Db/SQLite3/Database/TestCleanup.php
  4. 14
      tests/cases/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php
  5. 14
      tests/cases/Db/SQLite3/Database/TestDatabaseCleanupSQLite3.php
  6. 14
      tests/cases/Db/SQLite3/Database/TestDatabaseFeedSQLite3.php
  7. 14
      tests/cases/Db/SQLite3/Database/TestDatabaseFolderSQLite3.php
  8. 10
      tests/cases/Db/SQLite3/Database/TestDatabaseLabelSQLite3.php
  9. 14
      tests/cases/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php
  10. 14
      tests/cases/Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php
  11. 10
      tests/cases/Db/SQLite3/Database/TestDatabaseSessionSQLite3.php
  12. 14
      tests/cases/Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php
  13. 14
      tests/cases/Db/SQLite3/Database/TestDatabaseUserSQLite3.php
  14. 14
      tests/cases/Db/SQLite3/Database/TestFeed.php
  15. 14
      tests/cases/Db/SQLite3/Database/TestFolder.php
  16. 10
      tests/cases/Db/SQLite3/Database/TestLabel.php
  17. 14
      tests/cases/Db/SQLite3/Database/TestMeta.php
  18. 14
      tests/cases/Db/SQLite3/Database/TestMiscellany.php
  19. 10
      tests/cases/Db/SQLite3/Database/TestSession.php
  20. 14
      tests/cases/Db/SQLite3/Database/TestSubscription.php
  21. 14
      tests/cases/Db/SQLite3/Database/TestUser.php
  22. 32
      tests/cases/Db/SQLite3/TestCreation.php
  23. 19
      tests/cases/Db/SQLite3/TestDriver.php
  24. 22
      tests/cases/Db/SQLite3/TestResult.php
  25. 10
      tests/cases/Db/SQLite3/TestStatement.php
  26. 13
      tests/cases/Db/SQLite3/TestUpdate.php
  27. 19
      tests/cases/Db/TestResultAggregate.php
  28. 16
      tests/cases/Db/TestResultEmpty.php
  29. 9
      tests/cases/Db/TestTransaction.php
  30. 14
      tests/cases/Exception/TestException.php
  31. 15
      tests/cases/Feed/TestFeed.php
  32. 7
      tests/cases/Feed/TestFetching.php
  33. 14
      tests/cases/Lang/TestBasic.php
  34. 9
      tests/cases/Lang/TestErrors.php
  35. 11
      tests/cases/Lang/testComplex.php
  36. 4
      tests/cases/Misc/TestContext.php
  37. 12
      tests/cases/Misc/TestValueInfo.php
  38. 18
      tests/cases/REST/NextCloudNews/TestV1_2.php
  39. 13
      tests/cases/REST/NextCloudNews/TestVersions.php
  40. 11
      tests/cases/REST/TinyTinyRSS/TestAPI.php
  41. 11
      tests/cases/REST/TinyTinyRSS/TestIcon.php
  42. 8
      tests/cases/Service/TestService.php
  43. 79
      tests/cases/User/TestAuthorization.php
  44. 8
      tests/cases/User/TestMockExternal.php
  45. 10
      tests/cases/User/TestMockInternal.php
  46. 8
      tests/cases/User/Testnternal.php
  47. 52
      tests/phpunit.xml

5
tests/cases/Conf/TestConf.php

@ -4,12 +4,13 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Conf;
use JKingWeb\Arsse\Conf;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\Conf */ /** @covers \JKingWeb\Arsse\Conf */
class TestConf extends Test\AbstractTest { class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
public static $vfs; public static $vfs;
public static $path; public static $path;

14
tests/cases/Db/SQLite3/Database/TestArticle.php

@ -0,0 +1,14 @@
<?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\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestArticle extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesArticle;
}

14
tests/cases/Db/SQLite3/Database/TestCleanup.php

@ -0,0 +1,14 @@
<?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\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestCleanup extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesCleanup;
}

14
tests/cases/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php

@ -1,14 +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;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseArticleSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesArticle;
}

14
tests/cases/Db/SQLite3/Database/TestDatabaseCleanupSQLite3.php

@ -1,14 +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;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseCleanupSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesCleanup;
}

14
tests/cases/Db/SQLite3/Database/TestDatabaseFeedSQLite3.php

@ -1,14 +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;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseFeedSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesFeed;
}

14
tests/cases/Db/SQLite3/Database/TestDatabaseFolderSQLite3.php

@ -1,14 +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;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseFolderSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesFolder;
}

10
tests/cases/Db/SQLite3/Database/TestDatabaseLabelSQLite3.php

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseLabelSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesLabel;
}

14
tests/cases/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php

@ -1,14 +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;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseMetaSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesMeta;
}

14
tests/cases/Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php

@ -1,14 +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;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseMiscellanySQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesMiscellany;
}

10
tests/cases/Db/SQLite3/Database/TestDatabaseSessionSQLite3.php

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseSessionSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesSession;
}

14
tests/cases/Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php

@ -1,14 +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;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseSubscriptionSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesSubscription;
}

14
tests/cases/Db/SQLite3/Database/TestDatabaseUserSQLite3.php

@ -1,14 +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;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestDatabaseUserSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesUser;
}

14
tests/cases/Db/SQLite3/Database/TestFeed.php

@ -0,0 +1,14 @@
<?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\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesFeed;
}

14
tests/cases/Db/SQLite3/Database/TestFolder.php

@ -0,0 +1,14 @@
<?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\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestFolder extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesFolder;
}

10
tests/cases/Db/SQLite3/Database/TestLabel.php

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestLabel extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesLabel;
}

14
tests/cases/Db/SQLite3/Database/TestMeta.php

@ -0,0 +1,14 @@
<?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\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestMeta extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesMeta;
}

14
tests/cases/Db/SQLite3/Database/TestMiscellany.php

@ -0,0 +1,14 @@
<?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\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestMiscellany extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesMiscellany;
}

10
tests/cases/Db/SQLite3/Database/TestSession.php

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestSession extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesSession;
}

14
tests/cases/Db/SQLite3/Database/TestSubscription.php

@ -0,0 +1,14 @@
<?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\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestSubscription extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesSubscription;
}

14
tests/cases/Db/SQLite3/Database/TestUser.php

@ -0,0 +1,14 @@
<?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\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesUser;
}

32
tests/cases/Db/SQLite3/TestDbDriverCreationSQLite3.php → tests/cases/Db/SQLite3/TestCreation.php

@ -4,16 +4,18 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Db\SQLite3\Driver;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
use Phake; use Phake;
/** /**
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended> * @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */ * @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDbDriverCreationSQLite3 extends Test\AbstractTest { class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
protected $data; protected $data;
protected $drv; protected $drv;
protected $ch; protected $ch;
@ -117,78 +119,78 @@ class TestDbDriverCreationSQLite3 extends Test\AbstractTest {
public function testFailToCreateDatabase() { public function testFailToCreateDatabase() {
Arsse::$conf->dbSQLite3File = $this->path."Cmain/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Cmain/arsse.db";
$this->assertException("fileUncreatable", "Db"); $this->assertException("fileUncreatable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToCreateJournal() { public function testFailToCreateJournal() {
Arsse::$conf->dbSQLite3File = $this->path."Cwal/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Cwal/arsse.db";
$this->assertException("fileUncreatable", "Db"); $this->assertException("fileUncreatable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToCreateSharedMmeory() { public function testFailToCreateSharedMmeory() {
Arsse::$conf->dbSQLite3File = $this->path."Cshm/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Cshm/arsse.db";
$this->assertException("fileUncreatable", "Db"); $this->assertException("fileUncreatable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToReadDatabase() { public function testFailToReadDatabase() {
Arsse::$conf->dbSQLite3File = $this->path."Rmain/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Rmain/arsse.db";
$this->assertException("fileUnreadable", "Db"); $this->assertException("fileUnreadable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToReadJournal() { public function testFailToReadJournal() {
Arsse::$conf->dbSQLite3File = $this->path."Rwal/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Rwal/arsse.db";
$this->assertException("fileUnreadable", "Db"); $this->assertException("fileUnreadable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToReadSharedMmeory() { public function testFailToReadSharedMmeory() {
Arsse::$conf->dbSQLite3File = $this->path."Rshm/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Rshm/arsse.db";
$this->assertException("fileUnreadable", "Db"); $this->assertException("fileUnreadable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToWriteToDatabase() { public function testFailToWriteToDatabase() {
Arsse::$conf->dbSQLite3File = $this->path."Wmain/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Wmain/arsse.db";
$this->assertException("fileUnwritable", "Db"); $this->assertException("fileUnwritable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToWriteToJournal() { public function testFailToWriteToJournal() {
Arsse::$conf->dbSQLite3File = $this->path."Wwal/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Wwal/arsse.db";
$this->assertException("fileUnwritable", "Db"); $this->assertException("fileUnwritable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToWriteToSharedMmeory() { public function testFailToWriteToSharedMmeory() {
Arsse::$conf->dbSQLite3File = $this->path."Wshm/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Wshm/arsse.db";
$this->assertException("fileUnwritable", "Db"); $this->assertException("fileUnwritable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToAccessDatabase() { public function testFailToAccessDatabase() {
Arsse::$conf->dbSQLite3File = $this->path."Amain/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Amain/arsse.db";
$this->assertException("fileUnusable", "Db"); $this->assertException("fileUnusable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToAccessJournal() { public function testFailToAccessJournal() {
Arsse::$conf->dbSQLite3File = $this->path."Awal/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Awal/arsse.db";
$this->assertException("fileUnusable", "Db"); $this->assertException("fileUnusable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testFailToAccessSharedMmeory() { public function testFailToAccessSharedMmeory() {
Arsse::$conf->dbSQLite3File = $this->path."Ashm/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."Ashm/arsse.db";
$this->assertException("fileUnusable", "Db"); $this->assertException("fileUnusable", "Db");
new Db\SQLite3\Driver; new Driver;
} }
public function testAssumeDatabaseCorruption() { public function testAssumeDatabaseCorruption() {
Arsse::$conf->dbSQLite3File = $this->path."corrupt/arsse.db"; Arsse::$conf->dbSQLite3File = $this->path."corrupt/arsse.db";
$this->assertException("fileCorrupt", "Db"); $this->assertException("fileCorrupt", "Db");
new Db\SQLite3\Driver; new Driver;
} }
} }

19
tests/cases/Db/SQLite3/TestDbDriverSQLite3.php → tests/cases/Db/SQLite3/TestDriver.php

@ -4,12 +4,19 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Db\SQLite3\Driver;
use JKingWeb\Arsse\Db\SQLite3\Result;
use JKingWeb\Arsse\Db\SQLite3\Statement;
/** /**
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended> * @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */ * @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDbDriverSQLite3 extends Test\AbstractTest { class TestDriver extends \JKingWeb\Arsse\Test\AbstractTest {
protected $data; protected $data;
protected $drv; protected $drv;
protected $ch; protected $ch;
@ -21,10 +28,10 @@ class TestDbDriverSQLite3 extends Test\AbstractTest {
$this->clearData(); $this->clearData();
$conf = new Conf(); $conf = new Conf();
Arsse::$conf = $conf; Arsse::$conf = $conf;
$conf->dbDriver = Db\SQLite3\Driver::class; $conf->dbDriver = Driver::class;
$conf->dbSQLite3Timeout = 0; $conf->dbSQLite3Timeout = 0;
$conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook'); $conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook');
$this->drv = new Db\SQLite3\Driver(); $this->drv = new Driver();
$this->ch = new \SQLite3(Arsse::$conf->dbSQLite3File); $this->ch = new \SQLite3(Arsse::$conf->dbSQLite3File);
$this->ch->enableExceptions(true); $this->ch->enableExceptions(true);
} }
@ -80,7 +87,7 @@ class TestDbDriverSQLite3 extends Test\AbstractTest {
} }
public function testMakeAValidQuery() { public function testMakeAValidQuery() {
$this->assertInstanceOf(Db\Result::class, $this->drv->query("SELECT 1")); $this->assertInstanceOf(Result::class, $this->drv->query("SELECT 1"));
} }
public function testMakeAnInvalidQuery() { public function testMakeAnInvalidQuery() {
@ -108,7 +115,7 @@ class TestDbDriverSQLite3 extends Test\AbstractTest {
public function testPrepareAValidQuery() { public function testPrepareAValidQuery() {
$s = $this->drv->prepare("SELECT ?, ?", "int", "int"); $s = $this->drv->prepare("SELECT ?, ?", "int", "int");
$this->assertInstanceOf(Db\Statement::class, $s); $this->assertInstanceOf(Statement::class, $s);
} }
public function testPrepareAnInvalidQuery() { public function testPrepareAnInvalidQuery() {

22
tests/cases/Db/SQLite3/TestDbResultSQLite3.php → tests/cases/Db/SQLite3/TestResult.php

@ -4,10 +4,12 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Db\SQLite3\Result;
/** @covers \JKingWeb\Arsse\Db\SQLite3\Result<extended> */ /** @covers \JKingWeb\Arsse\Db\SQLite3\Result<extended> */
class TestDbResultSQLite3 extends Test\AbstractTest { class TestResult extends \JKingWeb\Arsse\Test\AbstractTest {
protected $c; protected $c;
public function setUp() { public function setUp() {
@ -26,7 +28,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testConstructResult() { public function testConstructResult() {
$set = $this->c->query("SELECT 1"); $set = $this->c->query("SELECT 1");
$this->assertInstanceOf(Db\Result::class, new Db\SQLite3\Result($set)); $this->assertInstanceOf(Result::class, new Result($set));
} }
public function testGetChangeCountAndLastInsertId() { public function testGetChangeCountAndLastInsertId() {
@ -34,7 +36,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
$set = $this->c->query("INSERT INTO test(col) values(1)"); $set = $this->c->query("INSERT INTO test(col) values(1)");
$rows = $this->c->changes(); $rows = $this->c->changes();
$id = $this->c->lastInsertRowID(); $id = $this->c->lastInsertRowID();
$r = new Db\SQLite3\Result($set, [$rows,$id]); $r = new Result($set, [$rows,$id]);
$this->assertEquals($rows, $r->changes()); $this->assertEquals($rows, $r->changes());
$this->assertEquals($id, $r->lastId()); $this->assertEquals($id, $r->lastId());
} }
@ -42,7 +44,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testIterateOverResults() { public function testIterateOverResults() {
$set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col"); $set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col");
$rows = []; $rows = [];
foreach (new Db\SQLite3\Result($set) as $index => $row) { foreach (new Result($set) as $index => $row) {
$rows[$index] = $row['col']; $rows[$index] = $row['col'];
} }
$this->assertEquals([0 => 1, 1 => 2, 2 => 3], $rows); $this->assertEquals([0 => 1, 1 => 2, 2 => 3], $rows);
@ -51,7 +53,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testIterateOverResultsTwice() { public function testIterateOverResultsTwice() {
$set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col"); $set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col");
$rows = []; $rows = [];
$test = new Db\SQLite3\Result($set); $test = new Result($set);
foreach ($test as $row) { foreach ($test as $row) {
$rows[] = $row['col']; $rows[] = $row['col'];
} }
@ -64,7 +66,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testGetSingleValues() { public function testGetSingleValues() {
$set = $this->c->query("SELECT 1867 as year union select 1970 as year union select 2112 as year"); $set = $this->c->query("SELECT 1867 as year union select 1970 as year union select 2112 as year");
$test = new Db\SQLite3\Result($set); $test = new Result($set);
$this->assertEquals(1867, $test->getValue()); $this->assertEquals(1867, $test->getValue());
$this->assertEquals(1970, $test->getValue()); $this->assertEquals(1970, $test->getValue());
$this->assertEquals(2112, $test->getValue()); $this->assertEquals(2112, $test->getValue());
@ -73,7 +75,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testGetFirstValuesOnly() { public function testGetFirstValuesOnly() {
$set = $this->c->query("SELECT 1867 as year, 19 as century union select 1970 as year, 20 as century union select 2112 as year, 22 as century"); $set = $this->c->query("SELECT 1867 as year, 19 as century union select 1970 as year, 20 as century union select 2112 as year, 22 as century");
$test = new Db\SQLite3\Result($set); $test = new Result($set);
$this->assertEquals(1867, $test->getValue()); $this->assertEquals(1867, $test->getValue());
$this->assertEquals(1970, $test->getValue()); $this->assertEquals(1970, $test->getValue());
$this->assertEquals(2112, $test->getValue()); $this->assertEquals(2112, $test->getValue());
@ -86,7 +88,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
['album' => '2112', 'track' => '2112'], ['album' => '2112', 'track' => '2112'],
['album' => 'Clockwork Angels', 'track' => 'The Wreckers'], ['album' => 'Clockwork Angels', 'track' => 'The Wreckers'],
]; ];
$test = new Db\SQLite3\Result($set); $test = new Result($set);
$this->assertEquals($rows[0], $test->getRow()); $this->assertEquals($rows[0], $test->getRow());
$this->assertEquals($rows[1], $test->getRow()); $this->assertEquals($rows[1], $test->getRow());
$this->assertSame(null, $test->getRow()); $this->assertSame(null, $test->getRow());
@ -98,7 +100,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
['album' => '2112', 'track' => '2112'], ['album' => '2112', 'track' => '2112'],
['album' => 'Clockwork Angels', 'track' => 'The Wreckers'], ['album' => 'Clockwork Angels', 'track' => 'The Wreckers'],
]; ];
$test = new Db\SQLite3\Result($set); $test = new Result($set);
$this->assertEquals($rows, $test->getAll()); $this->assertEquals($rows, $test->getAll());
} }
} }

10
tests/cases/Db/SQLite3/TestDbStatementSQLite3.php → tests/cases/Db/SQLite3/TestStatement.php

@ -4,18 +4,18 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Db\Statement; use JKingWeb\Arsse\Db\Statement;
/** /**
* @covers \JKingWeb\Arsse\Db\SQLite3\Statement<extended> * @covers \JKingWeb\Arsse\Db\SQLite3\Statement<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */ * @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDbStatementSQLite3 extends Test\AbstractTest { class TestStatement extends \JKingWeb\Arsse\Test\AbstractTest {
use Test\Db\BindingTests; use \JKingWeb\Arsse\Test\Db\BindingTests;
protected $c; protected $c;
protected static $imp = Db\SQLite3\Statement::class; protected static $imp = \JKingWeb\Arsse\Db\SQLite3\Statement::class;
public function setUp() { public function setUp() {
$this->clearData(); $this->clearData();
@ -48,7 +48,7 @@ class TestDbStatementSQLite3 extends Test\AbstractTest {
public function testConstructStatement() { public function testConstructStatement() {
$nativeStatement = $this->c->prepare("SELECT ? as value"); $nativeStatement = $this->c->prepare("SELECT ? as value");
$this->assertInstanceOf(Statement::class, new Db\SQLite3\Statement($this->c, $nativeStatement)); $this->assertInstanceOf(Statement::class, new \JKingWeb\Arsse\Db\SQLite3\Statement($this->c, $nativeStatement));
} }
public function testBindMissingValue() { public function testBindMissingValue() {

13
tests/cases/Db/SQLite3/TestDbUpdateSQLite3.php → tests/cases/Db/SQLite3/TestUpdate.php

@ -4,14 +4,19 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Db\Exception;
use JKingWeb\Arsse\Db\SQLite3\Driver;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
/** /**
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended> * @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */ * @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDbUpdateSQLite3 extends Test\AbstractTest { class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
protected $data; protected $data;
protected $drv; protected $drv;
protected $vfs; protected $vfs;
@ -29,12 +34,12 @@ class TestDbUpdateSQLite3 extends Test\AbstractTest {
if (!$conf) { if (!$conf) {
$conf = new Conf(); $conf = new Conf();
} }
$conf->dbDriver = Db\SQLite3\Driver::class; $conf->dbDriver = Driver::class;
$conf->dbSQLite3File = ":memory:"; $conf->dbSQLite3File = ":memory:";
Arsse::$conf = $conf; Arsse::$conf = $conf;
$this->base = $this->vfs->url(); $this->base = $this->vfs->url();
$this->path = $this->base."/SQLite3/"; $this->path = $this->base."/SQLite3/";
$this->drv = new Db\SQLite3\Driver(); $this->drv = new Driver();
} }
public function tearDown() { public function tearDown() {

19
tests/cases/Db/TestResultAggregate.php

@ -1,18 +1,19 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Db;
use JKingWeb\Arsse\Db\ResultAggregate;
use JKingWeb\Arsse\Test\Result; use JKingWeb\Arsse\Test\Result;
/** @covers \JKingWeb\Arsse\Db\ResultAggregate<extended> */ /** @covers \JKingWeb\Arsse\Db\ResultAggregate<extended> */
class TestResultAggregate extends Test\AbstractTest { class TestResultAggregate extends \JKingWeb\Arsse\Test\AbstractTest {
public function testGetChangeCountAndLastInsertId() { public function testGetChangeCountAndLastInsertId() {
$in = [ $in = [
new Result([], 3, 4), new Result([], 3, 4),
new Result([], 27, 10), new Result([], 27, 10),
new Result([], 12, 2112), new Result([], 12, 2112),
]; ];
$r = new Db\ResultAggregate(...$in); $r = new ResultAggregate(...$in);
$this->assertEquals(42, $r->changes()); $this->assertEquals(42, $r->changes());
$this->assertEquals(2112, $r->lastId()); $this->assertEquals(2112, $r->lastId());
} }
@ -24,7 +25,7 @@ class TestResultAggregate extends Test\AbstractTest {
new Result([['col' => 3]]), new Result([['col' => 3]]),
]; ];
$rows = []; $rows = [];
foreach (new Db\ResultAggregate(...$in) as $index => $row) { foreach (new ResultAggregate(...$in) as $index => $row) {
$rows[$index] = $row['col']; $rows[$index] = $row['col'];
} }
$this->assertEquals([0 => 1, 1 => 2, 2 => 3], $rows); $this->assertEquals([0 => 1, 1 => 2, 2 => 3], $rows);
@ -37,7 +38,7 @@ class TestResultAggregate extends Test\AbstractTest {
new Result([['col' => 3]]), new Result([['col' => 3]]),
]; ];
$rows = []; $rows = [];
$test = new Db\ResultAggregate(...$in); $test = new ResultAggregate(...$in);
foreach ($test as $row) { foreach ($test as $row) {
$rows[] = $row['col']; $rows[] = $row['col'];
} }
@ -49,7 +50,7 @@ class TestResultAggregate extends Test\AbstractTest {
} }
public function testGetSingleValues() { public function testGetSingleValues() {
$test = new Db\ResultAggregate(...[ $test = new ResultAggregate(...[
new Result([['year' => 1867]]), new Result([['year' => 1867]]),
new Result([['year' => 1970]]), new Result([['year' => 1970]]),
new Result([['year' => 2112]]), new Result([['year' => 2112]]),
@ -61,7 +62,7 @@ class TestResultAggregate extends Test\AbstractTest {
} }
public function testGetFirstValuesOnly() { public function testGetFirstValuesOnly() {
$test = new Db\ResultAggregate(...[ $test = new ResultAggregate(...[
new Result([['year' => 1867, 'century' => 19]]), new Result([['year' => 1867, 'century' => 19]]),
new Result([['year' => 1970, 'century' => 20]]), new Result([['year' => 1970, 'century' => 20]]),
new Result([['year' => 2112, 'century' => 22]]), new Result([['year' => 2112, 'century' => 22]]),
@ -73,7 +74,7 @@ class TestResultAggregate extends Test\AbstractTest {
} }
public function testGetRows() { public function testGetRows() {
$test = new Db\ResultAggregate(...[ $test = new ResultAggregate(...[
new Result([['album' => '2112', 'track' => '2112']]), new Result([['album' => '2112', 'track' => '2112']]),
new Result([['album' => 'Clockwork Angels', 'track' => 'The Wreckers']]), new Result([['album' => 'Clockwork Angels', 'track' => 'The Wreckers']]),
]); ]);
@ -87,7 +88,7 @@ class TestResultAggregate extends Test\AbstractTest {
} }
public function testGetAllRows() { public function testGetAllRows() {
$test = new Db\ResultAggregate(...[ $test = new ResultAggregate(...[
new Result([['album' => '2112', 'track' => '2112']]), new Result([['album' => '2112', 'track' => '2112']]),
new Result([['album' => 'Clockwork Angels', 'track' => 'The Wreckers']]), new Result([['album' => 'Clockwork Angels', 'track' => 'The Wreckers']]),
]); ]);

16
tests/cases/Db/TestResultEmpty.php

@ -1,35 +1,37 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Db;
use JKingWeb\Arsse\Db\ResultEmpty;
/** @covers \JKingWeb\Arsse\Db\ResultEmpty<extended> */ /** @covers \JKingWeb\Arsse\Db\ResultEmpty<extended> */
class TestResultEmpty extends Test\AbstractTest { class TestResultEmpty extends \JKingWeb\Arsse\Test\AbstractTest {
public function testGetChangeCountAndLastInsertId() { public function testGetChangeCountAndLastInsertId() {
$r = new Db\ResultEmpty; $r = new ResultEmpty;
$this->assertEquals(0, $r->changes()); $this->assertEquals(0, $r->changes());
$this->assertEquals(0, $r->lastId()); $this->assertEquals(0, $r->lastId());
} }
public function testIterateOverResults() { public function testIterateOverResults() {
$rows = []; $rows = [];
foreach (new Db\ResultEmpty as $index => $row) { foreach (new ResultEmpty as $index => $row) {
$rows[$index] = $row['col']; $rows[$index] = $row['col'];
} }
$this->assertEquals([], $rows); $this->assertEquals([], $rows);
} }
public function testGetSingleValues() { public function testGetSingleValues() {
$test = new Db\ResultEmpty; $test = new ResultEmpty;
$this->assertSame(null, $test->getValue()); $this->assertSame(null, $test->getValue());
} }
public function testGetRows() { public function testGetRows() {
$test = new Db\ResultEmpty; $test = new ResultEmpty;
$this->assertSame(null, $test->getRow()); $this->assertSame(null, $test->getRow());
} }
public function testGetAllRows() { public function testGetAllRows() {
$test = new Db\ResultEmpty; $test = new ResultEmpty;
$rows = []; $rows = [];
$this->assertEquals($rows, $test->getAll()); $this->assertEquals($rows, $test->getAll());
} }

9
tests/cases/Db/TestTransaction.php

@ -4,19 +4,20 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Db;
use JKingWeb\Arsse\Db\Transaction; use JKingWeb\Arsse\Db\Transaction;
use JKingWeb\Arsse\Db\Exception;
use Phake; use Phake;
/** /**
* @covers \JKingWeb\Arsse\Db\Transaction */ * @covers \JKingWeb\Arsse\Db\Transaction */
class TestTransaction extends Test\AbstractTest { class TestTransaction extends \JKingWeb\Arsse\Test\AbstractTest {
protected $drv; protected $drv;
public function setUp() { public function setUp() {
$this->clearData(); $this->clearData();
$drv = Phake::mock(Db\SQLite3\Driver::class); $drv = Phake::mock(\JKingWeb\Arsse\Db\SQLite3\Driver::class);
Phake::when($drv)->savepointRelease->thenReturn(true); Phake::when($drv)->savepointRelease->thenReturn(true);
Phake::when($drv)->savepointUndo->thenReturn(true); Phake::when($drv)->savepointUndo->thenReturn(true);
Phake::when($drv)->savepointCreate->thenReturn(1)->thenReturn(2); Phake::when($drv)->savepointCreate->thenReturn(1)->thenReturn(2);
@ -51,7 +52,7 @@ class TestTransaction extends Test\AbstractTest {
} }
public function testIgnoreRollbackErrors() { public function testIgnoreRollbackErrors() {
Phake::when($this->drv)->savepointUndo->thenThrow(new Db\Exception("savepointStale")); Phake::when($this->drv)->savepointUndo->thenThrow(new Exception("savepointStale"));
$tr1 = new Transaction($this->drv); $tr1 = new Transaction($this->drv);
$tr2 = new Transaction($this->drv); $tr2 = new Transaction($this->drv);
unset($tr1, $tr2); // no exception should bubble up unset($tr1, $tr2); // no exception should bubble up

14
tests/cases/Exception/TestException.php

@ -4,12 +4,16 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Exception;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Lang;
use JKingWeb\Arsse\Exception;
use JKingWeb\Arsse\Lang\Exception as LangException;
use Phake; use Phake;
/** @covers \JKingWeb\Arsse\AbstractException */ /** @covers \JKingWeb\Arsse\AbstractException */
class TestException extends Test\AbstractTest { class TestException extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() { public function setUp() {
$this->clearData(false); $this->clearData(false);
// create a mock Lang object so as not to create a dependency loop // create a mock Lang object so as not to create a dependency loop
@ -43,7 +47,7 @@ class TestException extends Test\AbstractTest {
*/ */
public function testDerivedClass() { public function testDerivedClass() {
$this->assertException("fileMissing", "Lang"); $this->assertException("fileMissing", "Lang");
throw new Lang\Exception("fileMissing"); throw new LangException("fileMissing");
} }
/** /**
@ -51,7 +55,7 @@ class TestException extends Test\AbstractTest {
*/ */
public function testDerivedClassWithMessageParameters() { public function testDerivedClassWithMessageParameters() {
$this->assertException("fileMissing", "Lang"); $this->assertException("fileMissing", "Lang");
throw new Lang\Exception("fileMissing", "en"); throw new LangException("fileMissing", "en");
} }
/** /**
@ -67,6 +71,6 @@ class TestException extends Test\AbstractTest {
*/ */
public function testDerivedClassWithMissingMessage() { public function testDerivedClassWithMissingMessage() {
$this->assertException("uncoded"); $this->assertException("uncoded");
throw new Lang\Exception("testThisExceptionMessageDoesNotExist"); throw new LangException("testThisExceptionMessageDoesNotExist");
} }
} }

15
tests/cases/Feed/TestFeed.php

@ -4,16 +4,21 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Feed;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Feed;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Misc\Date; use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Test\Result;
use Phake; use Phake;
/** /**
* @covers \JKingWeb\Arsse\Feed * @covers \JKingWeb\Arsse\Feed
* @covers \JKingWeb\Arsse\Feed\Exception * @covers \JKingWeb\Arsse\Feed\Exception
* @group slow */ * @group slow */
class TestFeed extends Test\AbstractTest { class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
protected static $host = "http://localhost:8000/"; protected static $host = "http://localhost:8000/";
protected $base = ""; protected $base = "";
protected $latest = [ protected $latest = [
@ -329,7 +334,7 @@ class TestFeed extends Test\AbstractTest {
} }
public function testMatchLatestArticles() { public function testMatchLatestArticles() {
Phake::when(Arsse::$db)->feedMatchLatest(1, $this->anything())->thenReturn(new Test\Result($this->latest)); Phake::when(Arsse::$db)->feedMatchLatest(1, $this->anything())->thenReturn(new Result($this->latest));
$f = new Feed(1, $this->base."Matching/1"); $f = new Feed(1, $this->base."Matching/1");
$this->assertCount(0, $f->newItems); $this->assertCount(0, $f->newItems);
$this->assertCount(0, $f->changedItems); $this->assertCount(0, $f->changedItems);
@ -345,8 +350,8 @@ class TestFeed extends Test\AbstractTest {
} }
public function testMatchHistoricalArticles() { public function testMatchHistoricalArticles() {
Phake::when(Arsse::$db)->feedMatchLatest(1, $this->anything())->thenReturn(new Test\Result($this->latest)); Phake::when(Arsse::$db)->feedMatchLatest(1, $this->anything())->thenReturn(new Result($this->latest));
Phake::when(Arsse::$db)->feedMatchIds(1, $this->anything(), $this->anything(), $this->anything(), $this->anything())->thenReturn(new Test\Result($this->others)); Phake::when(Arsse::$db)->feedMatchIds(1, $this->anything(), $this->anything(), $this->anything(), $this->anything())->thenReturn(new Result($this->others));
$f = new Feed(1, $this->base."Matching/5"); $f = new Feed(1, $this->base."Matching/5");
$this->assertCount(0, $f->newItems); $this->assertCount(0, $f->newItems);
$this->assertCount(0, $f->changedItems); $this->assertCount(0, $f->changedItems);

7
tests/cases/Feed/TestFeedFetching.php → tests/cases/Feed/TestFetching.php

@ -4,14 +4,17 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Feed;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Feed;
use Phake; use Phake;
/** /**
* @covers \JKingWeb\Arsse\Feed * @covers \JKingWeb\Arsse\Feed
* @group slow */ * @group slow */
class TestFeedFetching extends Test\AbstractTest { class TestFetching extends \JKingWeb\Arsse\Test\AbstractTest {
protected static $host = "http://localhost:8000/"; protected static $host = "http://localhost:8000/";
protected $base = ""; protected $base = "";

14
tests/cases/Lang/TestLang.php → tests/cases/Lang/TestBasic.php

@ -4,13 +4,15 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Lang;
use JKingWeb\Arsse\Lang as TestClass;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\Lang */ /** @covers \JKingWeb\Arsse\Lang */
class TestLang extends Test\AbstractTest { class TestBasic extends \JKingWeb\Arsse\Test\AbstractTest {
use Test\Lang\Setup; use \JKingWeb\Arsse\Test\Lang\Setup;
public $files; public $files;
public $path; public $path;
@ -38,14 +40,14 @@ class TestLang extends Test\AbstractTest {
*/ */
public function testLoadInternalStrings() { public function testLoadInternalStrings() {
$this->assertEquals("", $this->l->set("", true)); $this->assertEquals("", $this->l->set("", true));
$this->assertCount(sizeof(Lang::REQUIRED), $this->l->dump()); $this->assertCount(sizeof(TestClass::REQUIRED), $this->l->dump());
} }
/** /**
* @depends testLoadInternalStrings * @depends testLoadInternalStrings
*/ */
public function testLoadDefaultLanguage() { public function testLoadDefaultLanguage() {
$this->assertEquals(Lang::DEFAULT, $this->l->set(Lang::DEFAULT, true)); $this->assertEquals(TestClass::DEFAULT, $this->l->set(TestClass::DEFAULT, true));
$str = $this->l->dump(); $str = $this->l->dump();
$this->assertArrayHasKey('Exception.JKingWeb/Arsse/Exception.uncoded', $str); $this->assertArrayHasKey('Exception.JKingWeb/Arsse/Exception.uncoded', $str);
$this->assertArrayHasKey('Test.presentText', $str); $this->assertArrayHasKey('Test.presentText', $str);
@ -55,7 +57,7 @@ class TestLang extends Test\AbstractTest {
* @depends testLoadDefaultLanguage * @depends testLoadDefaultLanguage
*/ */
public function testLoadSupplementaryLanguage() { public function testLoadSupplementaryLanguage() {
$this->l->set(Lang::DEFAULT, true); $this->l->set(TestClass::DEFAULT, true);
$this->assertEquals("ja", $this->l->set("ja", true)); $this->assertEquals("ja", $this->l->set("ja", true));
$str = $this->l->dump(); $str = $this->l->dump();
$this->assertArrayHasKey('Exception.JKingWeb/Arsse/Exception.uncoded', $str); $this->assertArrayHasKey('Exception.JKingWeb/Arsse/Exception.uncoded', $str);

9
tests/cases/Lang/TestLangErrors.php → tests/cases/Lang/TestErrors.php

@ -4,13 +4,14 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Lang;
use JKingWeb\Arsse\Lang as TestClass;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\Lang */ /** @covers \JKingWeb\Arsse\Lang */
class TestLangErrors extends Test\AbstractTest { class TestErrors extends \JKingWeb\Arsse\Test\AbstractTest {
use Test\Lang\Setup; use \JKingWeb\Arsse\Test\Lang\Setup;
public $files; public $files;
public $path; public $path;
@ -62,7 +63,7 @@ class TestLangErrors extends Test\AbstractTest {
} }
public function testLoadMissingDefaultLanguage() { public function testLoadMissingDefaultLanguage() {
unlink($this->path.Lang::DEFAULT.".php"); unlink($this->path.TestClass::DEFAULT.".php");
$this->assertException("defaultFileMissing", "Lang"); $this->assertException("defaultFileMissing", "Lang");
$this->l->set("fr", true); $this->l->set("fr", true);
} }

11
tests/cases/Lang/testLangComplex.php → tests/cases/Lang/testComplex.php

@ -4,20 +4,21 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Lang;
use JKingWeb\Arsse\Lang as TestClass;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\Lang */ /** @covers \JKingWeb\Arsse\Lang */
class TestLangComplex extends Test\AbstractTest { class TestComplex extends \JKingWeb\Arsse\Test\AbstractTest {
use Test\Lang\Setup; use \JKingWeb\Arsse\Test\Lang\Setup;
public $files; public $files;
public $path; public $path;
public $l; public $l;
public function setUpSeries() { public function setUpSeries() {
$this->l->set(Lang::DEFAULT, true); $this->l->set(TestClass::DEFAULT, true);
} }
public function testLazyLoad() { public function testLazyLoad() {
@ -68,7 +69,7 @@ class TestLangComplex extends Test\AbstractTest {
*/ */
public function testFetchAMessageWithSingleNumericParameter() { public function testFetchAMessageWithSingleNumericParameter() {
$this->l->set("en_ca", true); $this->l->set("en_ca", true);
$this->assertEquals('Default language file "en" missing', $this->l->msg('Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing', Lang::DEFAULT)); $this->assertEquals('Default language file "en" missing', $this->l->msg('Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing', TestClass::DEFAULT));
} }
/** /**

4
tests/cases/Misc/TestContext.php

@ -4,12 +4,12 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Misc;
use JKingWeb\Arsse\Misc\Context; use JKingWeb\Arsse\Misc\Context;
/** @covers \JKingWeb\Arsse\Misc\Context */ /** @covers \JKingWeb\Arsse\Misc\Context */
class TestContext extends Test\AbstractTest { class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
public function testVerifyInitialState() { public function testVerifyInitialState() {
$c = new Context; $c = new Context;
foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) { foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {

12
tests/cases/Misc/TestValueInfo.php

@ -4,13 +4,15 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Misc;
use JKingWeb\Arsse\ExceptionType;
use JKingWeb\Arsse\Misc\ValueInfo as I; use JKingWeb\Arsse\Misc\ValueInfo as I;
use JKingWeb\Arsse\Test\Misc\StrClass; use JKingWeb\Arsse\Test\Misc\StrClass;
use JKingWeb\Arsse\Test\Result;
/** @covers \JKingWeb\Arsse\Misc\ValueInfo */ /** @covers \JKingWeb\Arsse\Misc\ValueInfo */
class TestValueInfo extends Test\AbstractTest { class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() { public function setUp() {
$this->clearData(); $this->clearData();
} }
@ -398,7 +400,7 @@ class TestValueInfo extends Test\AbstractTest {
[1e-6, [null,true], [true, false], [0, false], [1e-6, true], ["0.000001", true], [[1e-6], false]], [1e-6, [null,true], [true, false], [0, false], [1e-6, true], ["0.000001", true], [[1e-6], false]],
[[1,2,3], [null,true], [true, false], [0, false], [0.0, false], ["", false], [[1,2,3], true] ], [[1,2,3], [null,true], [true, false], [0, false], [0.0, false], ["", false], [[1,2,3], true] ],
[['a'=>1,'b'=>2], [null,true], [true, false], [0, false], [0.0, false], ["", false], [['a'=>1,'b'=>2], true] ], [['a'=>1,'b'=>2], [null,true], [true, false], [0, false], [0.0, false], ["", false], [['a'=>1,'b'=>2], true] ],
[new Test\Result([['a'=>1,'b'=>2]]), [null,true], [true, false], [0, false], [0.0, false], ["", false], [[['a'=>1,'b'=>2]], true] ], [new Result([['a'=>1,'b'=>2]]), [null,true], [true, false], [0, false], [0.0, false], ["", false], [[['a'=>1,'b'=>2]], true] ],
]; ];
$params = [ $params = [
[I::T_MIXED, "Mixed" ], [I::T_MIXED, "Mixed" ],
@ -496,8 +498,8 @@ class TestValueInfo extends Test\AbstractTest {
} }
// Array-mode tests // Array-mode tests
$tests = [ $tests = [
[I::T_INT | I::M_DROP, new Test\Result([1, 2, 2.2, 3]), [1,2,null,3] ], [I::T_INT | I::M_DROP, new Result([1, 2, 2.2, 3]), [1,2,null,3] ],
[I::T_INT, new Test\Result([1, 2, 2.2, 3]), [1,2,2,3] ], [I::T_INT, new Result([1, 2, 2.2, 3]), [1,2,2,3] ],
[I::T_STRING | I::M_STRICT, "Bare string", ["Bare string"]], [I::T_STRING | I::M_STRICT, "Bare string", ["Bare string"]],
]; ];
foreach ($tests as $index => $test) { foreach ($tests as $index => $test) {

18
tests/cases/REST/NextCloudNews/TestNCNV1_2.php → tests/cases/REST/NextCloudNews/TestV1_2.php

@ -4,8 +4,13 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\REST\NextCloudNews;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\REST\Request; use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\REST\Response; use JKingWeb\Arsse\REST\Response;
use JKingWeb\Arsse\Test\Result; use JKingWeb\Arsse\Test\Result;
@ -13,10 +18,11 @@ use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Misc\Context; use JKingWeb\Arsse\Misc\Context;
use JKingWeb\Arsse\Db\ExceptionInput; use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Db\Transaction; use JKingWeb\Arsse\Db\Transaction;
use JKingWeb\Arsse\REST\NextCloudNews\V1_2;
use Phake; use Phake;
/** @covers \JKingWeb\Arsse\REST\NextCloudNews\V1_2<extended> */ /** @covers \JKingWeb\Arsse\REST\NextCloudNews\V1_2<extended> */
class TestNCNV1_2 extends Test\AbstractTest { class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
protected $h; protected $h;
protected $feeds = [ // expected sample output of a feed list from the database, and the resultant expected transformation by the REST handler protected $feeds = [ // expected sample output of a feed list from the database, and the resultant expected transformation by the REST handler
'db' => [ 'db' => [
@ -304,7 +310,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
// create a mock database interface // create a mock database interface
Arsse::$db = Phake::mock(Database::class); Arsse::$db = Phake::mock(Database::class);
Phake::when(Arsse::$db)->begin->thenReturn(Phake::mock(Transaction::class)); Phake::when(Arsse::$db)->begin->thenReturn(Phake::mock(Transaction::class));
$this->h = new REST\NextCloudNews\V1_2(); $this->h = new V1_2();
} }
public function tearDown() { public function tearDown() {
@ -318,7 +324,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
public function testSendAuthenticationChallenge() { public function testSendAuthenticationChallenge() {
Phake::when(Arsse::$user)->authHTTP->thenReturn(false); Phake::when(Arsse::$user)->authHTTP->thenReturn(false);
$exp = new Response(401, "", "", ['WWW-Authenticate: Basic realm="'.REST\NextCloudNews\V1_2::REALM.'"']); $exp = new Response(401, "", "", ['WWW-Authenticate: Basic realm="'.V1_2::REALM.'"']);
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/"))); $this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/")));
} }
@ -496,7 +502,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
public function testRetrieveServerVersion() { public function testRetrieveServerVersion() {
$exp = new Response(200, [ $exp = new Response(200, [
'version' => REST\NextCloudNews\V1_2::VERSION, 'version' => V1_2::VERSION,
'arsse_version' => Arsse::VERSION, 'arsse_version' => Arsse::VERSION,
]); ]);
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/version"))); $this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/version")));
@ -867,7 +873,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
Phake::when(Arsse::$db)->metaGet("service_last_checkin")->thenReturn(Date::transform($valid, "sql"))->thenReturn(Date::transform($invalid, "sql")); Phake::when(Arsse::$db)->metaGet("service_last_checkin")->thenReturn(Date::transform($valid, "sql"))->thenReturn(Date::transform($invalid, "sql"));
Phake::when(Arsse::$db)->driverCharsetAcceptable->thenReturn(true)->thenReturn(false); Phake::when(Arsse::$db)->driverCharsetAcceptable->thenReturn(true)->thenReturn(false);
$arr1 = $arr2 = [ $arr1 = $arr2 = [
'version' => REST\NextCloudNews\V1_2::VERSION, 'version' => V1_2::VERSION,
'arsse_version' => Arsse::VERSION, 'arsse_version' => Arsse::VERSION,
'warnings' => [ 'warnings' => [
'improperlyConfiguredCron' => false, 'improperlyConfiguredCron' => false,

13
tests/cases/REST/NextCloudNews/TestNCNVersionDiscovery.php → tests/cases/REST/NextCloudNews/TestVersions.php

@ -4,20 +4,21 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\REST\NextCloudNews;
use JKingWeb\Arsse\REST\NextCloudNews\Versions;
use JKingWeb\Arsse\REST\Request; use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\REST\Response; use JKingWeb\Arsse\REST\Response;
/** @covers \JKingWeb\Arsse\REST\NextCloudNews\Versions */ /** @covers \JKingWeb\Arsse\REST\NextCloudNews\Versions */
class TestNCNVersionDiscovery extends Test\AbstractTest { class TestVersions extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() { public function setUp() {
$this->clearData(); $this->clearData();
} }
public function testFetchVersionList() { public function testFetchVersionList() {
$exp = new Response(200, ['apiLevels' => ['v1-2']]); $exp = new Response(200, ['apiLevels' => ['v1-2']]);
$h = new REST\NextCloudNews\Versions(); $h = new Versions;
$req = new Request("GET", "/"); $req = new Request("GET", "/");
$res = $h->dispatch($req); $res = $h->dispatch($req);
$this->assertEquals($exp, $res); $this->assertEquals($exp, $res);
@ -31,7 +32,7 @@ class TestNCNVersionDiscovery extends Test\AbstractTest {
public function testRespondToOptionsRequest() { public function testRespondToOptionsRequest() {
$exp = new Response(204, "", "", ["Allow: HEAD,GET"]); $exp = new Response(204, "", "", ["Allow: HEAD,GET"]);
$h = new REST\NextCloudNews\Versions(); $h = new Versions;
$req = new Request("OPTIONS", "/"); $req = new Request("OPTIONS", "/");
$res = $h->dispatch($req); $res = $h->dispatch($req);
$this->assertEquals($exp, $res); $this->assertEquals($exp, $res);
@ -39,7 +40,7 @@ class TestNCNVersionDiscovery extends Test\AbstractTest {
public function testUseIncorrectMethod() { public function testUseIncorrectMethod() {
$exp = new Response(405, "", "", ["Allow: HEAD,GET"]); $exp = new Response(405, "", "", ["Allow: HEAD,GET"]);
$h = new REST\NextCloudNews\Versions(); $h = new Versions;
$req = new Request("POST", "/"); $req = new Request("POST", "/");
$res = $h->dispatch($req); $res = $h->dispatch($req);
$this->assertEquals($exp, $res); $this->assertEquals($exp, $res);
@ -47,7 +48,7 @@ class TestNCNVersionDiscovery extends Test\AbstractTest {
public function testUseIncorrectPath() { public function testUseIncorrectPath() {
$exp = new Response(404); $exp = new Response(404);
$h = new REST\NextCloudNews\Versions(); $h = new Versions;
$req = new Request("GET", "/ook"); $req = new Request("GET", "/ook");
$res = $h->dispatch($req); $res = $h->dispatch($req);
$this->assertEquals($exp, $res); $this->assertEquals($exp, $res);

11
tests/cases/REST/TinyTinyRSS/TestTinyTinyAPI.php → tests/cases/REST/TinyTinyRSS/TestAPI.php

@ -4,8 +4,13 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\REST\TinyTinyRSS;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\REST\Request; use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\REST\Response; use JKingWeb\Arsse\REST\Response;
use JKingWeb\Arsse\Test\Result; use JKingWeb\Arsse\Test\Result;
@ -18,7 +23,7 @@ use Phake;
/** @covers \JKingWeb\Arsse\REST\TinyTinyRSS\API<extended> /** @covers \JKingWeb\Arsse\REST\TinyTinyRSS\API<extended>
* @covers \JKingWeb\Arsse\REST\TinyTinyRSS\Exception */ * @covers \JKingWeb\Arsse\REST\TinyTinyRSS\Exception */
class TestTinyTinyAPI extends Test\AbstractTest { class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
protected $h; protected $h;
protected $folders = [ protected $folders = [
['id' => 5, 'parent' => 3, 'children' => 0, 'feeds' => 1, 'name' => "Local"], ['id' => 5, 'parent' => 3, 'children' => 0, 'feeds' => 1, 'name' => "Local"],
@ -161,7 +166,7 @@ LONG_STRING;
'expires' => "2112-12-21 21:12:00", 'expires' => "2112-12-21 21:12:00",
'user' => Arsse::$user->id, 'user' => Arsse::$user->id,
]); ]);
$this->h = new REST\TinyTinyRSS\API(); $this->h = new API();
} }
public function tearDown() { public function tearDown() {

11
tests/cases/REST/TinyTinyRSS/TestTinyTinyIcon.php → tests/cases/REST/TinyTinyRSS/TestIcon.php

@ -4,14 +4,19 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\REST\TinyTinyRSS;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\REST\TinyTinyRSS\Icon;
use JKingWeb\Arsse\REST\Request; use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\REST\Response; use JKingWeb\Arsse\REST\Response;
use Phake; use Phake;
/** @covers \JKingWeb\Arsse\REST\TinyTinyRSS\Icon<extended> */ /** @covers \JKingWeb\Arsse\REST\TinyTinyRSS\Icon<extended> */
class TestTinyTinyIcon extends Test\AbstractTest { class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
protected $h; protected $h;
public function setUp() { public function setUp() {
@ -20,7 +25,7 @@ class TestTinyTinyIcon extends Test\AbstractTest {
// create a mock user manager // create a mock user manager
// create a mock database interface // create a mock database interface
Arsse::$db = Phake::mock(Database::class); Arsse::$db = Phake::mock(Database::class);
$this->h = new REST\TinyTinyRSS\Icon(); $this->h = new Icon();
} }
public function tearDown() { public function tearDown() {

8
tests/cases/Service/TestService.php

@ -4,13 +4,17 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\Service;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\Misc\Date; use JKingWeb\Arsse\Misc\Date;
use Phake; use Phake;
/** @covers \JKingWeb\Arsse\Service */ /** @covers \JKingWeb\Arsse\Service */
class TestService extends Test\AbstractTest { class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
protected $srv; protected $srv;
public function setUp() { public function setUp() {

79
tests/cases/User/TestAuthorization.php

@ -4,42 +4,47 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\User;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\User\Driver;
use Phake; use Phake;
/** @covers \JKingWeb\Arsse\User */ /** @covers \JKingWeb\Arsse\User */
class TestAuthorization extends Test\AbstractTest { class TestAuthorization extends \JKingWeb\Arsse\Test\AbstractTest {
const USERS = [ const USERS = [
'user@example.com' => User\Driver::RIGHTS_NONE, 'user@example.com' => Driver::RIGHTS_NONE,
'user@example.org' => User\Driver::RIGHTS_NONE, 'user@example.org' => Driver::RIGHTS_NONE,
'dman@example.com' => User\Driver::RIGHTS_DOMAIN_MANAGER, 'dman@example.com' => Driver::RIGHTS_DOMAIN_MANAGER,
'dman@example.org' => User\Driver::RIGHTS_DOMAIN_MANAGER, 'dman@example.org' => Driver::RIGHTS_DOMAIN_MANAGER,
'dadm@example.com' => User\Driver::RIGHTS_DOMAIN_ADMIN, 'dadm@example.com' => Driver::RIGHTS_DOMAIN_ADMIN,
'dadm@example.org' => User\Driver::RIGHTS_DOMAIN_ADMIN, 'dadm@example.org' => Driver::RIGHTS_DOMAIN_ADMIN,
'gman@example.com' => User\Driver::RIGHTS_GLOBAL_MANAGER, 'gman@example.com' => Driver::RIGHTS_GLOBAL_MANAGER,
'gman@example.org' => User\Driver::RIGHTS_GLOBAL_MANAGER, 'gman@example.org' => Driver::RIGHTS_GLOBAL_MANAGER,
'gadm@example.com' => User\Driver::RIGHTS_GLOBAL_ADMIN, 'gadm@example.com' => Driver::RIGHTS_GLOBAL_ADMIN,
'gadm@example.org' => User\Driver::RIGHTS_GLOBAL_ADMIN, 'gadm@example.org' => Driver::RIGHTS_GLOBAL_ADMIN,
// invalid rights levels // invalid rights levels
'bad1@example.com' => User\Driver::RIGHTS_NONE+1, 'bad1@example.com' => Driver::RIGHTS_NONE+1,
'bad1@example.org' => User\Driver::RIGHTS_NONE+1, 'bad1@example.org' => Driver::RIGHTS_NONE+1,
'bad2@example.com' => User\Driver::RIGHTS_DOMAIN_MANAGER+1, 'bad2@example.com' => Driver::RIGHTS_DOMAIN_MANAGER+1,
'bad2@example.org' => User\Driver::RIGHTS_DOMAIN_MANAGER+1, 'bad2@example.org' => Driver::RIGHTS_DOMAIN_MANAGER+1,
'bad3@example.com' => User\Driver::RIGHTS_DOMAIN_ADMIN+1, 'bad3@example.com' => Driver::RIGHTS_DOMAIN_ADMIN+1,
'bad3@example.org' => User\Driver::RIGHTS_DOMAIN_ADMIN+1, 'bad3@example.org' => Driver::RIGHTS_DOMAIN_ADMIN+1,
'bad4@example.com' => User\Driver::RIGHTS_GLOBAL_MANAGER+1, 'bad4@example.com' => Driver::RIGHTS_GLOBAL_MANAGER+1,
'bad4@example.org' => User\Driver::RIGHTS_GLOBAL_MANAGER+1, 'bad4@example.org' => Driver::RIGHTS_GLOBAL_MANAGER+1,
'bad5@example.com' => User\Driver::RIGHTS_GLOBAL_ADMIN+1, 'bad5@example.com' => Driver::RIGHTS_GLOBAL_ADMIN+1,
'bad5@example.org' => User\Driver::RIGHTS_GLOBAL_ADMIN+1, 'bad5@example.org' => Driver::RIGHTS_GLOBAL_ADMIN+1,
]; ];
const LEVELS = [ const LEVELS = [
User\Driver::RIGHTS_NONE, Driver::RIGHTS_NONE,
User\Driver::RIGHTS_DOMAIN_MANAGER, Driver::RIGHTS_DOMAIN_MANAGER,
User\Driver::RIGHTS_DOMAIN_ADMIN, Driver::RIGHTS_DOMAIN_ADMIN,
User\Driver::RIGHTS_GLOBAL_MANAGER, Driver::RIGHTS_GLOBAL_MANAGER,
User\Driver::RIGHTS_GLOBAL_ADMIN, Driver::RIGHTS_GLOBAL_ADMIN,
]; ];
const DOMAINS = [ const DOMAINS = [
'@example.com', '@example.com',
@ -49,7 +54,7 @@ class TestAuthorization extends Test\AbstractTest {
protected $data; protected $data;
public function setUp(string $drv = Test\User\DriverInternalMock::class, string $db = null) { public function setUp(string $drv = \JkingWeb\Arsse\Test\User\DriverInternalMock::class, string $db = null) {
$this->clearData(); $this->clearData();
$conf = new Conf(); $conf = new Conf();
$conf->userDriver = $drv; $conf->userDriver = $drv;
@ -91,7 +96,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testRegularUserLogic() { public function testRegularUserLogic() {
foreach (self::USERS as $actor => $rights) { foreach (self::USERS as $actor => $rights) {
if ($rights != User\Driver::RIGHTS_NONE) { if ($rights != Driver::RIGHTS_NONE) {
continue; continue;
} }
Arsse::$user->auth($actor, ""); Arsse::$user->auth($actor, "");
@ -118,7 +123,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testDomainManagerLogic() { public function testDomainManagerLogic() {
foreach (self::USERS as $actor => $actorRights) { foreach (self::USERS as $actor => $actorRights) {
if ($actorRights != User\Driver::RIGHTS_DOMAIN_MANAGER) { if ($actorRights != Driver::RIGHTS_DOMAIN_MANAGER) {
continue; continue;
} }
$actorDomain = substr($actor, strrpos($actor, "@")+1); $actorDomain = substr($actor, strrpos($actor, "@")+1);
@ -139,7 +144,7 @@ class TestAuthorization extends Test\AbstractTest {
} }
// and they should only be able to set their own rights to regular user // and they should only be able to set their own rights to regular user
foreach (self::LEVELS as $level) { foreach (self::LEVELS as $level) {
if ($actor==$affected && in_array($level, [User\Driver::RIGHTS_NONE, User\Driver::RIGHTS_DOMAIN_MANAGER])) { if ($actor==$affected && in_array($level, [User\Driver::RIGHTS_NONE, Driver::RIGHTS_DOMAIN_MANAGER])) {
$this->assertTrue(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted properly for $affected settings rights level $level, but the action was denied."); $this->assertTrue(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted properly for $affected settings rights level $level, but the action was denied.");
} else { } else {
$this->assertFalse(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted improperly for $affected settings rights level $level, but the action was allowed."); $this->assertFalse(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted improperly for $affected settings rights level $level, but the action was allowed.");
@ -159,7 +164,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testDomainAdministratorLogic() { public function testDomainAdministratorLogic() {
foreach (self::USERS as $actor => $actorRights) { foreach (self::USERS as $actor => $actorRights) {
if ($actorRights != User\Driver::RIGHTS_DOMAIN_ADMIN) { if ($actorRights != Driver::RIGHTS_DOMAIN_ADMIN) {
continue; continue;
} }
$actorDomain = substr($actor, strrpos($actor, "@")+1); $actorDomain = substr($actor, strrpos($actor, "@")+1);
@ -201,7 +206,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testGlobalManagerLogic() { public function testGlobalManagerLogic() {
foreach (self::USERS as $actor => $actorRights) { foreach (self::USERS as $actor => $actorRights) {
if ($actorRights != User\Driver::RIGHTS_GLOBAL_MANAGER) { if ($actorRights != Driver::RIGHTS_GLOBAL_MANAGER) {
continue; continue;
} }
$actorDomain = substr($actor, strrpos($actor, "@")+1); $actorDomain = substr($actor, strrpos($actor, "@")+1);
@ -218,7 +223,7 @@ class TestAuthorization extends Test\AbstractTest {
} }
// and they should only be able to set their own rights to regular user // and they should only be able to set their own rights to regular user
foreach (self::LEVELS as $level) { foreach (self::LEVELS as $level) {
if ($actor==$affected && in_array($level, [User\Driver::RIGHTS_NONE, User\Driver::RIGHTS_GLOBAL_MANAGER])) { if ($actor==$affected && in_array($level, [User\Driver::RIGHTS_NONE, Driver::RIGHTS_GLOBAL_MANAGER])) {
$this->assertTrue(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted properly for $affected settings rights level $level, but the action was denied."); $this->assertTrue(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted properly for $affected settings rights level $level, but the action was denied.");
} else { } else {
$this->assertFalse(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted improperly for $affected settings rights level $level, but the action was allowed."); $this->assertFalse(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted improperly for $affected settings rights level $level, but the action was allowed.");
@ -234,7 +239,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testGlobalAdministratorLogic() { public function testGlobalAdministratorLogic() {
foreach (self::USERS as $actor => $actorRights) { foreach (self::USERS as $actor => $actorRights) {
if ($actorRights != User\Driver::RIGHTS_GLOBAL_ADMIN) { if ($actorRights != Driver::RIGHTS_GLOBAL_ADMIN) {
continue; continue;
} }
Arsse::$user->auth($actor, ""); Arsse::$user->auth($actor, "");
@ -302,7 +307,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testExternalExceptionLogic() { public function testExternalExceptionLogic() {
// set up the test for an external driver // set up the test for an external driver
$this->setUp(Test\User\DriverExternalMock::class, Test\User\Database::class); $this->setUp(\JKingWeb\Arsse\Test\User\DriverExternalMock::class, \JKingWeb\Arsse\Test\User\Database::class);
// run the previous test with the external driver set up // run the previous test with the external driver set up
$this->testInternalExceptionLogic(); $this->testInternalExceptionLogic();
} }
@ -318,7 +323,7 @@ class TestAuthorization extends Test\AbstractTest {
} }
try { try {
call_user_func_array(array(Arsse::$user, $func), $args); call_user_func_array(array(Arsse::$user, $func), $args);
} catch (User\ExceptionAuthz $e) { } catch (\JKingWeb\Arsse\User\ExceptionAuthz $e) {
$err[] = $func; $err[] = $func;
} }
} }

8
tests/cases/User/TestUserMockExternal.php → tests/cases/User/TestMockExternal.php

@ -4,14 +4,14 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\User;
/** @covers \JKingWeb\Arsse\User */ /** @covers \JKingWeb\Arsse\User */
class TestUserMockExternal extends Test\AbstractTest { class TestMockExternal extends \JKingWeb\Arsse\Test\AbstractTest {
use Test\User\CommonTests; use \JKingWeb\Arsse\Test\User\CommonTests;
const USER1 = "john.doe@example.com"; const USER1 = "john.doe@example.com";
const USER2 = "jane.doe@example.com"; const USER2 = "jane.doe@example.com";
public $drv = Test\User\DriverExternalMock::class; public $drv = \JKingWeb\Arsse\Test\User\DriverExternalMock::class;
} }

10
tests/cases/User/TestUserMockInternal.php → tests/cases/User/TestMockInternal.php

@ -4,16 +4,18 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\User;
use JKingWeb\Arsse\Arsse;
/** @covers \JKingWeb\Arsse\User */ /** @covers \JKingWeb\Arsse\User */
class TestUserMockInternal extends Test\AbstractTest { class TestMockInternal extends \JKingWeb\Arsse\Test\AbstractTest {
use Test\User\CommonTests; use \JKingWeb\Arsse\Test\User\CommonTests;
const USER1 = "john.doe@example.com"; const USER1 = "john.doe@example.com";
const USER2 = "jane.doe@example.com"; const USER2 = "jane.doe@example.com";
public $drv = Test\User\DriverInternalMock::class; public $drv = \JKingWeb\Arsse\Test\User\DriverInternalMock::class;
public function setUpSeries() { public function setUpSeries() {
Arsse::$db = null; Arsse::$db = null;

8
tests/cases/User/TestUserInternalDriver.php → tests/cases/User/Testnternal.php

@ -4,17 +4,17 @@
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse\TestCase\User;
/** /**
* @covers \JKingWeb\Arsse\User * @covers \JKingWeb\Arsse\User
* @covers \JKingWeb\Arsse\User\Internal\Driver * @covers \JKingWeb\Arsse\User\Internal\Driver
* @covers \JKingWeb\Arsse\User\Internal\InternalFunctions */ * @covers \JKingWeb\Arsse\User\Internal\InternalFunctions */
class TestUserInternalDriver extends Test\AbstractTest { class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
use Test\User\CommonTests; use \JKingWeb\Arsse\Test\User\CommonTests;
const USER1 = "john.doe@example.com"; const USER1 = "john.doe@example.com";
const USER2 = "jane.doe@example.com"; const USER2 = "jane.doe@example.com";
public $drv = User\Internal\Driver::class; public $drv = \JKingWeb\Arsse\User\Internal\Driver::class;
} }

52
tests/phpunit.xml

@ -21,9 +21,9 @@
<file>cases/Exception/TestException.php</file> <file>cases/Exception/TestException.php</file>
</testsuite> </testsuite>
<testsuite name="Localization"> <testsuite name="Localization">
<file>cases/Lang/TestLang.php</file> <file>cases/Lang/TestBasic.php</file>
<file>cases/Lang/TestLangComplex.php</file> <file>cases/Lang/TestComplex.php</file>
<file>cases/Lang/TestLangErrors.php</file> <file>cases/Lang/TestErrors.php</file>
</testsuite> </testsuite>
<testsuite name="Configuration"> <testsuite name="Configuration">
<file>cases/Conf/TestConf.php</file> <file>cases/Conf/TestConf.php</file>
@ -33,45 +33,45 @@
<file>cases/Misc/TestContext.php</file> <file>cases/Misc/TestContext.php</file>
</testsuite> </testsuite>
<testsuite name="User management"> <testsuite name="User management">
<file>cases/User/TestUserMockInternal.php</file> <file>cases/User/TestMockInternal.php</file>
<file>cases/User/TestUserMockExternal.php</file> <file>cases/User/TestMockExternal.php</file>
<file>cases/User/TestUserInternalDriver.php</file> <file>cases/User/TestInternal.php</file>
<file>cases/User/TestAuthorization.php</file> <file>cases/User/TestAuthorization.php</file>
</testsuite> </testsuite>
<testsuite name="Feed parser"> <testsuite name="Feed parser">
<file>cases/Feed/TestFeedFetching.php</file> <file>cases/Feed/TestFetching.php</file>
<file>cases/Feed/TestFeed.php</file> <file>cases/Feed/TestFeed.php</file>
</testsuite> </testsuite>
<testsuite name="Database drivers"> <testsuite name="Database drivers">
<file>cases/Db/TestTransaction.php</file> <file>cases/Db/TestTransaction.php</file>
<file>cases/Db/TestResultAggregate.php</file> <file>cases/Db/TestResultAggregate.php</file>
<file>cases/Db/TestResultEmpty.php</file> <file>cases/Db/TestResultEmpty.php</file>
<file>cases/Db/SQLite3/TestDbResultSQLite3.php</file> <file>cases/Db/SQLite3/TestResult.php</file>
<file>cases/Db/SQLite3/TestDbStatementSQLite3.php</file> <file>cases/Db/SQLite3/TestStatement.php</file>
<file>cases/Db/SQLite3/TestDbDriverCreationSQLite3.php</file> <file>cases/Db/SQLite3/TestCreation.php</file>
<file>cases/Db/SQLite3/TestDbDriverSQLite3.php</file> <file>cases/Db/SQLite3/TestDriver.php</file>
<file>cases/Db/SQLite3/TestDbUpdateSQLite3.php</file> <file>cases/Db/SQLite3/TestUpdate.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/TestMiscellany.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestMeta.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestUser.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseSessionSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestSession.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseFolderSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestFolder.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseFeedSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestFeed.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestSubscription.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestArticle.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseLabelSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestLabel.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseCleanupSQLite3.php</file> <file>cases/Db/SQLite3/Database/TestCleanup.php</file>
</testsuite> </testsuite>
<testsuite name="Controllers"> <testsuite name="Controllers">
<testsuite name="NCNv1"> <testsuite name="NCNv1">
<file>cases/REST/NextCloudNews/TestNCNVersionDiscovery.php</file> <file>cases/REST/NextCloudNews/TestVersions.php</file>
<file>cases/REST/NextCloudNews/TestNCNV1_2.php</file> <file>cases/REST/NextCloudNews/TestV1_2.php</file>
</testsuite> </testsuite>
<testsuite name="TTRSS"> <testsuite name="TTRSS">
<file>cases/REST/TinyTinyRSS/TestTinyTinyAPI.php</file> <file>cases/REST/TinyTinyRSS/TestAPI.php</file>
<file>cases/REST/TinyTinyRSS/TestTinyTinyIcon.php</file> <file>cases/REST/TinyTinyRSS/TestIcon.php</file>
</testsuite> </testsuite>
</testsuite> </testsuite>
<testsuite name="Refresh service"> <testsuite name="Refresh service">

Loading…
Cancel
Save