mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2025-01-03 14:32:40 +00:00
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.
This commit is contained in:
parent
8fc31cfc40
commit
258be1d54e
4 changed files with 9 additions and 10 deletions
|
@ -1193,12 +1193,10 @@ class Database {
|
||||||
}
|
}
|
||||||
$id = $this->articleValidateId($user, $id)['article'];
|
$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();
|
$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) {
|
// flatten the result to return just the label ID or name, sorted
|
||||||
return $out;
|
$out = $out ? array_column($out, !$byName ? "id" : "name") : [];
|
||||||
} else {
|
sort($out);
|
||||||
// flatten the result to return just the label ID or name
|
return $out;
|
||||||
return array_column($out, !$byName ? "id" : "name");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function articleCategoriesGet(string $user, $id): array {
|
public function articleCategoriesGet(string $user, $id): array {
|
||||||
|
@ -1444,7 +1442,7 @@ class Database {
|
||||||
$this->labelValidateId($user, $id, $byName, false);
|
$this->labelValidateId($user, $id, $byName, false);
|
||||||
$field = !$byName ? "id" : "name";
|
$field = !$byName ? "id" : "name";
|
||||||
$type = !$byName ? "int" : "str";
|
$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 (!$out) {
|
||||||
// if no results were returned, do a full validation on the label ID
|
// if no results were returned, do a full validation on the label ID
|
||||||
$this->labelValidateId($user, $id, $byName, true, true);
|
$this->labelValidateId($user, $id, $byName, true, true);
|
||||||
|
|
|
@ -19,6 +19,7 @@ trait PDOError {
|
||||||
return [ExceptionInput::class, 'engineTypeViolation', $err[2]];
|
return [ExceptionInput::class, 'engineTypeViolation', $err[2]];
|
||||||
case "23000":
|
case "23000":
|
||||||
case "23502":
|
case "23502":
|
||||||
|
case "23505":
|
||||||
return [ExceptionInput::class, "constraintViolation", $err[2]];
|
return [ExceptionInput::class, "constraintViolation", $err[2]];
|
||||||
case "55P03":
|
case "55P03":
|
||||||
case "57014":
|
case "57014":
|
||||||
|
|
|
@ -957,7 +957,7 @@ trait SeriesArticle {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListTheLabelsOfAnArticle() {
|
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([2], Arsse::$db->articleLabelsGet("john.doe@example.com", 5));
|
||||||
$this->assertEquals([], Arsse::$db->articleLabelsGet("john.doe@example.com", 2));
|
$this->assertEquals([], Arsse::$db->articleLabelsGet("john.doe@example.com", 2));
|
||||||
$this->assertEquals(["Fascinating","Interesting"], Arsse::$db->articleLabelsGet("john.doe@example.com", 1, true));
|
$this->assertEquals(["Fascinating","Interesting"], Arsse::$db->articleLabelsGet("john.doe@example.com", 1, true));
|
||||||
|
|
|
@ -14,7 +14,7 @@ class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
|
||||||
protected static $implementation = "PDO PostgreSQL";
|
protected static $implementation = "PDO PostgreSQL";
|
||||||
|
|
||||||
protected function nextID(string $table): int {
|
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() {
|
public function setUp() {
|
||||||
|
@ -30,7 +30,7 @@ class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
|
||||||
and column_default like 'nextval(%'
|
and column_default like 'nextval(%'
|
||||||
";
|
";
|
||||||
foreach(static::$drv->query($seqList) as $r) {
|
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) {
|
if (!$num) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue