1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

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
This commit is contained in:
J. King 2017-11-29 18:14:59 -05:00
parent 40944a9b58
commit 5cd7268c0a
7 changed files with 25 additions and 0 deletions

View file

@ -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

View file

@ -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;
} }

View file

@ -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();
} }

View file

@ -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(),
] ]
]); ]);
} }

View file

@ -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)"));
} }

View file

@ -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")));
} }

View file

@ -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());
}
} }