1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Tests for adding folders

This commit is contained in:
J. King 2017-03-31 15:27:59 -04:00
parent 82e4838162
commit b68cea1188
5 changed files with 143 additions and 43 deletions

View file

@ -323,7 +323,7 @@ class Database {
throw new User\Exception("doesNotExist", ["user" => $user, "action" => __FUNCTION__]);
}
// if the desired folder name is missing or invalid, throw an exception
if(!array_key_exists("name", $data)) {
if(!array_key_exists("name", $data) || $data['name']=="") {
throw new Db\ExceptionInput("missing", ["action" => __FUNCTION__, "field" => "name"]);
} else if(!strlen(trim($data['name']))) {
throw new Db\ExceptionInput("whitespace", ["action" => __FUNCTION__, "field" => "name"]);

View file

@ -38,21 +38,21 @@ create table arsse_feeds(
-- users' subscriptions to newsfeeds, with settings
create table arsse_subscriptions(
id integer primary key not null, -- sequence number
owner TEXT not null references arsse_users(id) on delete cascade on update cascade, -- owner of subscription
feed integer not null references arsse_feeds(id) on delete cascade, -- feed for the subscription
owner TEXT not null references arsse_users(id) on delete cascade on update cascade, -- owner of subscription
feed integer not null references arsse_feeds(id) on delete cascade, -- feed for the subscription
added datetime not null default CURRENT_TIMESTAMP, -- time at which feed was added
modified datetime not null default CURRENT_TIMESTAMP, -- date at which subscription properties were last modified
title TEXT, -- user-supplied title
order_type int not null default 0, -- NextCloud sort order
pinned boolean not null default 0, -- whether feed is pinned (always sorts at top)
folder integer references arsse_folders(id) on delete cascade, -- TT-RSS category (nestable); the first-level category (which acts as NextCloud folder) is joined in when needed
folder integer references arsse_folders(id) on delete cascade, -- TT-RSS category (nestable); the first-level category (which acts as NextCloud folder) is joined in when needed
unique(owner,feed) -- a given feed should only appear once for a given owner
);
-- TT-RSS categories and NextCloud folders
create table arsse_folders(
id integer primary key not null, -- sequence number
owner TEXT not null references arsse_users(id) on delete cascade on update cascade, -- owner of folder
owner TEXT not null references arsse_users(id) on delete cascade on update cascade, -- owner of folder
parent integer default null, -- parent folder id
root integer default null, -- first-level folder (NextCloud folder)
name TEXT not null, -- folder name
@ -63,7 +63,7 @@ create table arsse_folders(
-- entries in newsfeeds
create table arsse_articles(
id integer primary key not null, -- sequence number
feed integer not null references arsse_feeds(id) on delete cascade, -- feed for the subscription
feed integer not null references arsse_feeds(id) on delete cascade, -- feed for the subscription
url TEXT not null, -- URL of article
title TEXT, -- article title
author TEXT, -- author's name

View file

@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\Test\Database;
use JKingWeb\Arsse\Data;
use JKingWeb\Arsse\User\Driver as UserDriver;
use Phake;
trait SeriesFolder {
function setUpSeries() {
$data = [
'arsse_folders' => [
'columns' => [
'id' => "int",
'owner' => "str",
'parent' => "int",
'root' => "int",
'name' => "str",
],
/* Layout translates to:
Jane
Politics
John
Technology
Software
Politics
Rocketry
Politics
*/
'rows' => [
[1, "john.doe@example.com", null, null, "Technology"],
[2, "john.doe@example.com", 1, 1, "Software"],
[3, "john.doe@example.com", 1, 1, "Rocketry"],
[4, "jane.doe@example.com", null, null, "Politics"],
[5, "john.doe@example.com", null, null, "Politics"],
[6, "john.doe@example.com", 2, 1, "Politics"],
]
]
];
// merge folder table with base user table
$this->data = array_merge($this->data, $data);
$this->primeDatabase($this->data);
}
function testAddARootFolder() {
$user = "john.doe@example.com";
$this->assertSame(7, Data::$db->folderAdd($user, ['name' => "Entertainment"]));
Phake::verify(Data::$user)->authorize($user, "folderAdd");
$state = $this->primeExpectations($this->data, ['arsse_folders' => ['id','owner', 'parent', 'root', 'name']]);
$state['arsse_folders']['rows'][] = [7, $user, null, null, "Entertainment"];
$this->compareExpectations($state);
}
function testAddADuplicateRootFolder() {
$this->assertException("constraintViolation", "Db", "ExceptionInput");
Data::$db->folderAdd("john.doe@example.com", ['name' => "Politics"]);
}
function testAddANestedFolder() {
$user = "john.doe@example.com";
$this->assertSame(7, Data::$db->folderAdd($user, ['name' => "GNOME", 'parent' => 2]));
Phake::verify(Data::$user)->authorize($user, "folderAdd");
$state = $this->primeExpectations($this->data, ['arsse_folders' => ['id','owner', 'parent', 'root', 'name']]);
$state['arsse_folders']['rows'][] = [7, $user, 2, 1, "GNOME"];
$this->compareExpectations($state);
}
function testAddANestedFolderToAMissingParent() {
$this->assertException("idMissing", "Db", "ExceptionInput");
Data::$db->folderAdd("john.doe@example.com", ['name' => "Sociology", 'parent' => 2112]);
}
function testAddANestedFolderForTheWrongOwner() {
$this->assertException("idMissing", "Db", "ExceptionInput");
Data::$db->folderAdd("john.doe@example.com", ['name' => "Sociology", 'parent' => 4]); // folder ID 4 belongs to Jane
}
function testAddAFolderForAMissingUser() {
$this->assertException("doesNotExist", "User");
Data::$db->folderAdd("john.doe@example.org", ['name' => "Sociology"]);
}
function testAddAFolderWithAMissingName() {
$this->assertException("missing", "Db", "ExceptionInput");
Data::$db->folderAdd("john.doe@example.com", []);
}
function testAddAFolderWithABlankName() {
$this->assertException("missing", "Db", "ExceptionInput");
Data::$db->folderAdd("john.doe@example.com", ['name' => ""]);
}
function testAddAFolderWithAWhitespaceName() {
$this->assertException("whitespace", "Db", "ExceptionInput");
Data::$db->folderAdd("john.doe@example.com", ['name' => " "]);
}
function testAddAFolderWithoutAuthority() {
Phake::when(Data::$user)->authorize->thenReturn(false);
$this->assertException("notAuthorized", "User", "ExceptionAuthz");
Data::$db->folderAdd("john.doe@example.com", ['name' => "Sociology"]);
}
}

View file

@ -71,7 +71,9 @@ trait Setup {
$cols = implode(",", array_keys($info['columns']));
foreach($this->drv->prepare("SELECT $cols from $table")->run() as $num => $row) {
$row = array_values($row);
$this->assertSame($expected[$table]['rows'][$num], $row, "Row ".($num+1)." of table $table does not match expectations at array index $num.");
$this->assertGreaterThan(0, sizeof($info['rows']), "Expectations contain fewer rows than the database table $table");
$exp = array_shift($info['rows']);
$this->assertSame($exp, $row, "Row ".($num+1)." of table $table does not match expectations at array index $num.");
}
}
return true;

View file

@ -10,40 +10,36 @@
beStrictAboutTestSize="true"
stopOnError="true">
<testsuite name="Exceptions">
<file>Exception/TestException.php</file>
</testsuite>
<testsuite name="Localization">
<file>Lang/TestLang.php</file>
<file>Lang/TestLangComplex.php</file>
<file>Lang/TestLangErrors.php</file>
</testsuite>
<testsuite name="Configuration loading and saving">
<file>Conf/TestConf.php</file>
</testsuite>
<testsuite name="User management">
<file>User/TestUserMockInternal.php</file>
<file>User/TestUserMockExternal.php</file>
<file>User/TestUserInternalDriver.php</file>
<file>User/TestAuthorization.php</file>
</testsuite>
<testsuite name="SQLite3 database driver">
<file>Db/SQLite3/TestDbResultSQLite3.php</file>
<file>Db/SQLite3/TestDbStatementSQLite3.php</file>
<file>Db/SQLite3/TestDbDriverSQLite3.php</file>
<file>Db/SQLite3/TestDbUpdateSQLite3.php</file>
</testsuite>
<testsuite name="SQLite3 database functions">
<file>Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
</testsuite>
<testsuite name="NextCloud News API">
<file>REST/NextCloudNews/TestNCNVersionDiscovery.php</file>
</testsuite>
<testsuites>
<testsuite name="Exceptions">
<file>Exception/TestException.php</file>
</testsuite>
<testsuite name="Localization">
<file>Lang/TestLang.php</file>
<file>Lang/TestLangComplex.php</file>
<file>Lang/TestLangErrors.php</file>
</testsuite>
<testsuite name="Configuration loading and saving">
<file>Conf/TestConf.php</file>
</testsuite>
<testsuite name="User management">
<file>User/TestUserMockInternal.php</file>
<file>User/TestUserMockExternal.php</file>
<file>User/TestUserInternalDriver.php</file>
<file>User/TestAuthorization.php</file>
</testsuite>
<testsuite name="SQLite3 database driver">
<file>Db/SQLite3/TestDbResultSQLite3.php</file>
<file>Db/SQLite3/TestDbStatementSQLite3.php</file>
<file>Db/SQLite3/TestDbDriverSQLite3.php</file>
<file>Db/SQLite3/TestDbUpdateSQLite3.php</file>
</testsuite>
<testsuite name="SQLite3 database functions">
<file>Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
<file>Db/SQLite3/Database/TestDatabaseFolderSQLite3.php</file>
</testsuite>
<testsuite name="NextCloud News API">
<file>REST/NextCloudNews/TestNCNVersionDiscovery.php</file>
</testsuite>
</testsuites>
</phpunit>