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

Adapt TTRSS to new type system

This commit is contained in:
J. King 2017-10-20 09:54:08 -04:00
parent 8c6c49d588
commit 488a7bddac
2 changed files with 100 additions and 111 deletions

View file

@ -10,6 +10,7 @@ use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Misc\Context; use JKingWeb\Arsse\Misc\Context;
use JKingWeb\Arsse\Misc\ValueInfo; use JKingWeb\Arsse\Misc\ValueInfo;
use JKingWeb\Arsse\AbstractException; use JKingWeb\Arsse\AbstractException;
use JKingWeb\Arsse\ExceptionType;
use JKingWeb\Arsse\Db\ExceptionInput; use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Feed\Exception as FeedException; use JKingWeb\Arsse\Feed\Exception as FeedException;
use JKingWeb\Arsse\REST\Response; use JKingWeb\Arsse\REST\Response;
@ -33,46 +34,47 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
const VERSION = "17.4"; const VERSION = "17.4";
const LABEL_OFFSET = 1024; const LABEL_OFFSET = 1024;
const VALID_INPUT = [ const VALID_INPUT = [
'op' => "str", 'op' => ValueInfo::T_STRING,
'sid' => "str", 'sid' => ValueInfo::T_STRING,
'user' => "str", 'seq' => ValueInfo::T_INT,
'password' => "str", 'user' => ValueInfo::T_STRING | ValueInfo::M_STRICT,
'include_empty' => "bool", 'password' => ValueInfo::T_STRING | ValueInfo::M_STRICT,
'unread_only' => "bool", 'include_empty' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'enable_nested' => "bool", 'unread_only' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'caption' => "str", 'enable_nested' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'parent_id' => "int", 'caption' => ValueInfo::T_STRING | ValueInfo::M_STRICT,
'category_id' => "int", 'parent_id' => ValueInfo::T_INT,
'feed_url' => "str", 'category_id' => ValueInfo::T_INT,
'login' => "str", 'feed_url' => ValueInfo::T_STRING | ValueInfo::M_STRICT,
'feed_id' => "int", 'login' => ValueInfo::T_STRING | ValueInfo::M_STRICT,
'article_id' => "int", 'feed_id' => ValueInfo::T_INT,
'label_id' => "int", 'article_id' => ValueInfo::T_INT,
'article_ids' => "str", 'label_id' => ValueInfo::T_INT,
'assign' => "bool", 'article_ids' => ValueInfo::T_STRING,
'is_cat' => "bool", 'assign' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'cat_id' => "int", 'is_cat' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'limit' => "int", 'cat_id' => ValueInfo::T_INT,
'offset' => "int", 'limit' => ValueInfo::T_INT,
'include_nested' => "bool", 'offset' => ValueInfo::T_INT,
'skip' => "int", 'include_nested' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'filter' => "str", 'skip' => ValueInfo::T_INT,
'show_excerpt' => "bool", 'filter' => ValueInfo::T_STRING,
'show_content' => "bool", 'show_excerpt' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'view_mode' => "str", 'show_content' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'include_attachments' => "bool", 'view_mode' => ValueInfo::T_STRING,
'since_id' => "int", 'include_attachments' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'order_by' => "str", 'since_id' => ValueInfo::T_INT,
'sanitize' => "bool", 'order_by' => ValueInfo::T_STRING,
'force_update' => "bool", 'sanitize' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'has_sandbox' => "bool", 'force_update' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'include_header' => "bool", 'has_sandbox' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'search' => "str", 'include_header' => ValueInfo::T_BOOL | ValueInfo::M_DROP,
'search_mode' => "str", 'search' => ValueInfo::T_STRING,
'match_on' => "str", 'search_mode' => ValueInfo::T_STRING,
'mode' => "int", 'match_on' => ValueInfo::T_STRING,
'field' => "int", 'mode' => ValueInfo::T_INT,
'data' => "str", 'field' => ValueInfo::T_INT,
'data' => ValueInfo::T_STRING,
]; ];
const FATAL_ERR = [ const FATAL_ERR = [
'seq' => null, 'seq' => null,
@ -98,16 +100,17 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
// non-JSON input indicates an error // non-JSON input indicates an error
return new Response(400, self::FATAL_ERR); return new Response(400, self::FATAL_ERR);
} }
// layer input over defaults
$data = array_merge([
'seq' => 0,
'op' => "",
'sid' => null,
], $data);
try { try {
// normalize input
try {
$data['seq'] = isset($data['seq']) ? $data['seq'] : 0;
$data = $this->normalizeInput($data, self::VALID_INPUT, "unix");
} catch(ExceptionType $e) {
throw new Exception("INCORRECT_USAGE");
}
if (strtolower((string) $data['op']) != "login") { if (strtolower((string) $data['op']) != "login") {
// unless logging in, a session identifier is required // unless logging in, a session identifier is required
$this->resumeSession($data['sid']); $this->resumeSession((string) $data['sid']);
} }
$method = "op".ucfirst($data['op']); $method = "op".ucfirst($data['op']);
if (!method_exists($this, $method)) { if (!method_exists($this, $method)) {
@ -142,10 +145,10 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
} }
protected function resumeSession($id): bool { protected function resumeSession(string $id): bool {
try { try {
// verify the supplied session is valid // verify the supplied session is valid
$s = Arsse::$db->sessionResume((string) $id); $s = Arsse::$db->sessionResume($id);
} catch (\JKingWeb\Arsse\User\ExceptionSession $e) { } catch (\JKingWeb\Arsse\User\ExceptionSession $e) {
// if not throw an exception // if not throw an exception
throw new Exception("NOT_LOGGED_IN"); throw new Exception("NOT_LOGGED_IN");
@ -167,7 +170,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opLogin(array $data): array { public function opLogin(array $data): array {
if (isset($data['user']) && isset($data['password']) && Arsse::$user->auth($data['user'], $data['password'])) { if (Arsse::$user->auth((string) $data['user'], (string) $data['password'])) {
$id = Arsse::$db->sessionCreate($data['user']); $id = Arsse::$db->sessionCreate($data['user']);
return [ return [
'session_id' => $id, 'session_id' => $id,
@ -281,9 +284,9 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
public function opGetCategories(array $data): array { public function opGetCategories(array $data): array {
// normalize input // normalize input
$all = isset($data['include_empty']) ? ValueInfo::bool($data['include_empty'], false) : false; $all = $data['include_empty'] ?? false;
$read = !(isset($data['unread_only']) ? ValueInfo::bool($data['unread_only'], false) : false); $read = !($data['unread_only'] ?? false);
$deep = !(isset($data['enable_nested']) ? ValueInfo::bool($data['enable_nested'], false) : false); $deep = !($data['enable_nested'] ?? false);
$user = Arsse::$user->id; $user = Arsse::$user->id;
// for each category, add the ID to a lookup table, set the number of unread to zero, and assign an increasing order index // for each category, add the ID to a lookup table, set the number of unread to zero, and assign an increasing order index
$cats = Arsse::$db->folderList($user, null, $deep)->getAll(); $cats = Arsse::$db->folderList($user, null, $deep)->getAll();
@ -356,12 +359,9 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
public function opAddCategory(array $data) { public function opAddCategory(array $data) {
$in = [ $in = [
'name' => isset($data['caption']) ? $data['caption'] : "", 'name' => $data['caption'],
'parent' => isset($data['parent_id']) ? $data['parent_id'] : null, 'parent' => $data['parent_id'],
]; ];
if (!$in['parent']) {
$in['parent'] = null;
}
try { try {
return Arsse::$db->folderAdd(Arsse::$user->id, $in); return Arsse::$db->folderAdd(Arsse::$user->id, $in);
} catch (ExceptionInput $e) { } catch (ExceptionInput $e) {
@ -384,7 +384,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opRemoveCategory(array $data) { public function opRemoveCategory(array $data) {
if (!isset($data['category_id']) || !ValueInfo::id($data['category_id'])) { if (!ValueInfo::id($data['category_id'])) {
// if the folder is invalid, throw an error // if the folder is invalid, throw an error
throw new Exception("INCORRECT_USAGE"); throw new Exception("INCORRECT_USAGE");
} }
@ -398,7 +398,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opMoveCategory(array $data) { public function opMoveCategory(array $data) {
if (!isset($data['category_id']) || !ValueInfo::id($data['category_id']) || !isset($data['parent_id']) || !ValueInfo::id($data['parent_id'], true)) { if (!ValueInfo::id($data['category_id']) || !ValueInfo::id($data['parent_id'], true)) {
// if the folder or parent is invalid, throw an error // if the folder or parent is invalid, throw an error
throw new Exception("INCORRECT_USAGE"); throw new Exception("INCORRECT_USAGE");
} }
@ -415,21 +415,17 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opRenameCategory(array $data) { public function opRenameCategory(array $data) {
if (!isset($data['category_id']) || !ValueInfo::id($data['category_id']) || !isset($data['caption'])) {
// if the folder is invalid, throw an error
throw new Exception("INCORRECT_USAGE");
}
$info = ValueInfo::str($data['caption']); $info = ValueInfo::str($data['caption']);
if (!($info & ValueInfo::VALID) || ($info & ValueInfo::EMPTY) || ($info & ValueInfo::WHITE)) { if (!ValueInfo::id($data['category_id']) || !($info & ValueInfo::VALID) || ($info & ValueInfo::EMPTY) || ($info & ValueInfo::WHITE)) {
// if the folder name is invalid, throw an error // if the folder or its new name are invalid, throw an error
throw new Exception("INCORRECT_USAGE"); throw new Exception("INCORRECT_USAGE");
} }
$in = [ $in = [
'name' => (string) $data['caption'], 'name' => $data['caption'],
]; ];
try { try {
// try to rename the folder // try to rename the folder
Arsse::$db->folderPropertiesSet(Arsse::$user->id, (int) $data['category_id'], $in); Arsse::$db->folderPropertiesSet(Arsse::$user->id, $data['category_id'], $in);
} catch(ExceptionInput $e) { } catch(ExceptionInput $e) {
// ignore all errors // ignore all errors
} }
@ -453,23 +449,14 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opSubscribeToFeed(array $data): array { public function opSubscribeToFeed(array $data): array {
if (!isset($data['feed_url']) || !(ValueInfo::str($data['feed_url']) & ValueInfo::VALID)) { if (!$data['feed_url'] || !ValueInfo::id($data['category_id'], true)) {
// if the feed URL is invalid, throw an error // if the feed URL or the category ID is invalid, throw an error
throw new Exception("INCORRECT_USAGE"); throw new Exception("INCORRECT_USAGE");
} }
// normalize input data
if (
(isset($data['category_id']) && !ValueInfo::id($data['category_id'], true)) ||
(isset($data['login']) && !(ValueInfo::str($data['login']) & ValueInfo::VALID)) ||
(isset($data['password']) && !(ValueInfo::str($data['password']) & ValueInfo::VALID))
) {
// if the category is not a valid ID or the feed username or password are not convertible to strings, also throw an error
throw new Exception("INCORRECT_USAGE");
}
$url = (string) $data['feed_url']; $url = (string) $data['feed_url'];
$folder = isset($data['category_id']) ? (int) $data['category_id'] : null; $folder = (int) $data['category_id'];
$fetchUser = isset($data['login']) ? (string) $data['login'] : ""; $fetchUser = (string) $data['login'];
$fetchPassword = isset($data['password']) ? (string) $data['password'] : ""; $fetchPassword = (string) $data['password'];
// check to make sure the requested folder exists before doing anything else, if one is specified // check to make sure the requested folder exists before doing anything else, if one is specified
if ($folder) { if ($folder) {
try { try {
@ -519,10 +506,6 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opUnsubscribeFeed(array $data): array { public function opUnsubscribeFeed(array $data): array {
if (!isset($data['feed_id']) || !ValueInfo::id($data['feed_id'])) {
// if the feed is invalid, throw an error
throw new Exception("FEED_NOT_FOUND");
}
try { try {
// attempt to remove the feed // attempt to remove the feed
Arsse::$db->subscriptionRemove(Arsse::$user->id, (int) $data['feed_id']); Arsse::$db->subscriptionRemove(Arsse::$user->id, (int) $data['feed_id']);
@ -533,16 +516,16 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opMoveFeed(array $data) { public function opMoveFeed(array $data) {
if (!isset($data['feed_id']) || !ValueInfo::id($data['feed_id']) || !isset($data['category_id']) || !ValueInfo::id($data['category_id'], true)) { if (!ValueInfo::id($data['feed_id']) || !isset($data['category_id']) || !ValueInfo::id($data['category_id'], true)) {
// if the feed or folder is invalid, throw an error // if the feed or folder is invalid, throw an error
throw new Exception("INCORRECT_USAGE"); throw new Exception("INCORRECT_USAGE");
} }
$in = [ $in = [
'folder' => (int) $data['category_id'], 'folder' => $data['category_id'],
]; ];
try { try {
// try to move the feed // try to move the feed
Arsse::$db->subscriptionPropertiesSet(Arsse::$user->id, (int) $data['feed_id'], $in); Arsse::$db->subscriptionPropertiesSet(Arsse::$user->id, $data['feed_id'], $in);
} catch(ExceptionInput $e) { } catch(ExceptionInput $e) {
// ignore all errors // ignore all errors
} }
@ -550,21 +533,17 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opRenameFeed(array $data) { public function opRenameFeed(array $data) {
if (!isset($data['feed_id']) || !ValueInfo::id($data['feed_id']) || !isset($data['caption'])) {
// if the feed is invalid or there is no caption, throw an error
throw new Exception("INCORRECT_USAGE");
}
$info = ValueInfo::str($data['caption']); $info = ValueInfo::str($data['caption']);
if (!($info & ValueInfo::VALID) || ($info & ValueInfo::EMPTY) || ($info & ValueInfo::WHITE)) { if (!ValueInfo::id($data['feed_id']) || !($info & ValueInfo::VALID) || ($info & ValueInfo::EMPTY) || ($info & ValueInfo::WHITE)) {
// if the feed name is invalid, throw an error // if the feed ID or name is invalid, throw an error
throw new Exception("INCORRECT_USAGE"); throw new Exception("INCORRECT_USAGE");
} }
$in = [ $in = [
'name' => (string) $data['caption'], 'name' => $data['caption'],
]; ];
try { try {
// try to rename the feed // try to rename the feed
Arsse::$db->subscriptionPropertiesSet(Arsse::$user->id, (int) $data['feed_id'], $in); Arsse::$db->subscriptionPropertiesSet(Arsse::$user->id, $data['feed_id'], $in);
} catch(ExceptionInput $e) { } catch(ExceptionInput $e) {
// ignore all errors // ignore all errors
} }
@ -577,7 +556,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
throw new Exception("INCORRECT_USAGE"); throw new Exception("INCORRECT_USAGE");
} }
try { try {
Arsse::$db->feedUpdate(Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, (int) $data['feed_id'])['feed']); Arsse::$db->feedUpdate(Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, $data['feed_id'])['feed']);
} catch(ExceptionInput $e) { } catch(ExceptionInput $e) {
throw new Exception("FEED_NOT_FOUND"); throw new Exception("FEED_NOT_FOUND");
} }
@ -597,7 +576,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
public function opGetLabels(array $data): array { public function opGetLabels(array $data): array {
// this function doesn't complain about invalid article IDs // this function doesn't complain about invalid article IDs
$article = (isset($data['article_id']) && ValueInfo::id($data['article_id'])) ? (int) $data['article_id'] : 0; $article = ValueInfo::id($data['article_id']) ? $data['article_id'] : 0;
try { try {
$list = $article ? Arsse::$db->articleLabelsGet(Arsse::$user->id, $article) : []; $list = $article ? Arsse::$db->articleLabelsGet(Arsse::$user->id, $article) : [];
} catch (ExceptionInput $e) { } catch (ExceptionInput $e) {
@ -618,7 +597,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
public function opAddLabel(array $data) { public function opAddLabel(array $data) {
$in = [ $in = [
'name' => isset($data['caption']) ? $data['caption'] : "", 'name' => (string) $data['caption'],
]; ];
try { try {
return $this->labelOut(Arsse::$db->labelAdd(Arsse::$user->id, $in)); return $this->labelOut(Arsse::$db->labelAdd(Arsse::$user->id, $in));
@ -635,7 +614,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
public function opRemoveLabel(array $data) { public function opRemoveLabel(array $data) {
// normalize the label ID; missing or invalid IDs are rejected // normalize the label ID; missing or invalid IDs are rejected
$id = $this->labelIn(isset($data['label_id']) ? $data['label_id'] : 0); $id = $this->labelIn($data['label_id']);
try { try {
// attempt to remove the label // attempt to remove the label
Arsse::$db->labelRemove(Arsse::$user->id, $id); Arsse::$db->labelRemove(Arsse::$user->id, $id);
@ -647,8 +626,8 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
public function opRenameLabel(array $data) { public function opRenameLabel(array $data) {
// normalize input; missing or invalid IDs are rejected // normalize input; missing or invalid IDs are rejected
$id = $this->labelIn(isset($data['label_id']) ? $data['label_id'] : 0); $id = $this->labelIn($data['label_id']);
$name = isset($data['caption']) ? $data['caption'] : ""; $name = (string) $data['caption'];
try { try {
// try to rename the folder // try to rename the folder
Arsse::$db->labelPropertiesSet(Arsse::$user->id, $id, ['name' => $name]); Arsse::$db->labelPropertiesSet(Arsse::$user->id, $id, ['name' => $name]);
@ -662,12 +641,11 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
public function opSetArticleLabel(array $data): array { public function opSetArticleLabel(array $data): array {
if (!isset($data['article_ids']) || !isset($data['label_id'])) { if (!$data['article_ids'] || !$data['label_id']) {
throw new Exception("INCORRECT_USAGE"); throw new Exception("INCORRECT_USAGE");
} }
$label = $this->labelIn($data['label_id']); $label = $this->labelIn($data['label_id']);
$articles = explode(",", (string) $data['article_ids']); $articles = explode(",", $data['article_ids']);
$assign = ValueInfo::bool(isset($data['assign']) ? $data['assign'] : null, false); $assign = $data['assign'] ?? false;
} }
} }

View file

@ -257,11 +257,21 @@ class TestTinyTinyAPI extends Test\AbstractTest {
[Arsse::$user->id, 2112, ['parent' => 2]], [Arsse::$user->id, 2112, ['parent' => 2]],
[Arsse::$user->id, 42, ['parent' => 0]], [Arsse::$user->id, 42, ['parent' => 0]],
[Arsse::$user->id, 42, ['parent' => 47]], [Arsse::$user->id, 42, ['parent' => 47]],
[Arsse::$user->id, -1, ['parent' => 1]],
[Arsse::$user->id, 42, ['parent' => -1]],
[Arsse::$user->id, 42, ['parent' => 0]],
[Arsse::$user->id, 0, ['parent' => -1]],
[Arsse::$user->id, 0, ['parent' => 0]],
]; ];
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[0])->thenReturn(true); Phake::when(Arsse::$db)->folderPropertiesSet(...$db[0])->thenReturn(true);
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[1])->thenThrow(new ExceptionInput("subjectMissing")); Phake::when(Arsse::$db)->folderPropertiesSet(...$db[1])->thenThrow(new ExceptionInput("subjectMissing"));
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[2])->thenThrow(new ExceptionInput("constraintViolation")); Phake::when(Arsse::$db)->folderPropertiesSet(...$db[2])->thenThrow(new ExceptionInput("constraintViolation"));
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[3])->thenThrow(new ExceptionInput("idMissing")); Phake::when(Arsse::$db)->folderPropertiesSet(...$db[3])->thenThrow(new ExceptionInput("idMissing"));
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[4])->thenThrow(new ExceptionInput("typeViolation"));
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[5])->thenThrow(new ExceptionInput("typeViolation"));
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[6])->thenThrow(new ExceptionInput("constraintViolation"));
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[7])->thenThrow(new ExceptionInput("typeViolation"));
Phake::when(Arsse::$db)->folderPropertiesSet(...$db[8])->thenThrow(new ExceptionInput("typeViolation"));
// succefully move a folder // succefully move a folder
$exp = $this->respGood(); $exp = $this->respGood();
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0]))));
@ -272,14 +282,14 @@ class TestTinyTinyAPI extends Test\AbstractTest {
$exp = $this->respGood(); $exp = $this->respGood();
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[6]))));
// all the rest should cause errors // all the rest should cause errors
$exp = $this->respErr("INCORRECT_USAGE"); $exp = $this->respErr("INCORRECT_USAGE");
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[4]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[5]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[6]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[7])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[7]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[8])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[8]))));
Phake::verify(Arsse::$db, Phake::times(4))->folderPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything()); Phake::verify(Arsse::$db, Phake::times(5))->folderPropertiesSet(Arsse::$user->id, $this->anything(), $this->anything());
} }
public function testRenameACategory() { public function testRenameACategory() {
@ -404,7 +414,8 @@ class TestTinyTinyAPI extends Test\AbstractTest {
['op' => "unsubscribeFeed", 'sid' => "PriestsOfSyrinx", 'feed_id' => -1], ['op' => "unsubscribeFeed", 'sid' => "PriestsOfSyrinx", 'feed_id' => -1],
['op' => "unsubscribeFeed", 'sid' => "PriestsOfSyrinx"], ['op' => "unsubscribeFeed", 'sid' => "PriestsOfSyrinx"],
]; ];
Phake::when(Arsse::$db)->subscriptionRemove(Arsse::$user->id, $this->anything())->thenThrow(new ExceptionInput("subjectMissing")); Phake::when(Arsse::$db)->subscriptionRemove(Arsse::$user->id, $this->anything())->thenThrow(new ExceptionInput("typeViolation"));
Phake::when(Arsse::$db)->subscriptionRemove(Arsse::$user->id, 2112)->thenThrow(new ExceptionInput("subjectMissing"));
Phake::when(Arsse::$db)->subscriptionRemove(Arsse::$user->id, 42)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing")); Phake::when(Arsse::$db)->subscriptionRemove(Arsse::$user->id, 42)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing"));
// succefully delete a folder // succefully delete a folder
$exp = $this->respGood(['status' => "OK"]); $exp = $this->respGood(['status' => "OK"]);
@ -415,7 +426,7 @@ class TestTinyTinyAPI extends Test\AbstractTest {
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3])))); $this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3]))));
Phake::verify(Arsse::$db, Phake::times(3))->subscriptionRemove(Arsse::$user->id, $this->anything()); Phake::verify(Arsse::$db, Phake::times(5))->subscriptionRemove(Arsse::$user->id, $this->anything());
} }
public function testMoveASubscription() { public function testMoveASubscription() {