mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Clean up configuration setting in tests
This commit is contained in:
parent
0be9dcb5a8
commit
d40243a84c
13 changed files with 29 additions and 34 deletions
|
@ -39,20 +39,20 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadDefaultValues() {
|
public function testLoadDefaultValues() {
|
||||||
$this->assertInstanceOf(Conf::class, new Conf());
|
$this->assertInstanceOf(Conf::class, new Conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @depends testLoadDefaultValues */
|
/** @depends testLoadDefaultValues */
|
||||||
public function testImportFromArray() {
|
public function testImportFromArray() {
|
||||||
$arr = ['lang' => "xx"];
|
$arr = ['lang' => "xx"];
|
||||||
$conf = new Conf();
|
$conf = new Conf;
|
||||||
$conf->import($arr);
|
$conf->import($arr);
|
||||||
$this->assertEquals("xx", $conf->lang);
|
$this->assertEquals("xx", $conf->lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @depends testImportFromArray */
|
/** @depends testImportFromArray */
|
||||||
public function testImportFromFile() {
|
public function testImportFromFile() {
|
||||||
$conf = new Conf();
|
$conf = new Conf;
|
||||||
$conf->importFile(self::$path."confGood");
|
$conf->importFile(self::$path."confGood");
|
||||||
$this->assertEquals("xx", $conf->lang);
|
$this->assertEquals("xx", $conf->lang);
|
||||||
$conf = new Conf(self::$path."confGood");
|
$conf = new Conf(self::$path."confGood");
|
||||||
|
@ -97,7 +97,7 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExportToArray() {
|
public function testExportToArray() {
|
||||||
$conf = new Conf();
|
$conf = new Conf;
|
||||||
$conf->lang = ["en", "fr"]; // should not be exported: not scalar
|
$conf->lang = ["en", "fr"]; // should not be exported: not scalar
|
||||||
$conf->dbSQLite3File = "test.db"; // should be exported: value changed
|
$conf->dbSQLite3File = "test.db"; // should be exported: value changed
|
||||||
$conf->userDriver = null; // should be exported: changed value, even when null
|
$conf->userDriver = null; // should be exported: changed value, even when null
|
||||||
|
@ -116,7 +116,7 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
/** @depends testExportToArray
|
/** @depends testExportToArray
|
||||||
* @depends testImportFromFile */
|
* @depends testImportFromFile */
|
||||||
public function testExportToFile() {
|
public function testExportToFile() {
|
||||||
$conf = new Conf();
|
$conf = new Conf;
|
||||||
$conf->lang = ["en", "fr"]; // should not be exported: not scalar
|
$conf->lang = ["en", "fr"]; // should not be exported: not scalar
|
||||||
$conf->dbSQLite3File = "test.db"; // should be exported: value changed
|
$conf->dbSQLite3File = "test.db"; // should be exported: value changed
|
||||||
$conf->userDriver = null; // should be exported: changed value, even when null
|
$conf->userDriver = null; // should be exported: changed value, even when null
|
||||||
|
|
|
@ -107,8 +107,7 @@ class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
chmod($path."Awal/arsse.db-wal", 0111);
|
chmod($path."Awal/arsse.db-wal", 0111);
|
||||||
chmod($path."Ashm/arsse.db-shm", 0111);
|
chmod($path."Ashm/arsse.db-shm", 0111);
|
||||||
// set up configuration
|
// set up configuration
|
||||||
Arsse::$conf = new Conf();
|
$this->setConf(['dbSQLite3File' => ":memory:"]);
|
||||||
Arsse::$conf->dbSQLite3File = ":memory:";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
|
|
|
@ -26,11 +26,11 @@ class TestDriver extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$this->markTestSkipped("SQLite extension not loaded");
|
$this->markTestSkipped("SQLite extension not loaded");
|
||||||
}
|
}
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
$conf = new Conf();
|
$this->setConf([
|
||||||
Arsse::$conf = $conf;
|
'dbDriver' => Driver::class,
|
||||||
$conf->dbDriver = Driver::class;
|
'dbSQLite3Timeout' => 0,
|
||||||
$conf->dbSQLite3Timeout = 0;
|
'dbSQLite3File' => tempnam(sys_get_temp_dir(), 'ook'),
|
||||||
$conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook');
|
]);
|
||||||
$this->drv = new 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);
|
||||||
|
|
|
@ -31,9 +31,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
$this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
|
$this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
|
||||||
if (!$conf) {
|
$conf = $conf ?? new Conf;
|
||||||
$conf = new Conf();
|
|
||||||
}
|
|
||||||
$conf->dbDriver = Driver::class;
|
$conf->dbDriver = Driver::class;
|
||||||
$conf->dbSQLite3File = ":memory:";
|
$conf->dbSQLite3File = ":memory:";
|
||||||
Arsse::$conf = $conf;
|
Arsse::$conf = $conf;
|
||||||
|
@ -111,7 +109,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
|
|
||||||
public function testDeclineManualUpdate() {
|
public function testDeclineManualUpdate() {
|
||||||
// turn auto-updating off
|
// turn auto-updating off
|
||||||
$conf = new Conf();
|
$conf = new Conf;
|
||||||
$conf->dbAutoUpdate = false;
|
$conf->dbAutoUpdate = false;
|
||||||
$this->setUp($conf);
|
$this->setUp($conf);
|
||||||
$this->assertException("updateManual", "Db");
|
$this->assertException("updateManual", "Db");
|
||||||
|
|
|
@ -108,8 +108,7 @@ class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
chmod($path."Awal/arsse.db-wal", 0111);
|
chmod($path."Awal/arsse.db-wal", 0111);
|
||||||
chmod($path."Ashm/arsse.db-shm", 0111);
|
chmod($path."Ashm/arsse.db-shm", 0111);
|
||||||
// set up configuration
|
// set up configuration
|
||||||
Arsse::$conf = new Conf();
|
$this->setConf(['dbSQLite3File' => ":memory:"]);
|
||||||
Arsse::$conf->dbSQLite3File = ":memory:";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
|
|
|
@ -27,11 +27,11 @@ class TestDriver extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$this->markTestSkipped("PDO-SQLite extension not loaded");
|
$this->markTestSkipped("PDO-SQLite extension not loaded");
|
||||||
}
|
}
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
$conf = new Conf();
|
$this->setConf([
|
||||||
Arsse::$conf = $conf;
|
'dbDriver' => PDODriver::class,
|
||||||
$conf->dbDriver = PDODriver::class;
|
'dbSQLite3Timeout' => 0,
|
||||||
$conf->dbSQLite3Timeout = 0;
|
'dbSQLite3File' => tempnam(sys_get_temp_dir(), 'ook'),
|
||||||
$conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook');
|
]);
|
||||||
$this->drv = new PDODriver();
|
$this->drv = new PDODriver();
|
||||||
$this->ch = new \PDO("sqlite:".Arsse::$conf->dbSQLite3File, "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
|
$this->ch = new \PDO("sqlite:".Arsse::$conf->dbSQLite3File, "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
$this->base = self::$host."Feed/";
|
$this->base = self::$host."Feed/";
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
Arsse::$conf = new Conf();
|
$this->setConf();
|
||||||
Arsse::$db = Phake::mock(Database::class);
|
Arsse::$db = Phake::mock(Database::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class TestFetching extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
$this->base = self::$host."Feed/";
|
$this->base = self::$host."Feed/";
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
Arsse::$conf = new Conf();
|
$this->setConf();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHandle400() {
|
public function testHandle400() {
|
||||||
|
|
|
@ -340,7 +340,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
Arsse::$conf = new Conf();
|
$this->setConf();
|
||||||
// create a mock user manager
|
// create a mock user manager
|
||||||
Arsse::$user = Phake::mock(User::class);
|
Arsse::$user = Phake::mock(User::class);
|
||||||
Phake::when(Arsse::$user)->auth->thenReturn(true);
|
Phake::when(Arsse::$user)->auth->thenReturn(true);
|
||||||
|
|
|
@ -177,7 +177,7 @@ LONG_STRING;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
Arsse::$conf = new Conf();
|
$this->setConf();
|
||||||
// create a mock user manager
|
// create a mock user manager
|
||||||
Arsse::$user = Phake::mock(User::class);
|
Arsse::$user = Phake::mock(User::class);
|
||||||
Phake::when(Arsse::$user)->auth->thenReturn(true);
|
Phake::when(Arsse::$user)->auth->thenReturn(true);
|
||||||
|
@ -226,7 +226,7 @@ LONG_STRING;
|
||||||
/** @dataProvider provideLoginRequests */
|
/** @dataProvider provideLoginRequests */
|
||||||
public function testLogIn(array $conf, $httpUser, array $data, $sessions) {
|
public function testLogIn(array $conf, $httpUser, array $data, $sessions) {
|
||||||
Arsse::$user->id = null;
|
Arsse::$user->id = null;
|
||||||
Arsse::$conf = (new Conf)->import($conf);
|
$this->setConf($conf);
|
||||||
Phake::when(Arsse::$user)->auth->thenReturn(false);
|
Phake::when(Arsse::$user)->auth->thenReturn(false);
|
||||||
Phake::when(Arsse::$user)->auth("john.doe@example.com", "secret")->thenReturn(true);
|
Phake::when(Arsse::$user)->auth("john.doe@example.com", "secret")->thenReturn(true);
|
||||||
Phake::when(Arsse::$user)->auth("jane.doe@example.com", "superman")->thenReturn(true);
|
Phake::when(Arsse::$user)->auth("jane.doe@example.com", "superman")->thenReturn(true);
|
||||||
|
@ -260,7 +260,7 @@ LONG_STRING;
|
||||||
/** @dataProvider provideResumeRequests */
|
/** @dataProvider provideResumeRequests */
|
||||||
public function testValidateASession(array $conf, $httpUser, string $data, $result) {
|
public function testValidateASession(array $conf, $httpUser, string $data, $result) {
|
||||||
Arsse::$user->id = null;
|
Arsse::$user->id = null;
|
||||||
Arsse::$conf = (new Conf)->import($conf);
|
$this->setConf($conf);
|
||||||
Phake::when(Arsse::$db)->sessionResume("PriestsOfSyrinx")->thenReturn([
|
Phake::when(Arsse::$db)->sessionResume("PriestsOfSyrinx")->thenReturn([
|
||||||
'id' => "PriestsOfSyrinx",
|
'id' => "PriestsOfSyrinx",
|
||||||
'created' => "2000-01-01 00:00:00",
|
'created' => "2000-01-01 00:00:00",
|
||||||
|
|
|
@ -24,7 +24,7 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
Arsse::$conf = new Conf();
|
$this->setConf();
|
||||||
// create a mock user manager
|
// create a mock user manager
|
||||||
Arsse::$user = Phake::mock(User::class);
|
Arsse::$user = Phake::mock(User::class);
|
||||||
// create a mock database interface
|
// create a mock database interface
|
||||||
|
@ -108,7 +108,7 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$this->assertMessage($exp, $this->reqAuthFailed("42.ico"));
|
$this->assertMessage($exp, $this->reqAuthFailed("42.ico"));
|
||||||
$this->assertMessage($exp, $this->reqAuthFailed("1337.ico"));
|
$this->assertMessage($exp, $this->reqAuthFailed("1337.ico"));
|
||||||
// with HTTP auth required, only authenticated requests should succeed
|
// with HTTP auth required, only authenticated requests should succeed
|
||||||
Arsse::$conf = (new Conf())->import(['userHTTPAuthRequired' => true]);
|
$this->setConf(['userHTTPAuthRequired' => true]);
|
||||||
$exp = new Response(301, ['Location' => "http://example.org/icon.gif"]);
|
$exp = new Response(301, ['Location' => "http://example.org/icon.gif"]);
|
||||||
$this->assertMessage($exp, $this->reqAuth("42.ico"));
|
$this->assertMessage($exp, $this->reqAuth("42.ico"));
|
||||||
$this->assertMessage($exp, $this->reqAuth("1337.ico"));
|
$this->assertMessage($exp, $this->reqAuth("1337.ico"));
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
Arsse::$conf = new Conf();
|
$this->setConf();
|
||||||
Arsse::$db = Phake::mock(Database::class);
|
Arsse::$db = Phake::mock(Database::class);
|
||||||
$this->srv = new Service();
|
$this->srv = new Service();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ trait Setup {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
// establish a clean baseline
|
// establish a clean baseline
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
// create a default configuration
|
$this->setConf();
|
||||||
Arsse::$conf = new Conf();
|
|
||||||
// configure and create the relevant database driver
|
// configure and create the relevant database driver
|
||||||
$this->setUpDriver();
|
$this->setUpDriver();
|
||||||
// create the database interface with the suitable driver
|
// create the database interface with the suitable driver
|
||||||
|
|
Loading…
Reference in a new issue