Browse Source

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
microsub
J. King 7 years ago
parent
commit
5cd7268c0a
  1. 4
      lib/Database.php
  2. 2
      lib/Db/Driver.php
  3. 5
      lib/Db/SQLite3/Driver.php
  4. 2
      lib/REST/NextCloudNews/V1_2.php
  5. 4
      tests/Db/SQLite3/TestDbDriverSQLite3.php
  6. 3
      tests/REST/NextCloudNews/TestNCNV1_2.php
  7. 5
      tests/lib/Database/SeriesMiscellany.php

4
lib/Database.php

@ -61,6 +61,10 @@ class Database {
return false; return false;
} }
public function driverCharsetAcceptable(): bool {
return $this->db->charsetAcceptable();
}
protected function generateSet(array $props, array $valid): array { protected function generateSet(array $props, array $valid): array {
$out = [ $out = [
[], // query clause [], // query clause

2
lib/Db/Driver.php

@ -35,4 +35,6 @@ interface Driver {
// ready a prepared statement for later execution // ready a prepared statement for later execution
public function prepare(string $query, ...$paramType): Statement; public function prepare(string $query, ...$paramType): Statement;
public function prepareArray(string $query, array $paramTypes): Statement; public function prepareArray(string $query, array $paramTypes): Statement;
// report whether the database character set is correct/acceptable
public function charsetAcceptable(): bool;
} }

5
lib/Db/SQLite3/Driver.php

@ -127,6 +127,11 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
return true; return true;
} }
public function charsetAcceptable(): bool {
// SQLite 3 databases are UTF-8 internally, thus always acceptable
return true;
}
protected function getError(): string { protected function getError(): string {
return $this->db->lastErrorMsg(); return $this->db->lastErrorMsg();
} }

2
lib/REST/NextCloudNews/V1_2.php

@ -204,6 +204,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
'starred' => "bool", 'starred' => "bool",
'pubDate' => "datetime", 'pubDate' => "datetime",
'lastModified' => "datetime", 'lastModified' => "datetime",
'guidHash' => "string"
], $this->dateFormat); ], $this->dateFormat);
return $article; return $article;
} }
@ -653,6 +654,7 @@ class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
'arsse_version' => Arsse::VERSION, 'arsse_version' => Arsse::VERSION,
'warnings' => [ 'warnings' => [
'improperlyConfiguredCron' => !Service::hasCheckedIn(), 'improperlyConfiguredCron' => !Service::hasCheckedIn(),
'incorrectDbCharset' => !Arsse::$db->driverCharsetAcceptable(),
] ]
]); ]);
} }

4
tests/Db/SQLite3/TestDbDriverSQLite3.php

@ -43,6 +43,10 @@ class TestDbDriverSQLite3 extends Test\AbstractTest {
$this->assertTrue(strlen($class::driverName()) > 0); $this->assertTrue(strlen($class::driverName()) > 0);
} }
public function testCheckCharacterSetAcceptability() {
$this->assertTrue($this->drv->charsetAcceptable());
}
public function testExecAValidStatement() { public function testExecAValidStatement() {
$this->assertTrue($this->drv->exec("CREATE TABLE test(id integer primary key)")); $this->assertTrue($this->drv->exec("CREATE TABLE test(id integer primary key)"));
} }

3
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); $valid = (new \DateTimeImmutable("now", new \DateTimezone("UTC")))->sub($interval);
$invalid = $valid->sub($interval)->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)->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 = [ $arr1 = $arr2 = [
'version' => REST\NextCloudNews\V1_2::VERSION, 'version' => REST\NextCloudNews\V1_2::VERSION,
'arsse_version' => Arsse::VERSION, 'arsse_version' => Arsse::VERSION,
'warnings' => [ 'warnings' => [
'improperlyConfiguredCron' => false, 'improperlyConfiguredCron' => false,
'incorrectDbCharset' => false,
] ]
]; ];
$arr2['warnings']['improperlyConfiguredCron'] = true; $arr2['warnings']['improperlyConfiguredCron'] = true;
$arr2['warnings']['incorrectDbCharset'] = true;
$exp = new Response(200, $arr1); $exp = new Response(200, $arr1);
$this->assertEquals($exp, $this->h->dispatch(new Request("GET", "/status"))); $this->assertEquals($exp, $this->h->dispatch(new Request("GET", "/status")));
} }

5
tests/lib/Database/SeriesMiscellany.php

@ -29,4 +29,9 @@ trait SeriesMiscellany {
$this->assertSame(Database::SCHEMA_VERSION, $d->driverSchemaVersion()); $this->assertSame(Database::SCHEMA_VERSION, $d->driverSchemaVersion());
$this->assertFalse($d->driverSchemaUpdate()); $this->assertFalse($d->driverSchemaUpdate());
} }
public function testCheckCharacterSetAcceptability() {
$d = new Database();
$this->assertInternalType("bool", $d->driverCharsetAcceptable());
}
} }

Loading…
Cancel
Save