mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
First set of Database subscription tests
This commit is contained in:
parent
554beacfdb
commit
a580579627
3 changed files with 107 additions and 0 deletions
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\Arsse;
|
||||
|
||||
class TestDatabaseSubscriptionSQLite3 extends \PHPUnit\Framework\TestCase {
|
||||
use Test\Tools, Test\Database\Setup;
|
||||
use Test\Database\DriverSQLite3;
|
||||
use Test\Database\SeriesSubscription;
|
||||
}
|
97
tests/lib/Database/SeriesSubscription.php
Normal file
97
tests/lib/Database/SeriesSubscription.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\Arsse\Test\Database;
|
||||
use JKingWeb\Arsse\Data;
|
||||
use JKingWeb\Arsse\Test\Database;
|
||||
use JKingWeb\Arsse\User\Driver as UserDriver;
|
||||
use JKingWeb\Arsse\Feed\Exception as FeedException;
|
||||
use Phake;
|
||||
|
||||
trait SeriesSubscription {
|
||||
function setUpSeries() {
|
||||
$data = [
|
||||
'arsse_feeds' => [
|
||||
'columns' => [
|
||||
'id' => "int",
|
||||
'url' => "str",
|
||||
'title' => "str",
|
||||
'username' => "str",
|
||||
'password' => "str",
|
||||
],
|
||||
'rows' => [
|
||||
[1,"http://example.com/feed1", "Ook", "", ""],
|
||||
]
|
||||
],
|
||||
'arsse_subscriptions' => [
|
||||
'columns' => [
|
||||
'id' => "int",
|
||||
'owner' => "str",
|
||||
'feed' => "int",
|
||||
],
|
||||
'rows' => [
|
||||
|
||||
]
|
||||
]
|
||||
];
|
||||
// merge folder table with base user table
|
||||
$this->data = array_merge($this->data, $data);
|
||||
$this->primeDatabase($this->data);
|
||||
// initialize a partial mock of the Database object to later manipulate the feedUpdate method
|
||||
Data::$db = Phake::PartialMock(Database::class, $this->drv);
|
||||
}
|
||||
|
||||
function testAddASubscriptionToAnExistingFeed() {
|
||||
$user = "john.doe@example.com";
|
||||
$url = "http://example.com/feed1";
|
||||
$subID = $this->nextID("arsse_subscriptions");
|
||||
Phake::when(Data::$db)->feedUpdate->thenReturn(true);
|
||||
$this->assertSame($subID,Data::$db->subscriptionAdd($user, $url));
|
||||
Phake::verify(Data::$user)->authorize($user, "subscriptionAdd");
|
||||
Phake::verify(Data::$db, Phake::times(0))->feedUpdate(1, true);
|
||||
$state = $this->primeExpectations($this->data, [
|
||||
'arsse_feeds' => ['id','url','username','password'],
|
||||
'arsse_subscriptions' => ['id','owner','feed'],
|
||||
]);
|
||||
$state['arsse_subscriptions']['rows'][] = [$subID,$user,1];
|
||||
$this->compareExpectations($state);
|
||||
}
|
||||
|
||||
function testAddASubscriptionToANewFeed() {
|
||||
$user = "john.doe@example.com";
|
||||
$url = "http://example.org/feed1";
|
||||
$feedID = $this->nextID("arsse_feeds");
|
||||
$subID = $this->nextID("arsse_subscriptions");
|
||||
Phake::when(Data::$db)->feedUpdate->thenReturn(true);
|
||||
$this->assertSame($subID,Data::$db->subscriptionAdd($user, $url));
|
||||
Phake::verify(Data::$user)->authorize($user, "subscriptionAdd");
|
||||
Phake::verify(Data::$db)->feedUpdate($feedID, true);
|
||||
$state = $this->primeExpectations($this->data, [
|
||||
'arsse_feeds' => ['id','url','username','password'],
|
||||
'arsse_subscriptions' => ['id','owner','feed'],
|
||||
]);
|
||||
$state['arsse_feeds']['rows'][] = [$feedID,$url,"",""];
|
||||
$state['arsse_subscriptions']['rows'][] = [$subID,$user,$feedID];
|
||||
$this->compareExpectations($state);
|
||||
}
|
||||
|
||||
function testAddASubscriptionToAnInvalidFeed() {
|
||||
$user = "john.doe@example.com";
|
||||
$url = "http://example.org/feed1";
|
||||
$feedID = $this->nextID("arsse_feeds");
|
||||
$subID = $this->nextID("arsse_subscriptions");
|
||||
Phake::when(Data::$db)->feedUpdate->thenThrow(new FeedException($url, new \PicoFeed\Client\InvalidUrlException()));
|
||||
try {
|
||||
Data::$db->subscriptionAdd($user, $url);
|
||||
} catch(FeedException $e) {
|
||||
Phake::verify(Data::$user)->authorize($user, "subscriptionAdd");
|
||||
Phake::verify(Data::$db)->feedUpdate($feedID, true);
|
||||
$state = $this->primeExpectations($this->data, [
|
||||
'arsse_feeds' => ['id','url','username','password'],
|
||||
'arsse_subscriptions' => ['id','owner','feed'],
|
||||
]);
|
||||
$this->compareExpectations($state);
|
||||
$this->assertException("invalidUrl", "Feed");
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@
|
|||
<testsuite name="SQLite3 database functions">
|
||||
<file>Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
|
||||
<file>Db/SQLite3/Database/TestDatabaseFolderSQLite3.php</file>
|
||||
<file>Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php</file>
|
||||
</testsuite>
|
||||
<testsuite name="NextCloud News API">
|
||||
<file>REST/NextCloudNews/TestNCNVersionDiscovery.php</file>
|
||||
|
|
Loading…
Reference in a new issue