mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 09:02:41 +00:00
Use existing infrastructure for update tests
This commit is contained in:
parent
fbf7848c14
commit
9459ef044f
2 changed files with 44 additions and 31 deletions
|
@ -158,34 +158,47 @@ class BaseUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
QUERY_TEXT
|
QUERY_TEXT
|
||||||
);
|
);
|
||||||
$this->drv->schemaUpdate(7);
|
$this->drv->schemaUpdate(7);
|
||||||
$users = [
|
$exp = [
|
||||||
['id' => "a", 'password' => "xyz", 'num' => 1],
|
'arsse_users' => [
|
||||||
['id' => "b", 'password' => "abc", 'num' => 2],
|
'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 = [
|
$this->compareExpectations($this->drv, $exp);
|
||||||
['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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,7 +434,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
||||||
$row = [];
|
$row = [];
|
||||||
foreach ($r as $c => $v) {
|
foreach ($r as $c => $v) {
|
||||||
// store any date values for later comparison
|
// 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;
|
$dates[] = $v;
|
||||||
}
|
}
|
||||||
// serialize to CSV, null being represented by no value
|
// serialize to CSV, null being represented by no value
|
||||||
|
@ -459,7 +459,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
||||||
$row = [];
|
$row = [];
|
||||||
foreach ($r as $c => $v) {
|
foreach ($r as $c => $v) {
|
||||||
// account for dates which might be off by one second
|
// 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) {
|
if (array_search($v, $dates, true) === false) {
|
||||||
$v = Date::transform(Date::sub("PT1S", $v), "sql");
|
$v = Date::transform(Date::sub("PT1S", $v), "sql");
|
||||||
if (array_search($v, $dates, true) === false) {
|
if (array_search($v, $dates, true) === false) {
|
||||||
|
@ -492,7 +492,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
||||||
$extra[] = $row;
|
$extra[] = $row;
|
||||||
}
|
}
|
||||||
// add any unfound rows to the end of the actual array
|
// add any unfound rows to the end of the actual array
|
||||||
$base = sizeof($exp) + 1;
|
$base = sizeof($exp);
|
||||||
foreach ($extra as $k => $v) {
|
foreach ($extra as $k => $v) {
|
||||||
$act[$base + $k] = $v;
|
$act[$base + $k] = $v;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue