2019-10-19 16:13:42 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2021-04-14 15:17:01 +00:00
|
|
|
|
2019-10-19 16:13:42 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase;
|
|
|
|
|
2021-07-04 17:22:08 +00:00
|
|
|
use JKingWeb\Arsse\Exception;
|
2019-10-19 16:13:42 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
use JKingWeb\Arsse\Conf;
|
|
|
|
use JKingWeb\Arsse\Lang;
|
|
|
|
use JKingWeb\Arsse\User;
|
|
|
|
use JKingWeb\Arsse\Database;
|
|
|
|
|
|
|
|
/** @covers \JKingWeb\Arsse\Arsse */
|
|
|
|
class TestArsse extends \JKingWeb\Arsse\Test\AbstractTest {
|
2019-11-14 17:05:10 +00:00
|
|
|
public function setUp(): void {
|
2019-10-19 16:13:42 +00:00
|
|
|
self::clearData(false);
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testLoadExistingData(): void {
|
2023-11-11 22:22:13 +00:00
|
|
|
Arsse::$conf = \Phake::mock(Conf::class);
|
|
|
|
$lang = Arsse::$lang = \Phake::mock(Lang::class);
|
|
|
|
$db = Arsse::$db = \Phake::mock(Database::class);
|
|
|
|
$user = Arsse::$user = \Phake::mock(User::class);
|
2019-10-19 16:13:42 +00:00
|
|
|
$conf2 = (new Conf)->import(['lang' => "test"]);
|
|
|
|
Arsse::load($conf2);
|
|
|
|
$this->assertSame($conf2, Arsse::$conf);
|
2023-11-11 22:22:13 +00:00
|
|
|
$this->assertSame($lang, Arsse::$lang);
|
|
|
|
$this->assertSame($db, Arsse::$db);
|
|
|
|
$this->assertSame($user, Arsse::$user);
|
|
|
|
\Phake::verify($lang)->set("test");
|
2019-10-19 16:13:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testLoadNewData(): void {
|
2019-10-19 22:51:01 +00:00
|
|
|
if (!\JKingWeb\Arsse\Db\SQLite3\Driver::requirementsMet() && !\JKingWeb\Arsse\Db\SQLite3\PDODriver::requirementsMet()) {
|
|
|
|
$this->markTestSkipped("A functional SQLite interface is required for this test");
|
|
|
|
}
|
2019-10-19 16:13:42 +00:00
|
|
|
$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);
|
|
|
|
}
|
2021-07-04 17:22:08 +00:00
|
|
|
|
|
|
|
/** @dataProvider provideExtensionChecks */
|
|
|
|
public function testCheckForExtensions(array $ext, $exp): void {
|
|
|
|
if ($exp instanceof \Exception) {
|
|
|
|
$this->assertException($exp);
|
|
|
|
Arsse::checkExtensions(...$ext);
|
|
|
|
} else {
|
|
|
|
$this->assertNull(Arsse::checkExtensions(...$ext));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideExtensionChecks(): iterable {
|
|
|
|
return [
|
2021-07-05 00:55:32 +00:00
|
|
|
[["pcre"], null],
|
2021-07-04 17:22:08 +00:00
|
|
|
[["foo", "bar", "baz"], new Exception("extMissing", ['first' => "foo", 'total' => 3])],
|
2021-07-05 00:55:32 +00:00
|
|
|
[["bar", "baz"], new Exception("extMissing", ['first' => "bar", 'total' => 2])],
|
|
|
|
[["baz"], new Exception("extMissing", ['first' => "baz", 'total' => 1])],
|
2021-07-04 17:22:08 +00:00
|
|
|
];
|
|
|
|
}
|
2019-10-19 16:13:42 +00:00
|
|
|
}
|