Browse Source

Use existing infrastructure for update tests

redup
J. King 2 years ago
parent
commit
9459ef044f
  1. 69
      tests/cases/Db/BaseUpdate.php
  2. 6
      tests/lib/AbstractTest.php

69
tests/cases/Db/BaseUpdate.php

@ -158,34 +158,47 @@ class BaseUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
QUERY_TEXT
);
$this->drv->schemaUpdate(7);
$users = [
['id' => "a", 'password' => "xyz", 'num' => 1],
['id' => "b", 'password' => "abc", 'num' => 2],
$exp = [
'arsse_users' => [
'columns' => ["id", "password", "num"],
'rows' => [
["a", "xyz", 1],
["b", "abc", 2],
]
],
'arsse_folders' => [
'columns' => ["owner", "name"],
'rows' => [
["a", "1"],
["b", "2"],
]
],
'arsse_icons' => [
'columns' => ["id", "url"],
'rows' => [
[1, "http://example.com/icon"],
[2, "http://example.org/icon"],
]
],
'arsse_feeds' => [
'columns' => ["url", "icon"],
'rows' => [
["http://example.com/", 1],
["http://example.org/", 2],
["https://example.com/", 1],
["http://example.net/", null],
]
],
'arsse_subscriptions' => [
'columns' => ["id", "scrape"],
'rows' => [
[1,1],
[2,1],
[3,0],
[4,0],
]
]
];
$folders = [
['owner' => "a", 'name' => "1"],
['owner' => "b", 'name' => "2"],
];
$icons = [
['id' => 1, 'url' => "http://example.com/icon"],
['id' => 2, 'url' => "http://example.org/icon"],
];
$feeds = [
['url' => 'http://example.com/', 'icon' => 1],
['url' => 'http://example.org/', 'icon' => 2],
['url' => 'https://example.com/', 'icon' => 1],
['url' => 'http://example.net/', 'icon' => null],
];
$subs = [
['id' => 1, 'scrape' => 1],
['id' => 2, 'scrape' => 1],
['id' => 3, 'scrape' => 0],
['id' => 4, 'scrape' => 0],
];
$this->assertEquals($users, $this->drv->query("SELECT id, password, num from arsse_users order by id")->getAll());
$this->assertEquals($folders, $this->drv->query("SELECT owner, name from arsse_folders order by owner")->getAll());
$this->assertEquals($icons, $this->drv->query("SELECT id, url from arsse_icons order by id")->getAll());
$this->assertEquals($feeds, $this->drv->query("SELECT url, icon from arsse_feeds order by id")->getAll());
$this->assertEquals($subs, $this->drv->query("SELECT id, scrape from arsse_subscriptions order by id")->getAll());
$this->compareExpectations($this->drv, $exp);
}
}

6
tests/lib/AbstractTest.php

@ -434,7 +434,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
$row = [];
foreach ($r as $c => $v) {
// store any date values for later comparison
if (self::COL_DEFS[$table][$info['columns'][$c]] === "datetime") {
if (is_string($v) && preg_match("/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/", $v)) {
$dates[] = $v;
}
// serialize to CSV, null being represented by no value
@ -459,7 +459,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
$row = [];
foreach ($r as $c => $v) {
// account for dates which might be off by one second
if (self::COL_DEFS[$table][$c] === "datetime") {
if (is_string($v) && preg_match("/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/", $v)) {
if (array_search($v, $dates, true) === false) {
$v = Date::transform(Date::sub("PT1S", $v), "sql");
if (array_search($v, $dates, true) === false) {
@ -492,7 +492,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
$extra[] = $row;
}
// add any unfound rows to the end of the actual array
$base = sizeof($exp) + 1;
$base = sizeof($exp);
foreach ($extra as $k => $v) {
$act[$base + $k] = $v;
}

Loading…
Cancel
Save