Browse Source

Fix most PostgreSQL test failures

Reasons for failures included an unhandled error code, erroneous sorting
assumptions, and a broken computation of the next insert ID in tests

Five failures remain.
microsub
J. King 5 years ago
parent
commit
258be1d54e
  1. 12
      lib/Database.php
  2. 1
      lib/Db/PDOError.php
  3. 2
      tests/cases/Database/SeriesArticle.php
  4. 4
      tests/cases/Db/PostgreSQL/TestDatabase.php

12
lib/Database.php

@ -1193,12 +1193,10 @@ class Database {
}
$id = $this->articleValidateId($user, $id)['article'];
$out = $this->db->prepare("SELECT id,name from arsse_labels where owner = ? and exists(select id from arsse_label_members where article = ? and label = arsse_labels.id and assigned = 1)", "str", "int")->run($user, $id)->getAll();
if (!$out) {
return $out;
} else {
// flatten the result to return just the label ID or name
return array_column($out, !$byName ? "id" : "name");
}
// flatten the result to return just the label ID or name, sorted
$out = $out ? array_column($out, !$byName ? "id" : "name") : [];
sort($out);
return $out;
}
public function articleCategoriesGet(string $user, $id): array {
@ -1444,7 +1442,7 @@ class Database {
$this->labelValidateId($user, $id, $byName, false);
$field = !$byName ? "id" : "name";
$type = !$byName ? "int" : "str";
$out = $this->db->prepare("SELECT article from arsse_label_members join arsse_labels on label = id where assigned = 1 and $field = ? and owner = ?", $type, "str")->run($id, $user)->getAll();
$out = $this->db->prepare("SELECT article from arsse_label_members join arsse_labels on label = id where assigned = 1 and $field = ? and owner = ? order by article", $type, "str")->run($id, $user)->getAll();
if (!$out) {
// if no results were returned, do a full validation on the label ID
$this->labelValidateId($user, $id, $byName, true, true);

1
lib/Db/PDOError.php

@ -19,6 +19,7 @@ trait PDOError {
return [ExceptionInput::class, 'engineTypeViolation', $err[2]];
case "23000":
case "23502":
case "23505":
return [ExceptionInput::class, "constraintViolation", $err[2]];
case "55P03":
case "57014":

2
tests/cases/Database/SeriesArticle.php

@ -957,7 +957,7 @@ trait SeriesArticle {
}
public function testListTheLabelsOfAnArticle() {
$this->assertEquals([2,1], Arsse::$db->articleLabelsGet("john.doe@example.com", 1));
$this->assertEquals([1,2], Arsse::$db->articleLabelsGet("john.doe@example.com", 1));
$this->assertEquals([2], Arsse::$db->articleLabelsGet("john.doe@example.com", 5));
$this->assertEquals([], Arsse::$db->articleLabelsGet("john.doe@example.com", 2));
$this->assertEquals(["Fascinating","Interesting"], Arsse::$db->articleLabelsGet("john.doe@example.com", 1, true));

4
tests/cases/Db/PostgreSQL/TestDatabase.php

@ -14,7 +14,7 @@ class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
protected static $implementation = "PDO PostgreSQL";
protected function nextID(string $table): int {
return ((int) static::$drv->query("SELECT last_value from pg_sequences where sequencename = '{$table}_id_seq'")->getValue()) + 1;
return (int) static::$drv->query("SELECT coalesce(last_value, (select max(id) from $table)) + 1 from pg_sequences where sequencename = '{$table}_id_seq'")->getValue();
}
public function setUp() {
@ -30,7 +30,7 @@ class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
and column_default like 'nextval(%'
";
foreach(static::$drv->query($seqList) as $r) {
$num = static::$drv->query("SELECT max({$r['col']}) from {$r['table']}")->getValue();
$num = (int) static::$drv->query("SELECT max({$r['col']}) from {$r['table']}")->getValue();
if (!$num) {
continue;
}

Loading…
Cancel
Save