mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2025-01-03 14:32:40 +00:00
Basic tests for subscription list
- Need entries and read marks to fully test - Added assertion type to test result subsets - Fixed custom subscription titles
This commit is contained in:
parent
acbb254bfb
commit
f635155687
3 changed files with 69 additions and 8 deletions
|
@ -408,7 +408,7 @@ class Database {
|
|||
"SELECT
|
||||
arsse_subscriptions.id,
|
||||
url,favicon,source,folder,added,pinned,err_count,err_msg,order_type,
|
||||
CASE WHEN arsse_subscriptions.title THEN arsse_subscriptions.title ELSE arsse_feeds.title END as title,
|
||||
CASE WHEN arsse_subscriptions.title is not null THEN arsse_subscriptions.title ELSE arsse_feeds.title END as title,
|
||||
(SELECT count(*) from arsse_articles where feed is arsse_subscriptions.feed) - (SELECT count(*) from (SELECT article,feed from arsse_subscription_articles join arsse_articles on article = arsse_articles.id where owner is ? and feed is arsse_feeds.id and read is 1)) as unread
|
||||
from arsse_subscriptions join arsse_feeds on feed = arsse_feeds.id where owner is ?";
|
||||
if(!is_null($folder)) {
|
||||
|
|
|
@ -21,20 +21,23 @@ trait SeriesSubscription {
|
|||
'rows' => [
|
||||
[1,"http://example.com/feed1", "Ook", "", ""],
|
||||
[2,"http://example.com/feed2", "Eek", "", ""],
|
||||
[3,"http://example.com/feed3", "Ack", "", ""],
|
||||
]
|
||||
],
|
||||
'arsse_subscriptions' => [
|
||||
'columns' => [
|
||||
'id' => "int",
|
||||
'owner' => "str",
|
||||
'feed' => "int",
|
||||
'title' => "str",
|
||||
'id' => "int",
|
||||
'owner' => "str",
|
||||
'feed' => "int",
|
||||
'title' => "str",
|
||||
'folder' => "int",
|
||||
],
|
||||
'rows' => [
|
||||
[1,"john.doe@example.com",2,null],
|
||||
[2,"jane.doe@example.com",2,null],
|
||||
[1,"john.doe@example.com",2,null,null],
|
||||
[2,"jane.doe@example.com",2,null,null],
|
||||
[3,"john.doe@example.com",3,"Ook",2],
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
// merge tables
|
||||
$this->data = array_merge($this->data, $data);
|
||||
|
@ -141,4 +144,33 @@ trait SeriesSubscription {
|
|||
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
|
||||
Data::$db->subscriptionRemove("john.doe@example.com", 1);
|
||||
}
|
||||
|
||||
function testListSubscriptions() {
|
||||
$user = "john.doe@example.com";
|
||||
$exp = [
|
||||
[
|
||||
'url' => "http://example.com/feed2",
|
||||
'title' => "Eek",
|
||||
'folder' => null,
|
||||
],
|
||||
[
|
||||
'url' => "http://example.com/feed3",
|
||||
'title' => "Ook",
|
||||
'folder' => 2,
|
||||
],
|
||||
];
|
||||
$this->assertResult($exp, Data::$db->subscriptionList($user));
|
||||
}
|
||||
|
||||
function testListSubscriptionsInAFolder() {
|
||||
$user = "john.doe@example.com";
|
||||
$exp = [
|
||||
[
|
||||
'url' => "http://example.com/feed3",
|
||||
'title' => "Ook",
|
||||
'folder' => 2,
|
||||
],
|
||||
];
|
||||
$this->assertResult($exp, Data::$db->subscriptionList($user, 2));
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ use JKingWeb\Arsse\Data;
|
|||
use JKingWeb\Arsse\Conf;
|
||||
use JKingWeb\Arsse\User;
|
||||
use JKingWeb\Arsse\Test\Database;
|
||||
use JKingWeb\Arsse\Db\Result;
|
||||
use Phake;
|
||||
|
||||
trait Setup {
|
||||
|
@ -142,4 +143,32 @@ trait Setup {
|
|||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function assertResult(array $expected, Result $res) {
|
||||
$exp = $expected;
|
||||
$res = $res->getAll();
|
||||
$this->assertSame(sizeof($exp), sizeof($res), "Number of result rows (".sizeof($res).") differs from number of expected rows (".sizeof($exp).")");
|
||||
foreach($res as $r) {
|
||||
$found = false;
|
||||
foreach($exp as $index => $x) {
|
||||
foreach($x as $field => $value) {
|
||||
$valid = true;
|
||||
if(!array_key_exists($field, $r) || $r[$field] !== $value) {
|
||||
echo "$field\n";
|
||||
$valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($valid) {
|
||||
$found = true;
|
||||
$this->assertArraySubset($x, $r);
|
||||
unset($exp[$index]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$found) {
|
||||
$this->assertArraySubset($r, $expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue