From 5cd7268c0a276175486646ec005be08acec008be Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 29 Nov 2017 18:14:59 -0500 Subject: [PATCH] Added incorrectDbCharset to NCNv1 server status This has been exposed since version 11.0.3, released before our version 0.1.0, but after implementation work had begun --- lib/Database.php | 4 ++++ lib/Db/Driver.php | 2 ++ lib/Db/SQLite3/Driver.php | 5 +++++ lib/REST/NextCloudNews/V1_2.php | 2 ++ tests/Db/SQLite3/TestDbDriverSQLite3.php | 4 ++++ tests/REST/NextCloudNews/TestNCNV1_2.php | 3 +++ tests/lib/Database/SeriesMiscellany.php | 5 +++++ 7 files changed, 25 insertions(+) diff --git a/lib/Database.php b/lib/Database.php index e7f33cf1..7b684939 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -61,6 +61,10 @@ class Database { return false; } + public function driverCharsetAcceptable(): bool { + return $this->db->charsetAcceptable(); + } + protected function generateSet(array $props, array $valid): array { $out = [ [], // query clause diff --git a/lib/Db/Driver.php b/lib/Db/Driver.php index 2b3d2535..5485458f 100644 --- a/lib/Db/Driver.php +++ b/lib/Db/Driver.php @@ -35,4 +35,6 @@ interface Driver { // ready a prepared statement for later execution public function prepare(string $query, ...$paramType): Statement; public function prepareArray(string $query, array $paramTypes): Statement; + // report whether the database character set is correct/acceptable + public function charsetAcceptable(): bool; } diff --git a/lib/Db/SQLite3/Driver.php b/lib/Db/SQLite3/Driver.php index 4d00ae40..e4d5f1e8 100644 --- a/lib/Db/SQLite3/Driver.php +++ b/lib/Db/SQLite3/Driver.php @@ -127,6 +127,11 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { return true; } + public function charsetAcceptable(): bool { + // SQLite 3 databases are UTF-8 internally, thus always acceptable + return true; + } + protected function getError(): string { return $this->db->lastErrorMsg(); } diff --git a/lib/REST/NextCloudNews/V1_2.php b/lib/REST/NextCloudNews/V1_2.php index f8ae0728..7b33af00 100644 --- a/lib/REST/NextCloudNews/V1_2.php +++ b/lib/REST/NextCloudNews/V1_2.php @@ -204,6 +204,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler { 'starred' => "bool", 'pubDate' => "datetime", 'lastModified' => "datetime", + 'guidHash' => "string" ], $this->dateFormat); return $article; } @@ -653,6 +654,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler { 'arsse_version' => Arsse::VERSION, 'warnings' => [ 'improperlyConfiguredCron' => !Service::hasCheckedIn(), + 'incorrectDbCharset' => !Arsse::$db->driverCharsetAcceptable(), ] ]); } diff --git a/tests/Db/SQLite3/TestDbDriverSQLite3.php b/tests/Db/SQLite3/TestDbDriverSQLite3.php index 867610a5..051ebae3 100644 --- a/tests/Db/SQLite3/TestDbDriverSQLite3.php +++ b/tests/Db/SQLite3/TestDbDriverSQLite3.php @@ -43,6 +43,10 @@ class TestDbDriverSQLite3 extends Test\AbstractTest { $this->assertTrue(strlen($class::driverName()) > 0); } + public function testCheckCharacterSetAcceptability() { + $this->assertTrue($this->drv->charsetAcceptable()); + } + public function testExecAValidStatement() { $this->assertTrue($this->drv->exec("CREATE TABLE test(id integer primary key)")); } diff --git a/tests/REST/NextCloudNews/TestNCNV1_2.php b/tests/REST/NextCloudNews/TestNCNV1_2.php index 2c42654d..ed0392e0 100644 --- a/tests/REST/NextCloudNews/TestNCNV1_2.php +++ b/tests/REST/NextCloudNews/TestNCNV1_2.php @@ -852,14 +852,17 @@ class TestNCNV1_2 extends Test\AbstractTest { $valid = (new \DateTimeImmutable("now", new \DateTimezone("UTC")))->sub($interval); $invalid = $valid->sub($interval)->sub($interval); 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); $arr1 = $arr2 = [ 'version' => REST\NextCloudNews\V1_2::VERSION, 'arsse_version' => Arsse::VERSION, 'warnings' => [ 'improperlyConfiguredCron' => false, + 'incorrectDbCharset' => false, ] ]; $arr2['warnings']['improperlyConfiguredCron'] = true; + $arr2['warnings']['incorrectDbCharset'] = true; $exp = new Response(200, $arr1); $this->assertEquals($exp, $this->h->dispatch(new Request("GET", "/status"))); } diff --git a/tests/lib/Database/SeriesMiscellany.php b/tests/lib/Database/SeriesMiscellany.php index aa4bd472..e58c4306 100644 --- a/tests/lib/Database/SeriesMiscellany.php +++ b/tests/lib/Database/SeriesMiscellany.php @@ -29,4 +29,9 @@ trait SeriesMiscellany { $this->assertSame(Database::SCHEMA_VERSION, $d->driverSchemaVersion()); $this->assertFalse($d->driverSchemaUpdate()); } + + public function testCheckCharacterSetAcceptability() { + $d = new Database(); + $this->assertInternalType("bool", $d->driverCharsetAcceptable()); + } }