зеркало из https://github.com/nextcloud/news.git
split up api class for easier testing and clearer code
This commit is contained in:
Родитель
bd35b98d2c
Коммит
517e4ca543
107
app/news.php
107
app/news.php
|
@ -28,8 +28,9 @@ namespace OCA\News\App;
|
|||
use \OC\Files\View;
|
||||
use \OCP\AppFramework\App;
|
||||
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Logger;
|
||||
use \OCA\News\Core\Db;
|
||||
use \OCA\News\Core\Settings;
|
||||
|
||||
use \OCA\News\Controller\PageController;
|
||||
use \OCA\News\Controller\FolderController;
|
||||
|
@ -89,82 +90,96 @@ class News extends App {
|
|||
*/
|
||||
$container->registerService('PageController', function($c) {
|
||||
return new PageController(
|
||||
$c->query('API'),
|
||||
$c->query('Request')
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('Settings'),
|
||||
$c->query('L10N')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('FolderController', function($c) {
|
||||
return new FolderController(
|
||||
$c->query('API'),
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('FolderBusinessLayer'),
|
||||
$c->query('FeedBusinessLayer'),
|
||||
$c->query('ItemBusinessLayer')
|
||||
$c->query('ItemBusinessLayer'),
|
||||
$c->query('UserId')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('FeedController', function($c) {
|
||||
return new FeedController(
|
||||
$c->query('API'),
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('FolderBusinessLayer'),
|
||||
$c->query('FeedBusinessLayer'),
|
||||
$c->query('ItemBusinessLayer')
|
||||
$c->query('ItemBusinessLayer'),
|
||||
$c->query('UserId'),
|
||||
$c->query('Settings')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('ItemController', function($c) {
|
||||
return new ItemController(
|
||||
$c->query('API'),
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('FeedBusinessLayer'),
|
||||
$c->query('ItemBusinessLayer')
|
||||
$c->query('ItemBusinessLayer'),
|
||||
$c->query('UserId'),
|
||||
$c->query('Settings')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('ExportController', function($c) {
|
||||
return new ExportController(
|
||||
$c->query('API'),
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('FeedBusinessLayer'),
|
||||
$c->query('FolderBusinessLayer'),
|
||||
$c->query('ItemBusinessLayer'),
|
||||
$c->query('OPMLExporter'));
|
||||
$c->query('OPMLExporter'),
|
||||
$c->query('UserId')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('ApiController', function($c) {
|
||||
return new ApiController(
|
||||
$c->query('API'),
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('Updater')
|
||||
$c->query('Updater'),
|
||||
$c->query('Settings')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('FolderApiController', function($c) {
|
||||
return new FolderApiController(
|
||||
$c->query('API'),
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('FolderBusinessLayer'),
|
||||
$c->query('ItemBusinessLayer')
|
||||
$c->query('ItemBusinessLayer'),
|
||||
$c->query('UserId')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('FeedApiController', function($c) {
|
||||
return new FeedApiController(
|
||||
$c->query('API'),
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('FolderBusinessLayer'),
|
||||
$c->query('FeedBusinessLayer'),
|
||||
$c->query('ItemBusinessLayer')
|
||||
$c->query('ItemBusinessLayer'),
|
||||
$c->query('Logger'),
|
||||
$c->query('UserId')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('ItemApiController', function($c) {
|
||||
return new ItemApiController(
|
||||
$c->query('API'),
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('ItemBusinessLayer')
|
||||
$c->query('ItemBusinessLayer'),
|
||||
$c->query('UserId')
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -175,7 +190,7 @@ class News extends App {
|
|||
$container->registerService('FolderBusinessLayer', function($c) {
|
||||
return new FolderBusinessLayer(
|
||||
$c->query('FolderMapper'),
|
||||
$c->query('API'),
|
||||
$c->query('L10N'),
|
||||
$c->query('TimeFactory'),
|
||||
$c->query('Config')
|
||||
);
|
||||
|
@ -186,7 +201,8 @@ class News extends App {
|
|||
$c->query('FeedMapper'),
|
||||
$c->query('Fetcher'),
|
||||
$c->query('ItemMapper'),
|
||||
$c->query('API'),
|
||||
$c->query('Logger'),
|
||||
$c->query('L10N'),
|
||||
$c->query('TimeFactory'),
|
||||
$c->query('Config'),
|
||||
$c->query('Enhancer'),
|
||||
|
@ -209,38 +225,55 @@ class News extends App {
|
|||
*/
|
||||
$container->registerService('MapperFactory', function($c) {
|
||||
return new MapperFactory(
|
||||
$c->query('API')
|
||||
$c->query('Settings'), $c->query('Db')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('FolderMapper', function($c) {
|
||||
return new FolderMapper(
|
||||
$c->query('API')
|
||||
$c->query('Db')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('FeedMapper', function($c) {
|
||||
return new FeedMapper(
|
||||
$c->query('API')
|
||||
$c->query('Db')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('ItemMapper', function($c) {
|
||||
return $c->query('MapperFactory')->getItemMapper(
|
||||
$c->query('API')
|
||||
$c->query('Db')
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Core
|
||||
*/
|
||||
$container->registerService('L10N', function($c) {
|
||||
return \OC_L10N::get($c['AppName']);
|
||||
});
|
||||
|
||||
$container->registerService('UserId', function($c) {
|
||||
return \OCP\User::getUser();
|
||||
});
|
||||
|
||||
$container->registerService('Logger', function($c) {
|
||||
return new Logger($c['AppName']);
|
||||
});
|
||||
|
||||
$container->registerService('Db', function($c) {
|
||||
return new Db($c['AppName']);
|
||||
});
|
||||
|
||||
$container->registerService('Settings', function($c) {
|
||||
return new Settings($c['AppName'], $c['UserId']);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Utility
|
||||
*/
|
||||
$container->registerService('API', function($c){
|
||||
return new API(
|
||||
$c->query('AppName')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('ConfigView', function($c) {
|
||||
$view = new View('/news/config');
|
||||
if (!$view->file_exists('')) {
|
||||
|
@ -251,13 +284,13 @@ class News extends App {
|
|||
});
|
||||
|
||||
$container->registerService('Config', function($c) {
|
||||
$config = new Config($c->query('ConfigView'), $c->query('API'));
|
||||
$config = new Config($c->query('ConfigView'), $c->query('Logger'));
|
||||
$config->read('config.ini', true);
|
||||
return $config;
|
||||
});
|
||||
|
||||
$container->registerService('simplePieCacheDirectory', function($c) {
|
||||
$directory = $c->query('API')->getSystemValue('datadirectory') .
|
||||
$directory = $c->query('Settings')->getSystemValue('datadirectory') .
|
||||
'/news/cache/simplepie';
|
||||
|
||||
if(!is_dir($directory)) {
|
||||
|
@ -267,7 +300,7 @@ class News extends App {
|
|||
});
|
||||
|
||||
$container->registerService('HTMLPurifier', function($c) {
|
||||
$directory = $c->query('API')->getSystemValue('datadirectory') .
|
||||
$directory = $c->query('Settings')->getSystemValue('datadirectory') .
|
||||
'/news/cache/purifier';
|
||||
|
||||
if(!is_dir($directory)) {
|
||||
|
@ -329,9 +362,7 @@ class News extends App {
|
|||
});
|
||||
|
||||
$container->registerService('FeedFetcher', function($c) {
|
||||
return new FeedFetcher(
|
||||
$c->query('API'),
|
||||
$c->query('SimplePieAPIFactory'),
|
||||
return new FeedFetcher($c->query('SimplePieAPIFactory'),
|
||||
$c->query('FaviconFetcher'),
|
||||
$c->query('TimeFactory'),
|
||||
$c->query('simplePieCacheDirectory'),
|
||||
|
|
|
@ -24,31 +24,28 @@
|
|||
|
||||
namespace OCA\News;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
|
||||
$api = new API('news');
|
||||
|
||||
$api->addNavigationEntry(array(
|
||||
\OCP\App::addNavigationEntry(array(
|
||||
|
||||
// the string under which your app will be referenced in owncloud
|
||||
'id' => $api->getAppName(),
|
||||
'id' => 'news',
|
||||
|
||||
// sorting weight for the navigation. The higher the number, the higher
|
||||
// will it be listed in the navigation
|
||||
'order' => 10,
|
||||
|
||||
// the route that will be shown on startup
|
||||
'href' => $api->linkToRoute('news.page.index'),
|
||||
'href' => \OCP\Util::linkToRoute('news.page.index'),
|
||||
|
||||
// the icon that will be shown in the navigation
|
||||
// this file needs to exist in img/example.png
|
||||
'icon' => $api->imagePath('news.svg'),
|
||||
'icon' => \OCP\Util::imagePath('news', 'news.svg'),
|
||||
|
||||
// the title of your application. This will be used in the
|
||||
// navigation or on the settings page of your app
|
||||
'name' => $api->getTrans()->t('News')
|
||||
'name' => \OC_L10N::get('news')->t('News')
|
||||
|
||||
));
|
||||
|
||||
$api->addRegularTask('OCA\News\Backgroundjob\Task', 'run');
|
||||
$api->connectHook('OC_User', 'pre_deleteUser', 'OCA\News\Hooks\User', 'deleteUser');
|
||||
\OCP\Backgroundjob::addRegularTask('OCA\News\Backgroundjob\Task', 'run');
|
||||
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\News\Hooks\User', 'deleteUser');
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
*/
|
||||
|
||||
namespace OCA\News\BusinessLayer;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Logger;
|
||||
use \OCA\News\Db\DoesNotExistException;
|
||||
use \OCA\News\Db\Feed;
|
||||
use \OCA\News\Db\Item;
|
||||
|
@ -41,14 +40,18 @@ class FeedBusinessLayer extends BusinessLayer {
|
|||
|
||||
private $feedFetcher;
|
||||
private $itemMapper;
|
||||
private $api;
|
||||
private $logger;
|
||||
private $l10n;
|
||||
private $timeFactory;
|
||||
private $autoPurgeMinimumInterval;
|
||||
private $enhancer;
|
||||
private $purifier;
|
||||
|
||||
public function __construct(FeedMapper $feedMapper, Fetcher $feedFetcher,
|
||||
ItemMapper $itemMapper, API $api,
|
||||
public function __construct(FeedMapper $feedMapper,
|
||||
Fetcher $feedFetcher,
|
||||
ItemMapper $itemMapper,
|
||||
Logger $logger,
|
||||
$l10n,
|
||||
$timeFactory,
|
||||
Config $config,
|
||||
Enhancer $enhancer,
|
||||
|
@ -56,7 +59,8 @@ class FeedBusinessLayer extends BusinessLayer {
|
|||
parent::__construct($feedMapper);
|
||||
$this->feedFetcher = $feedFetcher;
|
||||
$this->itemMapper = $itemMapper;
|
||||
$this->api = $api;
|
||||
$this->logger = $logger;
|
||||
$this->l10n = $l10n;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->autoPurgeMinimumInterval = $config->getAutoPurgeMinimumInterval();
|
||||
$this->enhancer = $enhancer;
|
||||
|
@ -100,7 +104,7 @@ class FeedBusinessLayer extends BusinessLayer {
|
|||
try {
|
||||
$this->mapper->findByUrlHash($feed->getUrlHash(), $userId);
|
||||
throw new BusinessLayerConflictException(
|
||||
$this->api->getTrans()->t('Can not add feed: Exists already'));
|
||||
$this->l10n->t('Can not add feed: Exists already'));
|
||||
} catch(DoesNotExistException $ex){}
|
||||
|
||||
// insert feed
|
||||
|
@ -135,9 +139,9 @@ class FeedBusinessLayer extends BusinessLayer {
|
|||
|
||||
return $feed;
|
||||
} catch(FetcherException $ex){
|
||||
$this->api->log($ex->getMessage(), 'debug');
|
||||
$this->logger->log($ex->getMessage(), 'debug');
|
||||
throw new BusinessLayerException(
|
||||
$this->api->getTrans()->t(
|
||||
$this->l10n->t(
|
||||
'Can not add feed: URL does not exist or has invalid xml'));
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +157,7 @@ class FeedBusinessLayer extends BusinessLayer {
|
|||
try {
|
||||
$this->update($feed->getId(), $feed->getUserId());
|
||||
} catch(BusinessLayerException $ex){
|
||||
$this->api->log('Could not update feed ' . $ex->getMessage(),
|
||||
$this->logger->log('Could not update feed ' . $ex->getMessage(),
|
||||
'debug');
|
||||
}
|
||||
}
|
||||
|
@ -203,9 +207,9 @@ class FeedBusinessLayer extends BusinessLayer {
|
|||
|
||||
} catch(FetcherException $ex){
|
||||
// failed updating is not really a problem, so only log it
|
||||
$this->api->log('Can not update feed with url ' . $existingFeed->getUrl() .
|
||||
$this->logger->log('Can not update feed with url ' . $existingFeed->getUrl() .
|
||||
': Not found or bad source', 'debug');
|
||||
$this->api->log($ex->getMessage(), 'debug');
|
||||
$this->logger->log($ex->getMessage(), 'debug');
|
||||
}
|
||||
|
||||
return $this->mapper->find($feedId, $userId);
|
||||
|
@ -282,7 +286,7 @@ class FeedBusinessLayer extends BusinessLayer {
|
|||
$feed->setUserId($userId);
|
||||
$feed->setLink($url);
|
||||
$feed->setUrl($url);
|
||||
$feed->setTitle($this->api->getTrans()->t('Articles without feed'));
|
||||
$feed->setTitle($this->l10n->t('Articles without feed'));
|
||||
$feed->setAdded($this->timeFactory->getTime());
|
||||
$feed->setFolderId(0);
|
||||
$feed->setPreventUpdate(true);
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
namespace OCA\News\BusinessLayer;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Db\Folder;
|
||||
use \OCA\News\Db\FolderMapper;
|
||||
use \OCA\News\Utility\Config;
|
||||
|
@ -33,16 +32,16 @@ use \OCA\News\Utility\Config;
|
|||
|
||||
class FolderBusinessLayer extends BusinessLayer {
|
||||
|
||||
private $api;
|
||||
private $l10n;
|
||||
private $timeFactory;
|
||||
private $autoPurgeMinimumInterval;
|
||||
|
||||
public function __construct(FolderMapper $folderMapper,
|
||||
API $api,
|
||||
$l10n,
|
||||
$timeFactory,
|
||||
Config $config){
|
||||
parent::__construct($folderMapper);
|
||||
$this->api = $api;
|
||||
$this->l10n = $l10n;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->autoPurgeMinimumInterval = $config->getAutoPurgeMinimumInterval();
|
||||
}
|
||||
|
@ -62,7 +61,7 @@ class FolderBusinessLayer extends BusinessLayer {
|
|||
if(count($existingFolders) > 0){
|
||||
|
||||
throw new BusinessLayerConflictException(
|
||||
$this->api->getTrans()->t('Can not add folder: Exists already'));
|
||||
$this->l10n->t('Can not add folder: Exists already'));
|
||||
}
|
||||
|
||||
if(mb_strlen($folderName) === 0) {
|
||||
|
|
|
@ -32,17 +32,18 @@ use \OCP\AppFramework\Http\JSONResponse;
|
|||
use \OCP\AppFramework\Http\Response;
|
||||
|
||||
use \OCA\News\Utility\Updater;
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Settings;
|
||||
|
||||
class ApiController extends Controller {
|
||||
|
||||
private $updater;
|
||||
private $api;
|
||||
private $settings;
|
||||
|
||||
public function __construct(API $api, IRequest $request, Updater $updater){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
public function __construct($appName, IRequest $request, Updater $updater,
|
||||
Settings $settings){
|
||||
parent::__construct($appName, $request);
|
||||
$this->updater = $updater;
|
||||
$this->api = $api;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,7 +53,7 @@ class ApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function version() {
|
||||
$version = $this->api->getAppValue('installed_version');
|
||||
$version = $this->settings->getAppValue('installed_version');
|
||||
$response = new JSONResponse(array('version' => $version));
|
||||
return $response;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ use \OCP\AppFramework\Http\JSONResponse;
|
|||
use \OCP\AppFramework\Http\Response;
|
||||
|
||||
use \OCA\News\Http\TextDownloadResponse;
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\BusinessLayer\FeedBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\FolderBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\ItemBusinessLayer;
|
||||
|
@ -44,19 +43,21 @@ class ExportController extends Controller {
|
|||
private $folderBusinessLayer;
|
||||
private $feedBusinessLayer;
|
||||
private $itemBusinessLayer;
|
||||
private $api;
|
||||
private $userId;
|
||||
|
||||
public function __construct(API $api, IRequest $request,
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
FeedBusinessLayer $feedBusinessLayer,
|
||||
FolderBusinessLayer $folderBusinessLayer,
|
||||
ItemBusinessLayer $itemBusinessLayer,
|
||||
OPMLExporter $opmlExporter){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
OPMLExporter $opmlExporter,
|
||||
$userId){
|
||||
parent::__construct($appName, $request);
|
||||
$this->feedBusinessLayer = $feedBusinessLayer;
|
||||
$this->folderBusinessLayer = $folderBusinessLayer;
|
||||
$this->opmlExporter = $opmlExporter;
|
||||
$this->itemBusinessLayer = $itemBusinessLayer;
|
||||
$this->api = $api;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,9 +66,8 @@ class ExportController extends Controller {
|
|||
* @NoCSRFRequired
|
||||
*/
|
||||
public function opml(){
|
||||
$userId = $this->api->getUserId();
|
||||
$feeds = $this->feedBusinessLayer->findAll($userId);
|
||||
$folders = $this->folderBusinessLayer->findAll($userId);
|
||||
$feeds = $this->feedBusinessLayer->findAll($this->userId);
|
||||
$folders = $this->folderBusinessLayer->findAll($this->userId);
|
||||
$opml = $this->opmlExporter->build($folders, $feeds)->saveXML();
|
||||
return new TextDownloadResponse($opml, 'subscriptions.opml', 'text/xml');
|
||||
}
|
||||
|
@ -78,9 +78,8 @@ class ExportController extends Controller {
|
|||
* @NoCSRFRequired
|
||||
*/
|
||||
public function articles(){
|
||||
$userId = $this->api->getUserId();
|
||||
$feeds = $this->feedBusinessLayer->findAll($userId);
|
||||
$items = $this->itemBusinessLayer->getUnreadOrStarred($userId);
|
||||
$feeds = $this->feedBusinessLayer->findAll($this->userId);
|
||||
$items = $this->itemBusinessLayer->getUnreadOrStarred($this->userId);
|
||||
|
||||
// build assoc array for fast access
|
||||
$feedsDict = array();
|
||||
|
|
|
@ -30,7 +30,7 @@ use \OCP\AppFramework\Controller;
|
|||
use \OCP\AppFramework\Http;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Logger;
|
||||
use \OCA\News\BusinessLayer\FeedBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\FolderBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\ItemBusinessLayer;
|
||||
|
@ -43,18 +43,22 @@ class FeedApiController extends Controller {
|
|||
private $itemBusinessLayer;
|
||||
private $feedBusinessLayer;
|
||||
private $folderBusinessLayer;
|
||||
private $api;
|
||||
private $userId;
|
||||
private $logger;
|
||||
|
||||
public function __construct(API $api,
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
FolderBusinessLayer $folderBusinessLayer,
|
||||
FeedBusinessLayer $feedBusinessLayer,
|
||||
ItemBusinessLayer $itemBusinessLayer){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
ItemBusinessLayer $itemBusinessLayer,
|
||||
Logger $logger,
|
||||
$userId){
|
||||
parent::__construct($appName, $request);
|
||||
$this->folderBusinessLayer = $folderBusinessLayer;
|
||||
$this->feedBusinessLayer = $feedBusinessLayer;
|
||||
$this->itemBusinessLayer = $itemBusinessLayer;
|
||||
$this->api = $api;
|
||||
$this->userId = $userId;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,21 +68,20 @@ class FeedApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function index() {
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
$result = array(
|
||||
'feeds' => array(),
|
||||
'starredCount' => $this->itemBusinessLayer->starredCount($userId)
|
||||
'starredCount' => $this->itemBusinessLayer->starredCount($this->userId)
|
||||
);
|
||||
|
||||
foreach ($this->feedBusinessLayer->findAll($userId) as $feed) {
|
||||
foreach ($this->feedBusinessLayer->findAll($this->userId) as $feed) {
|
||||
array_push($result['feeds'], $feed->toAPI());
|
||||
}
|
||||
|
||||
// check case when there are no items
|
||||
try {
|
||||
$result['newestItemId'] =
|
||||
$this->itemBusinessLayer->getNewestItemId($userId);
|
||||
$this->itemBusinessLayer->getNewestItemId($this->userId);
|
||||
} catch(BusinessLayerException $ex) {}
|
||||
|
||||
return new JSONResponse($result);
|
||||
|
@ -91,21 +94,20 @@ class FeedApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function create() {
|
||||
$userId = $this->api->getUserId();
|
||||
$feedUrl = $this->params('url');
|
||||
$folderId = (int) $this->params('folderId', 0);
|
||||
|
||||
try {
|
||||
$this->feedBusinessLayer->purgeDeleted($userId, false);
|
||||
$this->feedBusinessLayer->purgeDeleted($this->userId, false);
|
||||
|
||||
$feed = $this->feedBusinessLayer->create($feedUrl, $folderId, $userId);
|
||||
$feed = $this->feedBusinessLayer->create($feedUrl, $folderId, $this->userId);
|
||||
$result = array(
|
||||
'feeds' => array($feed->toAPI())
|
||||
);
|
||||
|
||||
try {
|
||||
$result['newestItemId'] =
|
||||
$this->itemBusinessLayer->getNewestItemId($userId);
|
||||
$this->itemBusinessLayer->getNewestItemId($this->userId);
|
||||
} catch(BusinessLayerException $ex) {}
|
||||
|
||||
return new JSONResponse($result);
|
||||
|
@ -126,11 +128,10 @@ class FeedApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function delete() {
|
||||
$userId = $this->api->getUserId();
|
||||
$feedId = (int) $this->params('feedId');
|
||||
|
||||
try {
|
||||
$this->feedBusinessLayer->delete($feedId, $userId);
|
||||
$this->feedBusinessLayer->delete($feedId, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex) {
|
||||
return new JSONResponse(array('message' => $ex->getMessage()),
|
||||
|
@ -145,11 +146,10 @@ class FeedApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function read() {
|
||||
$userId = $this->api->getUserId();
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$newestItemId = (int) $this->params('newestItemId');
|
||||
|
||||
$this->itemBusinessLayer->readFeed($feedId, $newestItemId, $userId);
|
||||
$this->itemBusinessLayer->readFeed($feedId, $newestItemId, $this->userId);
|
||||
return new JSONResponse();
|
||||
}
|
||||
|
||||
|
@ -160,12 +160,11 @@ class FeedApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function move() {
|
||||
$userId = $this->api->getUserId();
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$folderId = (int) $this->params('folderId');
|
||||
|
||||
try {
|
||||
$this->feedBusinessLayer->move($feedId, $folderId, $userId);
|
||||
$this->feedBusinessLayer->move($feedId, $folderId, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex) {
|
||||
return new JSONResponse(array('message' => $ex->getMessage()),
|
||||
|
@ -180,12 +179,11 @@ class FeedApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function rename() {
|
||||
$userId = $this->api->getUserId();
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$feedTitle = $this->params('feedTitle');
|
||||
|
||||
try {
|
||||
$this->feedBusinessLayer->rename($feedId, $feedTitle, $userId);
|
||||
$this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex) {
|
||||
return new JSONResponse(array('message' => $ex->getMessage()),
|
||||
|
@ -225,7 +223,7 @@ class FeedApiController extends Controller {
|
|||
$this->feedBusinessLayer->update($feedId, $userId);
|
||||
// ignore update failure (feed could not be reachable etc, we dont care)
|
||||
} catch(\Exception $ex) {
|
||||
$this->api->log('Could not update feed ' . $ex->getMessage(),
|
||||
$this->logger->log('Could not update feed ' . $ex->getMessage(),
|
||||
'debug');
|
||||
}
|
||||
return new JSONResponse();
|
||||
|
|
|
@ -30,7 +30,7 @@ use \OCP\AppFramework\Controller;
|
|||
use \OCP\AppFramework\Http;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Settings;
|
||||
use \OCA\News\BusinessLayer\ItemBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\FeedBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\FolderBusinessLayer;
|
||||
|
@ -44,17 +44,22 @@ class FeedController extends Controller {
|
|||
private $feedBusinessLayer;
|
||||
private $folderBusinessLayer;
|
||||
private $itemBusinessLayer;
|
||||
private $api;
|
||||
private $userId;
|
||||
private $settings;
|
||||
|
||||
public function __construct(API $api, IRequest $request,
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
FolderBusinessLayer $folderBusinessLayer,
|
||||
FeedBusinessLayer $feedBusinessLayer,
|
||||
ItemBusinessLayer $itemBusinessLayer){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
ItemBusinessLayer $itemBusinessLayer,
|
||||
$userId,
|
||||
Settings $settings){
|
||||
parent::__construct($appName, $request);
|
||||
$this->feedBusinessLayer = $feedBusinessLayer;
|
||||
$this->folderBusinessLayer = $folderBusinessLayer;
|
||||
$this->itemBusinessLayer = $itemBusinessLayer;
|
||||
$this->api = $api;
|
||||
$this->userId = $userId;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,19 +67,18 @@ class FeedController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function index(){
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
// this method is also used to update the interface
|
||||
// because of this we also pass the starred count and the newest
|
||||
// item id which will be used for marking feeds read
|
||||
$params = array(
|
||||
'feeds' => $this->feedBusinessLayer->findAll($userId),
|
||||
'starred' => $this->itemBusinessLayer->starredCount($userId)
|
||||
'feeds' => $this->feedBusinessLayer->findAll($this->userId),
|
||||
'starred' => $this->itemBusinessLayer->starredCount($this->userId)
|
||||
);
|
||||
|
||||
try {
|
||||
$params['newestItemId'] =
|
||||
$this->itemBusinessLayer->getNewestItemId($userId);
|
||||
$this->itemBusinessLayer->getNewestItemId($this->userId);
|
||||
} catch (BusinessLayerException $ex) {}
|
||||
|
||||
return new JSONResponse($params);
|
||||
|
@ -85,9 +89,8 @@ class FeedController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function active(){
|
||||
$userId = $this->api->getUserId();
|
||||
$feedId = (int) $this->api->getUserValue('lastViewedFeedId');
|
||||
$feedType = $this->api->getUserValue('lastViewedFeedType');
|
||||
$feedId = (int) $this->settings->getUserValue('lastViewedFeedId');
|
||||
$feedType = $this->settings->getUserValue('lastViewedFeedType');
|
||||
|
||||
// cast from null to int is 0
|
||||
if($feedType !== null){
|
||||
|
@ -97,10 +100,10 @@ class FeedController extends Controller {
|
|||
// check if feed or folder exists
|
||||
try {
|
||||
if($feedType === FeedType::FOLDER){
|
||||
$this->folderBusinessLayer->find($feedId, $userId);
|
||||
$this->folderBusinessLayer->find($feedId, $this->userId);
|
||||
|
||||
} elseif ($feedType === FeedType::FEED){
|
||||
$this->feedBusinessLayer->find($feedId, $userId);
|
||||
$this->feedBusinessLayer->find($feedId, $this->userId);
|
||||
|
||||
// if its the first launch, those values will be null
|
||||
} elseif($feedType === null){
|
||||
|
@ -129,21 +132,20 @@ class FeedController extends Controller {
|
|||
public function create(){
|
||||
$url = $this->params('url');
|
||||
$parentFolderId = (int) $this->params('parentFolderId');
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
try {
|
||||
// we need to purge deleted feeds if a feed is created to
|
||||
// prevent already exists exceptions
|
||||
$this->feedBusinessLayer->purgeDeleted($userId, false);
|
||||
$this->feedBusinessLayer->purgeDeleted($this->userId, false);
|
||||
|
||||
$feed = $this->feedBusinessLayer->create($url, $parentFolderId, $userId);
|
||||
$feed = $this->feedBusinessLayer->create($url, $parentFolderId, $this->userId);
|
||||
$params = array(
|
||||
'feeds' => array($feed)
|
||||
);
|
||||
|
||||
try {
|
||||
$params['newestItemId'] =
|
||||
$this->itemBusinessLayer->getNewestItemId($userId);
|
||||
$this->itemBusinessLayer->getNewestItemId($this->userId);
|
||||
} catch (BusinessLayerException $ex) {}
|
||||
|
||||
return new JSONResponse($params);
|
||||
|
@ -166,10 +168,9 @@ class FeedController extends Controller {
|
|||
*/
|
||||
public function delete(){
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
try {
|
||||
$this->feedBusinessLayer->markDeleted($feedId, $userId);
|
||||
$this->feedBusinessLayer->markDeleted($feedId, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex) {
|
||||
return new JSONResponse(array(
|
||||
|
@ -185,9 +186,8 @@ class FeedController extends Controller {
|
|||
public function update(){
|
||||
try {
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
$feed = $this->feedBusinessLayer->update($feedId, $userId);
|
||||
$feed = $this->feedBusinessLayer->update($feedId, $this->userId);
|
||||
|
||||
$params = array(
|
||||
'feeds' => array(
|
||||
|
@ -216,10 +216,9 @@ class FeedController extends Controller {
|
|||
public function move(){
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$parentFolderId = (int) $this->params('parentFolderId');
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
try {
|
||||
$this->feedBusinessLayer->move($feedId, $parentFolderId, $userId);
|
||||
$this->feedBusinessLayer->move($feedId, $parentFolderId, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex) {
|
||||
return new JSONResponse(array(
|
||||
|
@ -234,10 +233,9 @@ class FeedController extends Controller {
|
|||
public function rename() {
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$feedTitle = $this->params('feedTitle');
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
try {
|
||||
$this->feedBusinessLayer->rename($feedId, $feedTitle, $userId);
|
||||
$this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex) {
|
||||
return new JSONResponse(array(
|
||||
|
@ -251,9 +249,8 @@ class FeedController extends Controller {
|
|||
*/
|
||||
public function import() {
|
||||
$json = $this->params('json');
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
$feed = $this->feedBusinessLayer->importArticles($json, $userId);
|
||||
$feed = $this->feedBusinessLayer->importArticles($json, $this->userId);
|
||||
|
||||
$params = array();
|
||||
if($feed) {
|
||||
|
@ -268,11 +265,10 @@ class FeedController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function read(){
|
||||
$userId = $this->api->getUserId();
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$highestItemId = (int) $this->params('highestItemId');
|
||||
|
||||
$this->itemBusinessLayer->readFeed($feedId, $highestItemId, $userId);
|
||||
$this->itemBusinessLayer->readFeed($feedId, $highestItemId, $this->userId);
|
||||
|
||||
$params = array(
|
||||
'feeds' => array(
|
||||
|
@ -291,10 +287,9 @@ class FeedController extends Controller {
|
|||
*/
|
||||
public function restore(){
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$userId = $this->api->getUserId();
|
||||
|
||||
try {
|
||||
$this->feedBusinessLayer->unmarkDeleted($feedId, $userId);
|
||||
$this->feedBusinessLayer->unmarkDeleted($feedId, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex) {
|
||||
return new JSONResponse(array(
|
||||
|
|
|
@ -30,7 +30,6 @@ use \OCP\AppFramework\Controller;
|
|||
use \OCP\AppFramework\Http;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\BusinessLayer\FolderBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\ItemBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\BusinessLayerException;
|
||||
|
@ -42,16 +41,17 @@ class FolderApiController extends Controller {
|
|||
|
||||
private $folderBusinessLayer;
|
||||
private $itemBusinessLayer;
|
||||
private $api;
|
||||
private $userId;
|
||||
|
||||
public function __construct(API $api,
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
FolderBusinessLayer $folderBusinessLayer,
|
||||
ItemBusinessLayer $itemBusinessLayer){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
ItemBusinessLayer $itemBusinessLayer,
|
||||
$userId){
|
||||
parent::__construct($appName, $request);
|
||||
$this->folderBusinessLayer = $folderBusinessLayer;
|
||||
$this->itemBusinessLayer = $itemBusinessLayer;
|
||||
$this->api = $api;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,12 +61,11 @@ class FolderApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function index() {
|
||||
$userId = $this->api->getUserId();
|
||||
$result = array(
|
||||
'folders' => array()
|
||||
);
|
||||
|
||||
foreach ($this->folderBusinessLayer->findAll($userId) as $folder) {
|
||||
foreach ($this->folderBusinessLayer->findAll($this->userId) as $folder) {
|
||||
array_push($result['folders'], $folder->toAPI());
|
||||
}
|
||||
|
||||
|
@ -80,15 +79,14 @@ class FolderApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function create() {
|
||||
$userId = $this->api->getUserId();
|
||||
$folderName = $this->params('name');
|
||||
$result = array(
|
||||
'folders' => array()
|
||||
);
|
||||
|
||||
try {
|
||||
$this->folderBusinessLayer->purgeDeleted($userId, false);
|
||||
$folder = $this->folderBusinessLayer->create($folderName, $userId);
|
||||
$this->folderBusinessLayer->purgeDeleted($this->userId, false);
|
||||
$folder = $this->folderBusinessLayer->create($folderName, $this->userId);
|
||||
array_push($result['folders'], $folder->toAPI());
|
||||
|
||||
return new JSONResponse($result);
|
||||
|
@ -110,11 +108,10 @@ class FolderApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function delete() {
|
||||
$userId = $this->api->getUserId();
|
||||
$folderId = (int) $this->params('folderId');
|
||||
|
||||
try {
|
||||
$this->folderBusinessLayer->delete($folderId, $userId);
|
||||
$this->folderBusinessLayer->delete($folderId, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex) {
|
||||
return new JSONResponse(array('message' => $ex->getMessage()),
|
||||
|
@ -129,12 +126,11 @@ class FolderApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function update() {
|
||||
$userId = $this->api->getUserId();
|
||||
$folderId = (int) $this->params('folderId');
|
||||
$folderName = $this->params('name');
|
||||
|
||||
try {
|
||||
$this->folderBusinessLayer->rename($folderId, $folderName, $userId);
|
||||
$this->folderBusinessLayer->rename($folderId, $folderName, $this->userId);
|
||||
return new JSONResponse();
|
||||
|
||||
} catch(BusinessLayerValidationException $ex) {
|
||||
|
@ -158,11 +154,10 @@ class FolderApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function read() {
|
||||
$userId = $this->api->getUserId();
|
||||
$folderId = (int) $this->params('folderId');
|
||||
$newestItemId = (int) $this->params('newestItemId');
|
||||
|
||||
$this->itemBusinessLayer->readFolder($folderId, $newestItemId, $userId);
|
||||
$this->itemBusinessLayer->readFolder($folderId, $newestItemId, $this->userId);
|
||||
return new JSONResponse();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ use \OCP\AppFramework\Controller;
|
|||
use \OCP\AppFramework\Http;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\BusinessLayer\FolderBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\FeedBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\ItemBusinessLayer;
|
||||
|
@ -43,17 +42,18 @@ class FolderController extends Controller {
|
|||
private $folderBusinessLayer;
|
||||
private $feedBusinessLayer;
|
||||
private $itemBusinessLayer;
|
||||
private $api;
|
||||
private $userId;
|
||||
|
||||
public function __construct(API $api, IRequest $request,
|
||||
public function __construct($appName, IRequest $request,
|
||||
FolderBusinessLayer $folderBusinessLayer,
|
||||
FeedBusinessLayer $feedBusinessLayer,
|
||||
ItemBusinessLayer $itemBusinessLayer){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
ItemBusinessLayer $itemBusinessLayer,
|
||||
$userId){
|
||||
parent::__construct($appName, $request);
|
||||
$this->folderBusinessLayer = $folderBusinessLayer;
|
||||
$this->feedBusinessLayer = $feedBusinessLayer;
|
||||
$this->itemBusinessLayer = $itemBusinessLayer;
|
||||
$this->api = $api;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,7 +61,7 @@ class FolderController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function index(){
|
||||
$folders = $this->folderBusinessLayer->findAll($this->api->getUserId());
|
||||
$folders = $this->folderBusinessLayer->findAll($this->userId);
|
||||
$result = array(
|
||||
'folders' => $folders
|
||||
);
|
||||
|
@ -70,10 +70,9 @@ class FolderController extends Controller {
|
|||
|
||||
|
||||
private function setOpened($isOpened){
|
||||
$userId = $this->api->getUserId();
|
||||
$folderId = (int) $this->params('folderId');
|
||||
|
||||
$this->folderBusinessLayer->open($folderId, $isOpened, $userId);
|
||||
$this->folderBusinessLayer->open($folderId, $isOpened, $this->userId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -111,15 +110,14 @@ class FolderController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function create(){
|
||||
$userId = $this->api->getUserId();
|
||||
$folderName = $this->params('folderName');
|
||||
|
||||
try {
|
||||
// we need to purge deleted folders if a folder is created to
|
||||
// prevent already exists exceptions
|
||||
$this->folderBusinessLayer->purgeDeleted($userId, false);
|
||||
$this->folderBusinessLayer->purgeDeleted($this->userId, false);
|
||||
|
||||
$folder = $this->folderBusinessLayer->create($folderName, $userId);
|
||||
$folder = $this->folderBusinessLayer->create($folderName, $this->userId);
|
||||
|
||||
$params = array(
|
||||
'folders' => array($folder)
|
||||
|
@ -146,11 +144,10 @@ class FolderController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function delete(){
|
||||
$userId = $this->api->getUserId();
|
||||
$folderId = (int) $this->params('folderId');
|
||||
|
||||
try {
|
||||
$this->folderBusinessLayer->markDeleted($folderId, $userId);
|
||||
$this->folderBusinessLayer->markDeleted($folderId, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch (BusinessLayerException $ex){
|
||||
return new JSONResponse(array(
|
||||
|
@ -164,12 +161,13 @@ class FolderController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function rename(){
|
||||
$userId = $this->api->getUserId();
|
||||
$userId = $this->userId;
|
||||
$folderName = $this->params('folderName');
|
||||
$folderId = (int) $this->params('folderId');
|
||||
|
||||
try {
|
||||
$folder = $this->folderBusinessLayer->rename($folderId, $folderName, $userId);
|
||||
$folder = $this->folderBusinessLayer->rename($folderId, $folderName,
|
||||
$this->userId);
|
||||
|
||||
$params = array(
|
||||
'folders' => array($folder)
|
||||
|
@ -197,14 +195,13 @@ class FolderController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function read(){
|
||||
$userId = $this->api->getUserId();
|
||||
$folderId = (int) $this->params('folderId');
|
||||
$highestItemId = (int) $this->params('highestItemId');
|
||||
|
||||
$this->itemBusinessLayer->readFolder($folderId, $highestItemId, $userId);
|
||||
$this->itemBusinessLayer->readFolder($folderId, $highestItemId, $this->userId);
|
||||
|
||||
$params = array(
|
||||
'feeds' => $this->feedBusinessLayer->findAll($userId)
|
||||
'feeds' => $this->feedBusinessLayer->findAll($this->userId)
|
||||
);
|
||||
return new JSONResponse($params);
|
||||
}
|
||||
|
@ -214,11 +211,10 @@ class FolderController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function restore(){
|
||||
$userId = $this->api->getUserId();
|
||||
$folderId = (int) $this->params('folderId');
|
||||
|
||||
try {
|
||||
$this->folderBusinessLayer->unmarkDeleted($folderId, $userId);
|
||||
$this->folderBusinessLayer->unmarkDeleted($folderId, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch (BusinessLayerException $ex){
|
||||
return new JSONResponse(array(
|
||||
|
|
|
@ -32,19 +32,19 @@ use \OCP\AppFramework\Http\JSONResponse;
|
|||
|
||||
use \OCA\News\BusinessLayer\ItemBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\BusinessLayerException;
|
||||
use \OCA\News\Core\API;
|
||||
|
||||
class ItemApiController extends Controller {
|
||||
|
||||
private $itemBusinessLayer;
|
||||
private $api;
|
||||
private $userId;
|
||||
|
||||
public function __construct(API $api,
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
ItemBusinessLayer $itemBusinessLayer){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
ItemBusinessLayer $itemBusinessLayer,
|
||||
$userId){
|
||||
parent::__construct($appName, $request);
|
||||
$this->itemBusinessLayer = $itemBusinessLayer;
|
||||
$this->api = $api;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,7 +58,6 @@ class ItemApiController extends Controller {
|
|||
'items' => array()
|
||||
);
|
||||
|
||||
$userId = $this->api->getUserId();
|
||||
$batchSize = (int) $this->params('batchSize', 20);
|
||||
$offset = (int) $this->params('offset', 0);
|
||||
$type = (int) $this->params('type');
|
||||
|
@ -77,7 +76,7 @@ class ItemApiController extends Controller {
|
|||
$batchSize,
|
||||
$offset,
|
||||
$showAll,
|
||||
$userId
|
||||
$this->userId
|
||||
);
|
||||
|
||||
foreach ($items as $item) {
|
||||
|
@ -98,7 +97,6 @@ class ItemApiController extends Controller {
|
|||
'items' => array()
|
||||
);
|
||||
|
||||
$userId = $this->api->getUserId();
|
||||
$lastModified = (int) $this->params('lastModified', 0);
|
||||
$type = (int) $this->params('type');
|
||||
$id = (int) $this->params('id');
|
||||
|
@ -108,7 +106,7 @@ class ItemApiController extends Controller {
|
|||
$type,
|
||||
$lastModified,
|
||||
true,
|
||||
$userId
|
||||
$this->userId
|
||||
);
|
||||
|
||||
foreach ($items as $item) {
|
||||
|
@ -120,10 +118,9 @@ class ItemApiController extends Controller {
|
|||
|
||||
|
||||
private function setRead($isRead) {
|
||||
$userId = $this->api->getUserId();
|
||||
$itemId = (int) $this->params('itemId');
|
||||
try {
|
||||
$this->itemBusinessLayer->read($itemId, $isRead, $userId);
|
||||
$this->itemBusinessLayer->read($itemId, $isRead, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex){
|
||||
return new JSONResponse(array('message' => $ex->getMessage()),
|
||||
|
@ -133,11 +130,10 @@ class ItemApiController extends Controller {
|
|||
|
||||
|
||||
private function setStarred($isStarred) {
|
||||
$userId = $this->api->getUserId();
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$guidHash = $this->params('guidHash');
|
||||
try {
|
||||
$this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $userId);
|
||||
$this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $this->userId);
|
||||
return new JSONResponse();
|
||||
} catch(BusinessLayerException $ex){
|
||||
return new JSONResponse(array('message' => $ex->getMessage()),
|
||||
|
@ -192,21 +188,19 @@ class ItemApiController extends Controller {
|
|||
* @API
|
||||
*/
|
||||
public function readAll() {
|
||||
$userId = $this->api->getUserId();
|
||||
$newestItemId = (int) $this->params('newestItemId');
|
||||
|
||||
$this->itemBusinessLayer->readAll($newestItemId, $userId);
|
||||
$this->itemBusinessLayer->readAll($newestItemId, $this->userId);
|
||||
return new JSONResponse();
|
||||
}
|
||||
|
||||
|
||||
private function setMultipleRead($isRead) {
|
||||
$userId = $this->api->getUserId();
|
||||
$items = $this->params('items');
|
||||
|
||||
foreach($items as $id) {
|
||||
try {
|
||||
$this->itemBusinessLayer->read($id, $isRead, $userId);
|
||||
$this->itemBusinessLayer->read($id, $isRead, $this->userId);
|
||||
} catch(BusinessLayerException $ex) {
|
||||
continue;
|
||||
}
|
||||
|
@ -237,13 +231,12 @@ class ItemApiController extends Controller {
|
|||
|
||||
|
||||
private function setMultipleStarred($isStarred) {
|
||||
$userId = $this->api->getUserId();
|
||||
$items = $this->params('items');
|
||||
|
||||
foreach($items as $item) {
|
||||
try {
|
||||
$this->itemBusinessLayer->star($item['feedId'],
|
||||
$item['guidHash'], $isStarred, $userId);
|
||||
$item['guidHash'], $isStarred, $this->userId);
|
||||
} catch(BusinessLayerException $ex) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ use \OCP\AppFramework\Controller;
|
|||
use \OCP\AppFramework\Http;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Settings;
|
||||
use \OCA\News\BusinessLayer\BusinessLayerException;
|
||||
use \OCA\News\BusinessLayer\ItemBusinessLayer;
|
||||
use \OCA\News\BusinessLayer\FeedBusinessLayer;
|
||||
|
@ -40,15 +40,20 @@ class ItemController extends Controller {
|
|||
|
||||
private $itemBusinessLayer;
|
||||
private $feedBusinessLayer;
|
||||
private $api;
|
||||
private $userId;
|
||||
private $settings;
|
||||
|
||||
public function __construct(API $api, IRequest $request,
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
FeedBusinessLayer $feedBusinessLayer,
|
||||
ItemBusinessLayer $itemBusinessLayer){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
ItemBusinessLayer $itemBusinessLayer,
|
||||
$userId,
|
||||
Settings $settings){
|
||||
parent::__construct($appName, $request);
|
||||
$this->itemBusinessLayer = $itemBusinessLayer;
|
||||
$this->feedBusinessLayer = $feedBusinessLayer;
|
||||
$this->api = $api;
|
||||
$this->userId = $userId;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,16 +61,15 @@ class ItemController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function index(){
|
||||
$userId = $this->api->getUserId();
|
||||
$showAll = $this->api->getUserValue('showAll') === '1';
|
||||
$showAll = $this->settings->getUserValue('showAll') === '1';
|
||||
|
||||
$limit = $this->params('limit');
|
||||
$type = (int) $this->params('type');
|
||||
$id = (int) $this->params('id');
|
||||
$offset = (int) $this->params('offset', 0);
|
||||
|
||||
$this->api->setUserValue('lastViewedFeedId', $id);
|
||||
$this->api->setUserValue('lastViewedFeedType', $type);
|
||||
$this->settings->setUserValue('lastViewedFeedId', $id);
|
||||
$this->settings->setUserValue('lastViewedFeedType', $type);
|
||||
|
||||
$params = array();
|
||||
|
||||
|
@ -76,13 +80,13 @@ class ItemController extends Controller {
|
|||
// out of sync
|
||||
if($offset === 0) {
|
||||
$params['newestItemId'] =
|
||||
$this->itemBusinessLayer->getNewestItemId($userId);
|
||||
$params['feeds'] = $this->feedBusinessLayer->findAll($userId);
|
||||
$params['starred'] = $this->itemBusinessLayer->starredCount($userId);
|
||||
$this->itemBusinessLayer->getNewestItemId($this->userId);
|
||||
$params['feeds'] = $this->feedBusinessLayer->findAll($this->userId);
|
||||
$params['starred'] = $this->itemBusinessLayer->starredCount($this->userId);
|
||||
}
|
||||
|
||||
$params['items'] = $this->itemBusinessLayer->findAll($id, $type, $limit,
|
||||
$offset, $showAll, $userId);
|
||||
$offset, $showAll, $this->userId);
|
||||
// this gets thrown if there are no items
|
||||
// in that case just return an empty array
|
||||
} catch(BusinessLayerException $ex) {}
|
||||
|
@ -95,8 +99,7 @@ class ItemController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function newItems() {
|
||||
$userId = $this->api->getUserId();
|
||||
$showAll = $this->api->getUserValue('showAll') === '1';
|
||||
$showAll = $this->settings->getUserValue('showAll') === '1';
|
||||
|
||||
$type = (int) $this->params('type');
|
||||
$id = (int) $this->params('id');
|
||||
|
@ -105,11 +108,11 @@ class ItemController extends Controller {
|
|||
$params = array();
|
||||
|
||||
try {
|
||||
$params['newestItemId'] = $this->itemBusinessLayer->getNewestItemId($userId);
|
||||
$params['feeds'] = $this->feedBusinessLayer->findAll($userId);
|
||||
$params['starred'] = $this->itemBusinessLayer->starredCount($userId);
|
||||
$params['newestItemId'] = $this->itemBusinessLayer->getNewestItemId($this->userId);
|
||||
$params['feeds'] = $this->feedBusinessLayer->findAll($this->userId);
|
||||
$params['starred'] = $this->itemBusinessLayer->starredCount($this->userId);
|
||||
$params['items'] = $this->itemBusinessLayer->findAllNew($id, $type,
|
||||
$lastModified, $showAll, $userId);
|
||||
$lastModified, $showAll, $this->userId);
|
||||
// this gets thrown if there are no items
|
||||
// in that case just return an empty array
|
||||
} catch(BusinessLayerException $ex) {}
|
||||
|
@ -119,11 +122,10 @@ class ItemController extends Controller {
|
|||
|
||||
|
||||
private function setStarred($isStarred){
|
||||
$userId = $this->api->getUserId();
|
||||
$feedId = (int) $this->params('feedId');
|
||||
$guidHash = $this->params('guidHash');
|
||||
|
||||
$this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $userId);
|
||||
$this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $this->userId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -158,10 +160,9 @@ class ItemController extends Controller {
|
|||
|
||||
|
||||
private function setRead($isRead){
|
||||
$userId = $this->api->getUserId();
|
||||
$itemId = (int) $this->params('itemId');
|
||||
|
||||
$this->itemBusinessLayer->read($itemId, $isRead, $userId);
|
||||
$this->itemBusinessLayer->read($itemId, $isRead, $this->userId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -199,13 +200,12 @@ class ItemController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function readAll(){
|
||||
$userId = $this->api->getUserId();
|
||||
$highestItemId = (int) $this->params('highestItemId');
|
||||
|
||||
$this->itemBusinessLayer->readAll($highestItemId, $userId);
|
||||
$this->itemBusinessLayer->readAll($highestItemId, $this->userId);
|
||||
|
||||
$params = array(
|
||||
'feeds' => $this->feedBusinessLayer->findAll($userId)
|
||||
'feeds' => $this->feedBusinessLayer->findAll($this->userId)
|
||||
);
|
||||
return new JSONResponse($params);
|
||||
}
|
||||
|
|
|
@ -29,15 +29,18 @@ use \OCP\IRequest;
|
|||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
use \OCP\AppFramework\Controller;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Settings;
|
||||
|
||||
class PageController extends Controller {
|
||||
|
||||
private $api;
|
||||
private $settings;
|
||||
private $l10n;
|
||||
|
||||
public function __construct(API $api, IRequest $request){
|
||||
parent::__construct($api->getAppName(), $request);
|
||||
$this->api = $api;
|
||||
public function __construct($appName, IRequest $request, Settings $settings,
|
||||
$l10n){
|
||||
parent::__construct($appName, $request);
|
||||
$this->settings = $settings;
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,9 +57,9 @@ class PageController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function settings() {
|
||||
$showAll = $this->api->getUserValue('showAll');
|
||||
$compact = $this->api->getUserValue('compact');
|
||||
$language = $this->api->getTrans()->findLanguage();
|
||||
$showAll = $this->settings->getUserValue('showAll');
|
||||
$compact = $this->settings->getUserValue('compact');
|
||||
$language = $this->l10n->findLanguage();
|
||||
|
||||
$settings = array(
|
||||
'showAll' => $showAll === '1',
|
||||
|
@ -76,11 +79,11 @@ class PageController extends Controller {
|
|||
$isCompact = $this->params('compact', null);
|
||||
|
||||
if($isShowAll !== null) {
|
||||
$this->api->setUserValue('showAll', $isShowAll);
|
||||
$this->settings->setUserValue('showAll', $isShowAll);
|
||||
}
|
||||
|
||||
if($isCompact !== null) {
|
||||
$this->api->setUserValue('compact', $isCompact);
|
||||
$this->settings->setUserValue('compact', $isCompact);
|
||||
}
|
||||
|
||||
return new JSONResponse();
|
||||
|
|
546
core/api.php
546
core/api.php
|
@ -1,546 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\News\Core;
|
||||
|
||||
|
||||
/**
|
||||
* This is used to wrap the owncloud static api calls into an object to make the
|
||||
* code better abstractable for use in the dependency injection container
|
||||
*
|
||||
* Should you find yourself in need for more methods, simply inherit from this
|
||||
* class and add your methods
|
||||
*/
|
||||
class API {
|
||||
|
||||
private $appName;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $appName the name of your application
|
||||
*/
|
||||
public function __construct($appName){
|
||||
$this->appName = $appName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* used to return the appname of the set application
|
||||
* @return string the name of your application
|
||||
*/
|
||||
public function getAppName(){
|
||||
return $this->appName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new navigation entry
|
||||
* @param array $entry containing: id, name, order, icon and href key
|
||||
*/
|
||||
public function addNavigationEntry(array $entry){
|
||||
\OCP\App::addNavigationEntry($entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the userid of the current user
|
||||
* @return string the user id of the current user
|
||||
*/
|
||||
public function getUserId(){
|
||||
return \OCP\User::getUser();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the current navigation entry to the currently running app
|
||||
*/
|
||||
public function activateNavigationEntry(){
|
||||
\OCP\App::setActiveNavigationEntry($this->appName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new javascript file
|
||||
* @param string $scriptName the name of the javascript in js/ without the suffix
|
||||
* @param string $appName the name of the app, defaults to the current one
|
||||
*/
|
||||
public function addScript($scriptName, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
\OCP\Util::addScript($appName, $scriptName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new css file
|
||||
* @param string $styleName the name of the css file in css/without the suffix
|
||||
* @param string $appName the name of the app, defaults to the current one
|
||||
*/
|
||||
public function addStyle($styleName, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
\OCP\Util::addStyle($appName, $styleName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* shorthand for addScript for files in the 3rdparty directory
|
||||
* @param string $name the name of the file without the suffix
|
||||
*/
|
||||
public function add3rdPartyScript($name){
|
||||
\OCP\Util::addScript($this->appName . '/3rdparty', $name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* shorthand for addStyle for files in the 3rdparty directory
|
||||
* @param string $name the name of the file without the suffix
|
||||
*/
|
||||
public function add3rdPartyStyle($name){
|
||||
\OCP\Util::addStyle($this->appName . '/3rdparty', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up a systemwide defined value
|
||||
* @param string $key the key of the value, under which it was saved
|
||||
* @return string the saved value
|
||||
*/
|
||||
public function getSystemValue($key){
|
||||
return \OCP\Config::getSystemValue($key, '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a new systemwide value
|
||||
* @param string $key the key of the value, under which will be saved
|
||||
* @param string $value the value that should be stored
|
||||
*/
|
||||
public function setSystemValue($key, $value){
|
||||
return \OCP\Config::setSystemValue($key, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Looks up an appwide defined value
|
||||
* @param string $key the key of the value, under which it was saved
|
||||
* @return string the saved value
|
||||
*/
|
||||
public function getAppValue($key, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
return \OCP\Config::getAppValue($appName, $key, '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes a new appwide value
|
||||
* @param string $key the key of the value, under which will be saved
|
||||
* @param string $value the value that should be stored
|
||||
*/
|
||||
public function setAppValue($key, $value, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
return \OCP\Config::setAppValue($appName, $key, $value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut for setting a user defined value
|
||||
* @param string $key the key under which the value is being stored
|
||||
* @param string $value the value that you want to store
|
||||
* @param string $userId the userId of the user that we want to store the value under, defaults to the current one
|
||||
*/
|
||||
public function setUserValue($key, $value, $userId=null){
|
||||
if($userId === null){
|
||||
$userId = $this->getUserId();
|
||||
}
|
||||
\OCP\Config::setUserValue($userId, $this->appName, $key, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut for getting a user defined value
|
||||
* @param string $key the key under which the value is being stored
|
||||
* @param string $userId the userId of the user that we want to store the value under, defaults to the current one
|
||||
*/
|
||||
public function getUserValue($key, $userId=null){
|
||||
if($userId === null){
|
||||
$userId = $this->getUserId();
|
||||
}
|
||||
return \OCP\Config::getUserValue($userId, $this->appName, $key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the translation object
|
||||
* @return \OC_L10N the translation object
|
||||
*/
|
||||
public function getTrans(){
|
||||
# TODO: use public api
|
||||
return \OC_L10N::get($this->appName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to abstract the owncloud database access away
|
||||
* @param string $sql the sql query with ? placeholder for params
|
||||
* @param int $limit the maximum number of rows
|
||||
* @param int $offset from which row we want to start
|
||||
* @return \OCP\DB a query object
|
||||
*/
|
||||
public function prepareQuery($sql, $limit=null, $offset=null){
|
||||
return \OCP\DB::prepare($sql, $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to get the id of the just inserted element
|
||||
* @param string $tableName the name of the table where we inserted the item
|
||||
* @return int the id of the inserted element
|
||||
*/
|
||||
public function getInsertId($tableName){
|
||||
return \OCP\DB::insertid($tableName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the URL for a route
|
||||
* @param string $routeName the name of the route
|
||||
* @param array $arguments an array with arguments which will be filled into the url
|
||||
* @return string the url
|
||||
*/
|
||||
public function linkToRoute($routeName, $arguments=array()){
|
||||
return \OCP\Util::linkToRoute($routeName, $arguments);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an URL for an image or file
|
||||
* @param string $file the name of the file
|
||||
* @param string $appName the name of the app, defaults to the current one
|
||||
*/
|
||||
public function linkTo($file, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
return \OCP\Util::linkTo($appName, $file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the link to an image, like link to but only with prepending img/
|
||||
* @param string $file the name of the file
|
||||
* @param string $appName the name of the app, defaults to the current one
|
||||
*/
|
||||
public function imagePath($file, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
return \OCP\Util::imagePath($appName, $file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Makes an URL absolute
|
||||
* @param string $url the url
|
||||
* @return string the absolute url
|
||||
*/
|
||||
public function getAbsoluteURL($url){
|
||||
# TODO: use public api
|
||||
return \OC_Helper::makeURLAbsolute($url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* links to a file
|
||||
* @param string $file the name of the file
|
||||
* @param string $appName the name of the app, defaults to the current one
|
||||
* @deprecated replaced with linkToRoute()
|
||||
* @return string the url
|
||||
*/
|
||||
public function linkToAbsolute($file, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
return \OCP\Util::linkToAbsolute($appName, $file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the current user is logged in
|
||||
* @return bool true if logged in
|
||||
*/
|
||||
public function isLoggedIn(){
|
||||
return \OCP\User::isLoggedIn();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a user is an admin
|
||||
* @param string $userId the id of the user
|
||||
* @return bool true if admin
|
||||
*/
|
||||
public function isAdminUser($userId){
|
||||
# TODO: use public api
|
||||
return \OC_User::isAdminUser($userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a user is an subadmin
|
||||
* @param string $userId the id of the user
|
||||
* @return bool true if subadmin
|
||||
*/
|
||||
public function isSubAdminUser($userId){
|
||||
# TODO: use public api
|
||||
return \OC_SubAdmin::isSubAdmin($userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the CSRF check was correct
|
||||
* @return bool true if CSRF check passed
|
||||
*/
|
||||
public function passesCSRFCheck(){
|
||||
# TODO: use public api
|
||||
return \OC_Util::isCallRegistered();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if an app is enabled
|
||||
* @param string $appName the name of an app
|
||||
* @return bool true if app is enabled
|
||||
*/
|
||||
public function isAppEnabled($appName){
|
||||
return \OCP\App::isEnabled($appName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes a function into the error log
|
||||
* @param string $msg the error message to be logged
|
||||
* @param int $level the error level
|
||||
*/
|
||||
public function log($msg, $level=null){
|
||||
switch($level){
|
||||
case 'debug':
|
||||
$level = \OCP\Util::DEBUG;
|
||||
break;
|
||||
case 'info':
|
||||
$level = \OCP\Util::INFO;
|
||||
break;
|
||||
case 'warn':
|
||||
$level = \OCP\Util::WARN;
|
||||
break;
|
||||
case 'fatal':
|
||||
$level = \OCP\Util::FATAL;
|
||||
break;
|
||||
default:
|
||||
$level = \OCP\Util::ERROR;
|
||||
break;
|
||||
}
|
||||
\OCP\Util::writeLog($this->appName, $msg, $level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a template
|
||||
* @param string $templateName the name of the template
|
||||
* @param string $renderAs how it should be rendered
|
||||
* @param string $appName the name of the app
|
||||
* @return \OCP\Template a new template
|
||||
*/
|
||||
public function getTemplate($templateName, $renderAs='user', $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
|
||||
if($renderAs === 'blank'){
|
||||
return new \OCP\Template($appName, $templateName);
|
||||
} else {
|
||||
return new \OCP\Template($appName, $templateName, $renderAs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* turns an owncloud path into a path on the filesystem
|
||||
* @param string path the path to the file on the oc filesystem
|
||||
* @return string the filepath in the filesystem
|
||||
*/
|
||||
public function getLocalFilePath($path){
|
||||
# TODO: use public api
|
||||
return \OC_Filesystem::getLocalFile($path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* used to return and open a new eventsource
|
||||
* @return \OC_EventSource a new open EventSource class
|
||||
*/
|
||||
public function openEventSource(){
|
||||
# TODO: use public api
|
||||
return new \OC_EventSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief connects a function to a hook
|
||||
* @param string $signalClass class name of emitter
|
||||
* @param string $signalName name of signal
|
||||
* @param string $slotClass class name of slot
|
||||
* @param string $slotName name of slot, in another word, this is the
|
||||
* name of the method that will be called when registered
|
||||
* signal is emitted.
|
||||
* @return bool, always true
|
||||
*/
|
||||
public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
|
||||
return \OCP\Util::connectHook($signalClass, $signalName, $slotClass, $slotName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Emits a signal. To get data from the slot use references!
|
||||
* @param string $signalClass class name of emitter
|
||||
* @param string $signalName name of signal
|
||||
* @param array $params defautl: array() array with additional data
|
||||
* @return bool, true if slots exists or false if not
|
||||
*/
|
||||
public function emitHook($signalClass, $signalName, $params = array()) {
|
||||
return \OCP\Util::emitHook($signalClass, $signalName, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear hooks
|
||||
* @param string $signalClass
|
||||
* @param string $signalName
|
||||
*/
|
||||
public function clearHook($signalClass=false, $signalName=false) {
|
||||
if ($signalClass) {
|
||||
\OC_Hook::clear($signalClass, $signalName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of an URL by using CURL or a fallback if it is not
|
||||
* installed
|
||||
* @param string $url the url that should be fetched
|
||||
* @return string the content of the webpage
|
||||
*/
|
||||
public function getUrlContent($url) {
|
||||
return \OC_Util::getUrlContent($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a backgroundjob task
|
||||
* @param string $className full namespace and class name of the class
|
||||
* @param string $methodName the name of the static method that should be
|
||||
* called
|
||||
*/
|
||||
public function addRegularTask($className, $methodName) {
|
||||
\OCP\Backgroundjob::addRegularTask($className, $methodName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells ownCloud to include a template in the admin overview
|
||||
* @param string $mainPath the path to the main php file without the php
|
||||
* suffix, relative to your apps directory! not the template directory
|
||||
* @param string $appName the name of the app, defaults to the current one
|
||||
*/
|
||||
public function registerAdmin($mainPath, $appName=null) {
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
|
||||
\OCP\App::registerAdmin($appName, $mainPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do a user login
|
||||
* @param string $user the username
|
||||
* @param string $password the password
|
||||
* @return bool true if successful
|
||||
*/
|
||||
public function login($user, $password) {
|
||||
return \OC_User::login($user, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Loggs the user out including all the session data
|
||||
* Logout, destroys session
|
||||
*/
|
||||
public function logout() {
|
||||
return \OCP\User::logout();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the filesystem info
|
||||
*
|
||||
* @param string $path
|
||||
* @return array with the following keys:
|
||||
* - size
|
||||
* - mtime
|
||||
* - mimetype
|
||||
* - encrypted
|
||||
* - versioned
|
||||
*/
|
||||
public function getFileInfo($path) {
|
||||
return \OC\Files\Filesystem::getFileInfo($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the absolute path of an file
|
||||
* @deprecated
|
||||
* @see getView
|
||||
*
|
||||
* @param string $path the path inside ownCloud
|
||||
* @return string the absolute path (with fakeRoot)
|
||||
*/
|
||||
public function getAbsolutePath($path) {
|
||||
return \OC\Files\Filesystem::getView()->getAbsolutePath($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the view
|
||||
*
|
||||
* @return object View instance
|
||||
*/
|
||||
public function getView() {
|
||||
return \OC\Files\Filesystem::getView();
|
||||
}
|
||||
|
||||
/**
|
||||
* search the file base by mime type
|
||||
*
|
||||
* @param string $mimetype the mimetype to search for
|
||||
* @return array search results
|
||||
*/
|
||||
public function searchByMime($mimetype) {
|
||||
return \OC\Files\Filesystem::searchByMime($mimetype);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\News\Core;
|
||||
|
||||
class Db {
|
||||
|
||||
protected $appName;
|
||||
|
||||
public function __construct($appName) {
|
||||
$this->appName = $appName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to abstract the owncloud database access away
|
||||
* @param string $sql the sql query with ? placeholder for params
|
||||
* @param int $limit the maximum number of rows
|
||||
* @param int $offset from which row we want to start
|
||||
* @return \OCP\DB a query object
|
||||
*/
|
||||
public function prepareQuery($sql, $limit=null, $offset=null){
|
||||
return \OCP\DB::prepare($sql, $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to get the id of the just inserted element
|
||||
* @param string $tableName the name of the table where we inserted the item
|
||||
* @return int the id of the inserted element
|
||||
*/
|
||||
public function getInsertId($tableName){
|
||||
return \OCP\DB::insertid($tableName);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\News\Core;
|
||||
|
||||
class Logger {
|
||||
|
||||
protected $appName;
|
||||
|
||||
public function __construct($appName) {
|
||||
$this->appName = $appName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes a function into the error log
|
||||
* @param string $msg the error message to be logged
|
||||
* @param int $level the error level
|
||||
*/
|
||||
public function log($msg, $level=null){
|
||||
switch($level){
|
||||
case 'debug':
|
||||
$level = \OCP\Util::DEBUG;
|
||||
break;
|
||||
case 'info':
|
||||
$level = \OCP\Util::INFO;
|
||||
break;
|
||||
case 'warn':
|
||||
$level = \OCP\Util::WARN;
|
||||
break;
|
||||
case 'fatal':
|
||||
$level = \OCP\Util::FATAL;
|
||||
break;
|
||||
default:
|
||||
$level = \OCP\Util::ERROR;
|
||||
break;
|
||||
}
|
||||
\OCP\Util::writeLog($this->appName, $msg, $level);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\News\Core;
|
||||
|
||||
class Settings {
|
||||
|
||||
protected $appName;
|
||||
protected $userId;
|
||||
|
||||
public function __construct($appName, $userId) {
|
||||
$this->appName = $appName;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Looks up a systemwide defined value
|
||||
* @param string $key the key of the value, under which it was saved
|
||||
* @return string the saved value
|
||||
*/
|
||||
public function getSystemValue($key){
|
||||
return \OCP\Config::getSystemValue($key, '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a new systemwide value
|
||||
* @param string $key the key of the value, under which will be saved
|
||||
* @param string $value the value that should be stored
|
||||
*/
|
||||
public function setSystemValue($key, $value){
|
||||
return \OCP\Config::setSystemValue($key, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Looks up an appwide defined value
|
||||
* @param string $key the key of the value, under which it was saved
|
||||
* @return string the saved value
|
||||
*/
|
||||
public function getAppValue($key, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
return \OCP\Config::getAppValue($appName, $key, '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes a new appwide value
|
||||
* @param string $key the key of the value, under which will be saved
|
||||
* @param string $value the value that should be stored
|
||||
*/
|
||||
public function setAppValue($key, $value, $appName=null){
|
||||
if($appName === null){
|
||||
$appName = $this->appName;
|
||||
}
|
||||
return \OCP\Config::setAppValue($appName, $key, $value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut for setting a user defined value
|
||||
* @param string $key the key under which the value is being stored
|
||||
* @param string $value the value that you want to store
|
||||
* @param string $userId the userId of the user that we want to store the value under, defaults to the current one
|
||||
*/
|
||||
public function setUserValue($key, $value, $userId=null){
|
||||
if($userId === null){
|
||||
$userId = $this->userId;
|
||||
}
|
||||
\OCP\Config::setUserValue($userId, $this->appName, $key, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut for getting a user defined value
|
||||
* @param string $key the key under which the value is being stored
|
||||
* @param string $userId the userId of the user that we want to store the value under, defaults to the current one
|
||||
*/
|
||||
public function getUserValue($key, $userId=null){
|
||||
if($userId === null){
|
||||
$userId = $this->userId;
|
||||
}
|
||||
return \OCP\Config::getUserValue($userId, $this->appName, $key);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -25,14 +25,14 @@
|
|||
|
||||
namespace OCA\News\Db;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Db;
|
||||
|
||||
|
||||
class FeedMapper extends Mapper implements IMapper {
|
||||
|
||||
|
||||
public function __construct(API $api) {
|
||||
parent::__construct($api, 'news_feeds');
|
||||
public function __construct(Db $db) {
|
||||
parent::__construct($db, 'news_feeds', '\OCA\News\Db\Feed');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,13 +25,13 @@
|
|||
|
||||
namespace OCA\News\Db;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Db;
|
||||
|
||||
|
||||
class FolderMapper extends Mapper implements IMapper {
|
||||
|
||||
public function __construct(API $api) {
|
||||
parent::__construct($api, 'news_folders');
|
||||
public function __construct(Db $db) {
|
||||
parent::__construct($db, 'news_folders', '\OCA\News\Db\Folder');
|
||||
}
|
||||
|
||||
public function find($id, $userId){
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
|
||||
namespace OCA\News\Db;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Db;
|
||||
|
||||
class ItemMapper extends Mapper implements IMapper {
|
||||
|
||||
public function __construct(API $api){
|
||||
parent::__construct($api, 'news_items', '\OCA\News\Db\Item');
|
||||
public function __construct(Db $db){
|
||||
parent::__construct($db, 'news_items', '\OCA\News\Db\Item');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
namespace OCA\News\Db;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Db;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -37,15 +37,16 @@ abstract class Mapper {
|
|||
|
||||
protected $tableName;
|
||||
protected $entityClass;
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @param API $api Instance of the API abstraction layer
|
||||
* @param Db $db Instance of the Db abstraction layer
|
||||
* @param string $tableName the name of the table. set this to allow entity
|
||||
* @param string $entityClass the name of the entity that the sql should be
|
||||
* mapped to queries without using sql
|
||||
*/
|
||||
public function __construct(API $api, $tableName, $entityClass=null){
|
||||
$this->api = $api;
|
||||
public function __construct(Db $db, $tableName, $entityClass=null){
|
||||
$this->db = $db;
|
||||
$this->tableName = '*PREFIX*' . $tableName;
|
||||
|
||||
// if not given set the entity name to the class without the mapper part
|
||||
|
@ -114,7 +115,7 @@ abstract class Mapper {
|
|||
|
||||
$this->execute($sql, $params);
|
||||
|
||||
$entity->setId((int) $this->api->getInsertId($this->tableName));
|
||||
$entity->setId((int) $this->db->getInsertId($this->tableName));
|
||||
return $entity;
|
||||
}
|
||||
|
||||
|
@ -177,7 +178,7 @@ abstract class Mapper {
|
|||
* @return \PDOStatement the database query result
|
||||
*/
|
||||
protected function execute($sql, array $params=array(), $limit=null, $offset=null){
|
||||
$query = $this->api->prepareQuery($sql, $limit, $offset);
|
||||
$query = $this->db->prepareQuery($sql, $limit, $offset);
|
||||
|
||||
$index = 1; // bindParam is 1 indexed
|
||||
foreach($params as $param) {
|
||||
|
|
|
@ -25,25 +25,27 @@
|
|||
|
||||
namespace OCA\News\Db;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Settings;
|
||||
use \OCA\News\Core\Db;
|
||||
|
||||
|
||||
class MapperFactory {
|
||||
|
||||
private $api;
|
||||
private $settings;
|
||||
|
||||
public function __construct(API $api) {
|
||||
$this->api = $api;
|
||||
public function __construct(Settings $settings, Db $db) {
|
||||
$this->settings = $settings;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
|
||||
public function getItemMapper() {
|
||||
switch($this->api->getSystemValue('dbtype')) {
|
||||
switch($this->settings->getSystemValue('dbtype')) {
|
||||
case 'pgsql':
|
||||
return new \OCA\News\Db\Postgres\ItemMapper($this->api);
|
||||
return new \OCA\News\Db\Postgres\ItemMapper($this->db);
|
||||
break;
|
||||
default:
|
||||
return new ItemMapper($this->api);
|
||||
return new ItemMapper($this->db);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
namespace OCA\News\Db\Postgres;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Db;
|
||||
use \OCA\News\Db\DoesNotExistException;
|
||||
use \OCA\News\Db\MultipleObjectsReturnedException;
|
||||
use \OCA\News\Db\Mapper;
|
||||
|
@ -33,8 +33,8 @@ use \OCA\News\Db\StatusFlag;
|
|||
|
||||
class ItemMapper extends \OCA\News\Db\ItemMapper {
|
||||
|
||||
public function __construct(API $api){
|
||||
parent::__construct($api);
|
||||
public function __construct(Db $db){
|
||||
parent::__construct($db, 'news_items', '\OCA\News\Db\Item');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
namespace OCA\News\Fetcher;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Db\Item;
|
||||
use \OCA\News\Db\Feed;
|
||||
use \OCA\News\Utility\FaviconFetcher;
|
||||
|
@ -35,7 +34,6 @@ use \OCA\News\Utility\Config;
|
|||
|
||||
class FeedFetcher implements IFeedFetcher {
|
||||
|
||||
private $api;
|
||||
private $cacheDirectory;
|
||||
private $cacheDuration;
|
||||
private $faviconFetcher;
|
||||
|
@ -46,13 +44,11 @@ class FeedFetcher implements IFeedFetcher {
|
|||
private $proxyPort;
|
||||
private $proxyAuth;
|
||||
|
||||
public function __construct(API $api,
|
||||
SimplePieAPIFactory $simplePieFactory,
|
||||
public function __construct(SimplePieAPIFactory $simplePieFactory,
|
||||
FaviconFetcher $faviconFetcher,
|
||||
$time,
|
||||
$cacheDirectory,
|
||||
Config $config){
|
||||
$this->api = $api;
|
||||
$this->cacheDirectory = $cacheDirectory;
|
||||
$this->cacheDuration = $config->getSimplePieCacheDuration();
|
||||
$this->fetchTimeout = $config->getFeedFetcherTimeout();
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Alessandro Cosentino
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
|
||||
* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\News\Db;
|
||||
|
||||
use \OCA\News\Utility\MapperTestUtility;
|
||||
|
||||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class InMemoryDatabase {
|
||||
|
||||
private $db;
|
||||
|
||||
public function __construct(){
|
||||
$this->db = new \PDO('sqlite::memory:');
|
||||
}
|
||||
|
||||
|
||||
public function prepare($sql){
|
||||
$count = 1;
|
||||
$sql = str_replace('*PREFIX*', 'oc', $sql, $count);
|
||||
var_dump($this->db->prepare($sql));
|
||||
return $this->db->prepare($sql);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ItemMapperIntegrationTest extends MapperTestUtility {
|
||||
|
||||
protected $api;
|
||||
|
||||
private $mapper;
|
||||
private $db;
|
||||
|
||||
protected function setUp(){
|
||||
$db = new InMemoryDatabase();
|
||||
$prepare = function($sql) use ($db){
|
||||
return $db->prepare($sql);
|
||||
};
|
||||
|
||||
$this->api = $this->getMock('OCA\News\Core\API',
|
||||
array('prepareQuery', 'getInsertId'), array('news'));
|
||||
$this->api->expects($this->any())
|
||||
->method('prepareQuery')
|
||||
->will($this->returnCallback($prepare));
|
||||
$this->mapper = new ItemMapper($this->api);
|
||||
}
|
||||
|
||||
|
||||
public function testFind(){
|
||||
//$this->mapper->find(3, 'john');
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -30,7 +30,7 @@ use \OCA\News\Db\Item;
|
|||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class EnhancerTest extends \OCA\News\Utility\TestUtility {
|
||||
class EnhancerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $enhancer;
|
||||
private $articleEnhancer;
|
||||
|
|
|
@ -30,7 +30,7 @@ use \OCA\News\Db\Item;
|
|||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class RegexArticleEnhancerTest extends \OCA\News\Utility\TestUtility {
|
||||
class RegexArticleEnhancerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
|
||||
public function testRegexEnhancer() {
|
||||
|
|
|
@ -30,7 +30,7 @@ use \OCA\News\Db\Item;
|
|||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class XPathArticleEnhancerTest extends \OCA\News\Utility\TestUtility {
|
||||
class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $testEnhancer;
|
||||
private $fileFactory;
|
||||
|
|
|
@ -39,14 +39,12 @@ class TestBusinessLayer extends BusinessLayer {
|
|||
}
|
||||
}
|
||||
|
||||
class BusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
||||
class BusinessLayerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $api;
|
||||
protected $mapper;
|
||||
protected $newsBusinessLayer;
|
||||
|
||||
protected function setUp(){
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
|
|
@ -34,7 +34,7 @@ use \OCA\News\Db\Item;
|
|||
use \OCA\News\Fetcher\Fetcher;
|
||||
use \OCA\News\Fetcher\FetcherException;
|
||||
|
||||
class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
||||
class FeedBusinessLayerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $feedMapper;
|
||||
private $feedBusinessLayer;
|
||||
|
@ -48,9 +48,15 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
private $autoPurgeMinimumInterval;
|
||||
private $enhancer;
|
||||
private $purifier;
|
||||
private $l10n;
|
||||
private $logger;
|
||||
|
||||
protected function setUp(){
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->logger = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Logger')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->l10n = $this->getMock('L10N', array('t'));
|
||||
$this->time = 222;
|
||||
$this->autoPurgeMinimumInterval = 10;
|
||||
$timeFactory = $this->getMock('TimeFactory', array('getTime'));
|
||||
|
@ -79,7 +85,7 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
->will($this->returnValue($this->autoPurgeMinimumInterval));
|
||||
|
||||
$this->feedBusinessLayer = new FeedBusinessLayer($this->feedMapper,
|
||||
$this->fetcher, $this->itemMapper, $this->api,
|
||||
$this->fetcher, $this->itemMapper, $this->logger, $this->l10n,
|
||||
$timeFactory, $config,
|
||||
$this->enhancer, $this->purifier);
|
||||
$this->user = 'jack';
|
||||
|
@ -101,12 +107,8 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
public function testCreateDoesNotFindFeed(){
|
||||
$ex = new FetcherException('hi');
|
||||
$url = 'test';
|
||||
$trans = $this->getMock('Trans', array('t'));
|
||||
$trans->expects($this->once())
|
||||
$this->l10n->expects($this->once())
|
||||
->method('t');
|
||||
$this->api->expects($this->once())
|
||||
->method('getTrans')
|
||||
->will($this->returnValue($trans));
|
||||
$this->fetcher->expects($this->once())
|
||||
->method('fetch')
|
||||
->with($this->equalTo($url))
|
||||
|
@ -361,7 +363,7 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
$this->fetcher->expects($this->once())
|
||||
->method('fetch')
|
||||
->will($this->throwException($ex));
|
||||
$this->api->expects($this->any())
|
||||
$this->logger->expects($this->any())
|
||||
->method('log');
|
||||
|
||||
$this->feedMapper->expects($this->at(1))
|
||||
|
@ -601,17 +603,13 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
$insertFeed->setPreventUpdate(true);
|
||||
$insertFeed->setFolderId(0);
|
||||
|
||||
$trans = $this->getMock('trans', array('t'));
|
||||
$trans->expects($this->once())
|
||||
$this->l10n->expects($this->once())
|
||||
->method('t')
|
||||
->will($this->returnValue('Articles without feed'));
|
||||
$this->feedMapper->expects($this->once())
|
||||
->method('findAllFromUser')
|
||||
->with($this->equalTo($this->user))
|
||||
->will($this->returnValue($feeds));
|
||||
$this->api->expects($this->once())
|
||||
->method('getTrans')
|
||||
->will($this->returnValue($trans));
|
||||
$this->feedMapper->expects($this->once())
|
||||
->method('insert')
|
||||
->with($this->equalTo($insertFeed))
|
||||
|
|
|
@ -31,16 +31,17 @@ require_once(__DIR__ . "/../../classloader.php");
|
|||
use \OCA\News\Db\Folder;
|
||||
|
||||
|
||||
class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
||||
class FolderBusinessLayerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $folderMapper;
|
||||
private $folderBusinessLayer;
|
||||
private $time;
|
||||
private $user;
|
||||
private $autoPurgeMinimumInterval;
|
||||
private $l10n;
|
||||
|
||||
protected function setUp(){
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->l10n = $this->getMock('L10N', array('t'));
|
||||
$this->time = 222;
|
||||
$timeFactory = $this->getMock('TimeFactory', array('getTime'));
|
||||
$timeFactory->expects($this->any())
|
||||
|
@ -59,7 +60,7 @@ class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
->method('getAutoPurgeMinimumInterval')
|
||||
->will($this->returnValue($this->autoPurgeMinimumInterval));
|
||||
$this->folderBusinessLayer = new FolderBusinessLayer(
|
||||
$this->folderMapper, $this->api, $timeFactory,
|
||||
$this->folderMapper, $this->l10n, $timeFactory,
|
||||
$config);
|
||||
$this->user = 'hi';
|
||||
}
|
||||
|
@ -103,12 +104,8 @@ class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
array('id' => 1)
|
||||
);
|
||||
|
||||
$trans = $this->getMock('Trans', array('t'));
|
||||
$trans->expects($this->once())
|
||||
$this->l10n->expects($this->once())
|
||||
->method('t');
|
||||
$this->api->expects($this->once())
|
||||
->method('getTrans')
|
||||
->will($this->returnValue($trans));
|
||||
$this->folderMapper->expects($this->once())
|
||||
->method('findByName')
|
||||
->with($this->equalTo($folderName))
|
||||
|
@ -179,12 +176,8 @@ class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
array('id' => 1)
|
||||
);
|
||||
|
||||
$trans = $this->getMock('Trans', array('t'));
|
||||
$trans->expects($this->once())
|
||||
$this->l10n->expects($this->once())
|
||||
->method('t');
|
||||
$this->api->expects($this->once())
|
||||
->method('getTrans')
|
||||
->will($this->returnValue($trans));
|
||||
$this->folderMapper->expects($this->once())
|
||||
->method('findByName')
|
||||
->with($this->equalTo($folderName))
|
||||
|
|
|
@ -33,9 +33,8 @@ use \OCA\News\Db\StatusFlag;
|
|||
use \OCA\News\Db\FeedType;
|
||||
|
||||
|
||||
class ItemBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
||||
class ItemBusinessLayerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $api;
|
||||
private $mapper;
|
||||
private $itemBusinessLayer;
|
||||
private $user;
|
||||
|
@ -51,7 +50,6 @@ class ItemBusinessLayerTest extends \OCA\News\Utility\TestUtility {
|
|||
$timeFactory->expects($this->any())
|
||||
->method('getTime')
|
||||
->will($this->returnValue($this->time));
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace OCA\News\Db;
|
|||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class StatusFlagTest extends \OCA\News\Utility\TestUtility {
|
||||
class StatusFlagTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $statusFlag;
|
||||
|
||||
|
|
|
@ -36,14 +36,16 @@ require_once(__DIR__ . "/../../classloader.php");
|
|||
|
||||
class ApiControllerTest extends ControllerTestUtility {
|
||||
|
||||
private $api;
|
||||
private $settings;
|
||||
private $request;
|
||||
private $newsAPI;
|
||||
private $updater;
|
||||
private $appName;
|
||||
|
||||
protected function setUp() {
|
||||
$this->api = $this->getMockBuilder(
|
||||
'\OCA\News\Core\API')
|
||||
$this->appName = 'news';
|
||||
$this->settings = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Settings')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getMockBuilder(
|
||||
|
@ -54,7 +56,8 @@ class ApiControllerTest extends ControllerTestUtility {
|
|||
'\OCA\News\Utility\Updater')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->newsAPI = new ApiController($this->api, $this->request, $this->updater);
|
||||
$this->newsAPI = new ApiController($this->appName, $this->request,
|
||||
$this->updater, $this->settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,7 +81,7 @@ class ApiControllerTest extends ControllerTestUtility {
|
|||
}
|
||||
|
||||
public function testGetVersion(){
|
||||
$this->api->expects($this->once())
|
||||
$this->settings->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with($this->equalTo('installed_version'))
|
||||
->will($this->returnValue('1.0'));
|
||||
|
@ -115,7 +118,8 @@ class ApiControllerTest extends ControllerTestUtility {
|
|||
|
||||
public function testCors() {
|
||||
$this->request = $this->getRequest(array('server' => array()));
|
||||
$this->newsAPI = new ApiController($this->api, $this->request, $this->updater);
|
||||
$this->newsAPI = new ApiController($this->appName, $this->request,
|
||||
$this->updater, $this->settings);
|
||||
$response = $this->newsAPI->cors();
|
||||
|
||||
$headers = $response->getHeaders();
|
||||
|
@ -130,7 +134,8 @@ class ApiControllerTest extends ControllerTestUtility {
|
|||
|
||||
public function testCorsUsesOriginIfGiven() {
|
||||
$this->request = $this->getRequest(array('server' => array('HTTP_ORIGIN' => 'test')));
|
||||
$this->newsAPI = new ApiController($this->api, $this->request, $this->updater);
|
||||
$this->newsAPI = new ApiController($this->appName, $this->request,
|
||||
$this->updater, $this->settings);
|
||||
$response = $this->newsAPI->cors();
|
||||
|
||||
$headers = $response->getHeaders();
|
||||
|
|
|
@ -40,7 +40,7 @@ require_once(__DIR__ . "/../../classloader.php");
|
|||
|
||||
class ExportControllerTest extends ControllerTestUtility {
|
||||
|
||||
private $api;
|
||||
private $appName;
|
||||
private $request;
|
||||
private $controller;
|
||||
private $user;
|
||||
|
@ -53,7 +53,8 @@ class ExportControllerTest extends ControllerTestUtility {
|
|||
* Gets run before each test
|
||||
*/
|
||||
public function setUp(){
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->appName = 'news';
|
||||
$this->user = 'john';
|
||||
$this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -65,10 +66,9 @@ class ExportControllerTest extends ControllerTestUtility {
|
|||
->getMock();
|
||||
$this->request = $this->getRequest();
|
||||
$this->opmlExporter = new OPMLExporter();
|
||||
$this->controller = new ExportController($this->api, $this->request,
|
||||
$this->controller = new ExportController($this->appName, $this->request,
|
||||
$this->feedBusinessLayer, $this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer, $this->opmlExporter);
|
||||
$this->user = 'john';
|
||||
$this->itemBusinessLayer, $this->opmlExporter, $this->user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,9 +94,6 @@ class ExportControllerTest extends ControllerTestUtility {
|
|||
" <body/>\n" .
|
||||
"</opml>\n";
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
->with($this->equalTo($this->user))
|
||||
|
@ -130,9 +127,6 @@ class ExportControllerTest extends ControllerTestUtility {
|
|||
$item1, $item2
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
->with($this->equalTo($this->user))
|
||||
|
|
|
@ -45,16 +45,19 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
private $feedBusinessLayer;
|
||||
private $itemBusinessLayer;
|
||||
private $feedAPI;
|
||||
private $api;
|
||||
private $appName;
|
||||
private $user;
|
||||
private $request;
|
||||
private $msg;
|
||||
private $logger;
|
||||
|
||||
protected function setUp() {
|
||||
$this->api = $this->getMockBuilder(
|
||||
'\OCA\News\Core\API')
|
||||
$this->user = 'tom';
|
||||
$this->logger = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Logger')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->appName = 'news';
|
||||
$this->request = $this->getMockBuilder(
|
||||
'\OCP\IRequest')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -72,13 +75,14 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
$this->user = 'tom';
|
||||
$this->msg = 'hohoho';
|
||||
}
|
||||
|
||||
|
@ -133,9 +137,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
$starredCount = 3;
|
||||
$newestItemId = 2;
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('starredCount')
|
||||
->with($this->equalTo($this->user))
|
||||
|
@ -165,9 +166,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$starredCount = 3;
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('starredCount')
|
||||
->with($this->equalTo($this->user))
|
||||
|
@ -195,16 +193,15 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
'feedId' => 2
|
||||
)));
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
|
@ -223,16 +220,15 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
'feedId' => 2
|
||||
)));
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('delete')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -254,16 +250,15 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
'folderId' => 3
|
||||
)));
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -298,16 +293,15 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
'folderId' => 3
|
||||
)));
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -334,9 +328,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
|
||||
|
||||
public function testCreateExists() {
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -353,9 +344,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
|
||||
|
||||
public function testCreateError() {
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('create')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -378,16 +366,15 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
));
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('readFeed')
|
||||
->with(
|
||||
|
@ -412,16 +399,15 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
));
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('move')
|
||||
->with(
|
||||
|
@ -449,16 +435,15 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
));
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('rename')
|
||||
->with(
|
||||
|
@ -474,9 +459,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
|
||||
|
||||
public function testMoveDoesNotExist() {
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('move')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -512,11 +494,13 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
'userId' => $userId
|
||||
)));
|
||||
$this->feedAPI = new FeedApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->logger,
|
||||
$this->user
|
||||
);
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('update')
|
||||
|
@ -531,7 +515,7 @@ class FeedApiControllerTest extends ControllerTestUtility {
|
|||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('update')
|
||||
->will($this->throwException(new \Exception($this->msg)));
|
||||
$this->api->expects($this->once())
|
||||
$this->logger->expects($this->once())
|
||||
->method('log')
|
||||
->with($this->equalTo('Could not update feed ' . $this->msg),
|
||||
$this->equalTo('debug'));
|
||||
|
|
|
@ -40,19 +40,25 @@ require_once(__DIR__ . "/../../classloader.php");
|
|||
|
||||
class FeedControllerTest extends ControllerTestUtility {
|
||||
|
||||
private $api;
|
||||
private $appName;
|
||||
private $feedBusinessLayer;
|
||||
private $request;
|
||||
private $controller;
|
||||
private $folderBusinessLayer;
|
||||
private $itemBusinessLayer;
|
||||
private $settings;
|
||||
|
||||
|
||||
/**
|
||||
* Gets run before each test
|
||||
*/
|
||||
public function setUp(){
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->appName = 'news';
|
||||
$this->user = 'jack';
|
||||
$this->settings = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Settings')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -63,11 +69,12 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getRequest();
|
||||
$this->controller = new FeedController($this->api, $this->request,
|
||||
$this->controller = new FeedController($this->appName, $this->request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer);
|
||||
$this->user = 'jack';
|
||||
$this->itemBusinessLayer,
|
||||
$this->user,
|
||||
$this->settings);
|
||||
}
|
||||
|
||||
private function assertFeedControllerAnnotations($methodName){
|
||||
|
@ -83,10 +90,12 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
|
||||
$request = $this->getRequest($post);
|
||||
return new FeedController($this->api, $request,
|
||||
return new FeedController($this->appName, $request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer);
|
||||
$this->itemBusinessLayer,
|
||||
$this->user,
|
||||
$this->settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,9 +149,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
),
|
||||
'starred' => 13
|
||||
);
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
->with($this->equalTo($this->user))
|
||||
|
@ -171,9 +177,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
'starred' => 13,
|
||||
'newestItemId' => 5
|
||||
);
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
->with($this->equalTo($this->user))
|
||||
|
@ -196,14 +199,11 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
|
||||
|
||||
private function activeInitMocks($id, $type){
|
||||
$this->api->expects($this->at(0))
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->api->expects($this->at(1))
|
||||
$this->settings->expects($this->at(0))
|
||||
->method('getUserValue')
|
||||
->with($this->equalTo('lastViewedFeedId'))
|
||||
->will($this->returnValue($id));
|
||||
$this->api->expects($this->at(2))
|
||||
$this->settings->expects($this->at(1))
|
||||
->method('getUserValue')
|
||||
->with($this->equalTo('lastViewedFeedType'))
|
||||
->will($this->returnValue($type));
|
||||
|
@ -308,9 +308,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController($post);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('getNewestItemId')
|
||||
|
@ -343,9 +340,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController($post);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -371,9 +365,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
public function testCreateReturnsErrorForInvalidCreate(){
|
||||
$msg = 'except';
|
||||
$ex = new BusinessLayerException($msg);
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -393,9 +384,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
public function testCreateReturnsErrorForDuplicateCreate(){
|
||||
$msg = 'except';
|
||||
$ex = new BusinessLayerConflictException($msg);
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -418,9 +406,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('markDeleted')
|
||||
->with($this->equalTo($url['feedId']));
|
||||
|
@ -437,9 +422,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
$msg = 'hehe';
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('markDeleted')
|
||||
->will($this->throwException(new BusinessLayerException($msg)));
|
||||
|
@ -471,9 +453,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('update')
|
||||
->with($this->equalTo($url['feedId']), $this->equalTo($this->user))
|
||||
|
@ -498,9 +477,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('update')
|
||||
->with($this->equalTo($url['feedId']), $this->equalTo($this->user))
|
||||
|
@ -524,9 +500,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController($post, $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('move')
|
||||
->with($this->equalTo($url['feedId']),
|
||||
|
@ -549,9 +522,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
$msg = 'john';
|
||||
$this->controller = $this->getPostController($post, $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('move')
|
||||
->will($this->throwException(new BusinessLayerException($msg)));
|
||||
|
@ -574,9 +544,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController($post, $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('rename')
|
||||
->with($this->equalTo($url['feedId']),
|
||||
|
@ -600,9 +567,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
|
||||
$msg = 'hi';
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('rename')
|
||||
->with($this->equalTo($url['feedId']),
|
||||
|
@ -631,9 +595,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController($post);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('importArticles')
|
||||
->with($this->equalTo($post['json']),
|
||||
|
@ -656,9 +617,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
$expected = array();
|
||||
$this->controller = $this->getPostController($post);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('importArticles')
|
||||
->with($this->equalTo($post['json']),
|
||||
|
@ -689,9 +647,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('readFeed')
|
||||
->with($url['feedId'], $post['highestItemId'], $this->user);
|
||||
|
@ -708,9 +663,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('unmarkDeleted')
|
||||
->with($this->equalTo($url['feedId']));
|
||||
|
@ -727,9 +679,6 @@ class FeedControllerTest extends ControllerTestUtility {
|
|||
$msg = 'hehe';
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('unmarkDeleted')
|
||||
->will($this->throwException(new BusinessLayerException($msg)));
|
||||
|
|
|
@ -46,16 +46,14 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
private $folderBusinessLayer;
|
||||
private $itemBusinessLayer;
|
||||
private $folderAPI;
|
||||
private $api;
|
||||
private $appName;
|
||||
private $user;
|
||||
private $request;
|
||||
private $msg;
|
||||
|
||||
protected function setUp() {
|
||||
$this->api = $this->getMockBuilder(
|
||||
'\OCA\News\Core\API')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->appName = 'news';
|
||||
$this->user = 'tom';
|
||||
$this->request = $this->getMockBuilder(
|
||||
'\OCP\IRequest')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -69,12 +67,12 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
$this->user = 'tom';
|
||||
$this->msg = 'test';
|
||||
}
|
||||
|
||||
|
@ -115,9 +113,6 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
new Folder()
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
->with($this->equalTo($this->user))
|
||||
|
@ -139,17 +134,15 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
$folder
|
||||
);
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->getRequest(array('params' => array(
|
||||
'name' => $folderName
|
||||
))),
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -169,9 +162,6 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
public function testCreateAlreadyExists() {
|
||||
$msg = 'exists';
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -190,9 +180,6 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
public function testCreateInvalidFolderName() {
|
||||
$msg = 'exists';
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -212,17 +199,15 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
$folderId = 23;
|
||||
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->getRequest(array('urlParams' => array(
|
||||
'folderId' => $folderId
|
||||
))),
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('delete')
|
||||
->with($this->equalTo($folderId), $this->equalTo($this->user));
|
||||
|
@ -237,17 +222,15 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
$folderId = 23;
|
||||
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->getRequest(array('urlParams' => array(
|
||||
'folderId' => $folderId
|
||||
))),
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('delete')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -265,7 +248,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
$folderName = 'test';
|
||||
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->getRequest(
|
||||
array(
|
||||
'urlParams' => array(
|
||||
|
@ -278,12 +261,10 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
),
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('rename')
|
||||
->with($this->equalTo($folderId),
|
||||
|
@ -301,7 +282,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
$folderName = 'test';
|
||||
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->getRequest(
|
||||
array(
|
||||
'urlParams' => array(
|
||||
|
@ -314,12 +295,10 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
),
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('rename')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -337,7 +316,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
$folderName = 'test';
|
||||
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->getRequest(
|
||||
array(
|
||||
'urlParams' => array(
|
||||
|
@ -350,12 +329,10 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
),
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('rename')
|
||||
->will($this->throwException(new BusinessLayerConflictException($this->msg)));
|
||||
|
@ -373,7 +350,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
$folderName = '';
|
||||
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->getRequest(
|
||||
array(
|
||||
'urlParams' => array(
|
||||
|
@ -386,12 +363,10 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
),
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('rename')
|
||||
->will($this->throwException(new BusinessLayerValidationException($this->msg)));
|
||||
|
@ -414,15 +389,13 @@ class FolderApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
));
|
||||
$this->folderAPI = new FolderApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('readFolder')
|
||||
->with(
|
||||
|
|
|
@ -41,7 +41,7 @@ require_once(__DIR__ . "/../../classloader.php");
|
|||
|
||||
class FolderControllerTest extends ControllerTestUtility {
|
||||
|
||||
private $api;
|
||||
private $appName;
|
||||
private $folderBusinessLayer;
|
||||
private $itemBusinessLayer;
|
||||
private $feedBusinessLayer;
|
||||
|
@ -54,7 +54,8 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
* Gets run before each test
|
||||
*/
|
||||
public function setUp(){
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->appName = 'news';
|
||||
$this->user = 'jack';
|
||||
$this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -65,11 +66,11 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getRequest();
|
||||
$this->controller = new FolderController($this->api, $this->request,
|
||||
$this->controller = new FolderController($this->appName, $this->request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer);
|
||||
$this->user = 'jack';
|
||||
$this->itemBusinessLayer,
|
||||
$this->user);
|
||||
$this->msg = 'ron';
|
||||
}
|
||||
|
||||
|
@ -87,10 +88,11 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
|
||||
$request = $this->getRequest($post);
|
||||
return new FolderController($this->api, $request,
|
||||
return new FolderController($this->appName, $request,
|
||||
$this->folderBusinessLayer,
|
||||
$this->feedBusinessLayer,
|
||||
$this->itemBusinessLayer);
|
||||
$this->itemBusinessLayer,
|
||||
$this->user);
|
||||
}
|
||||
|
||||
public function testFoldersAnnotations(){
|
||||
|
@ -154,9 +156,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
$url = array('folderId' => 5);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('open')
|
||||
->with($this->equalTo($url['folderId']),
|
||||
|
@ -172,9 +171,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
$url = array('folderId' => 5);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('open')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -193,9 +189,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
$url = array('folderId' => 5);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('open')
|
||||
->with($this->equalTo($url['folderId']),
|
||||
|
@ -211,9 +204,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
$url = array('folderId' => 5);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('open')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -235,9 +225,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
'folders' => array(new Folder())
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -257,9 +244,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
public function testCreateReturnsErrorForInvalidCreate(){
|
||||
$msg = 'except';
|
||||
$ex = new BusinessLayerValidationException($msg);
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -279,9 +263,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
public function testCreateReturnsErrorForDuplicateCreate(){
|
||||
$msg = 'except';
|
||||
$ex = new BusinessLayerConflictException($msg);
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('purgeDeleted')
|
||||
->with($this->equalTo($this->user), $this->equalTo(false));
|
||||
|
@ -302,9 +283,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
$url = array('folderId' => 5);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('markDeleted')
|
||||
->with($this->equalTo($url['folderId']),
|
||||
|
@ -320,9 +298,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
$url = array('folderId' => 5);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('markDeleted')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -345,9 +320,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
'folders' => array(new Folder())
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('rename')
|
||||
->with($this->equalTo($url['folderId']),
|
||||
|
@ -424,9 +396,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
'feeds' => array($feed)
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('readFolder')
|
||||
->with($this->equalTo($url['folderId']),
|
||||
|
@ -447,9 +416,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
$url = array('folderId' => 5);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('unmarkDeleted')
|
||||
->with($this->equalTo($url['folderId']),
|
||||
|
@ -465,9 +431,6 @@ class FolderControllerTest extends ControllerTestUtility {
|
|||
$url = array('folderId' => 5);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('unmarkDeleted')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
|
|
@ -46,10 +46,8 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
private $msg;
|
||||
|
||||
protected function setUp() {
|
||||
$this->api = $this->getMockBuilder(
|
||||
'\OCA\News\Core\API')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->user = 'tom';
|
||||
$this->appName = 'news';
|
||||
$this->request = $this->getMockBuilder(
|
||||
'\OCP\IRequest')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -58,11 +56,11 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'\OCA\News\BusinessLayer\ItemBusinessLayer')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->user = 'tom';
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$this->request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
$this->msg = 'hi';
|
||||
}
|
||||
|
@ -141,14 +139,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'getRead' => 'false'
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
->with(
|
||||
|
@ -180,14 +176,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'getRead' => 'false'
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
->with(
|
||||
|
@ -218,14 +212,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'id' => 2,
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('findAllNew')
|
||||
->with(
|
||||
|
@ -250,14 +242,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'itemId' => 2
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('read')
|
||||
->with(
|
||||
|
@ -278,14 +268,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'itemId' => 2
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('read')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -303,14 +291,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'itemId' => 2
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('read')
|
||||
->with(
|
||||
|
@ -331,14 +317,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'itemId' => 2
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('read')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -357,14 +341,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'guidHash' => 'hash'
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('star')
|
||||
->with(
|
||||
|
@ -387,14 +369,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'guidHash' => 'hash'
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('star')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -413,14 +393,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'guidHash' => 'hash'
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('star')
|
||||
->with(
|
||||
|
@ -443,14 +421,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'guidHash' => 'hash'
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('star')
|
||||
->will($this->throwException(new BusinessLayerException($this->msg)));
|
||||
|
@ -470,14 +446,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('readAll')
|
||||
->with(
|
||||
|
@ -497,14 +471,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'items' => array(2, 4)
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->at(0))
|
||||
->method('read')
|
||||
->with($this->equalTo(2),
|
||||
|
@ -525,14 +497,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'items' => array(2, 4)
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->at(0))
|
||||
->method('read')
|
||||
->will($this->throwException(new BusinessLayerException('')));
|
||||
|
@ -550,14 +520,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
'items' => array(2, 4)
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->at(0))
|
||||
->method('read')
|
||||
->with($this->equalTo(2),
|
||||
|
@ -587,14 +555,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->at(0))
|
||||
->method('star')
|
||||
->with($this->equalTo(2),
|
||||
|
@ -626,14 +592,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->at(0))
|
||||
->method('star')
|
||||
->will($this->throwException(new BusinessLayerException('')));
|
||||
|
@ -661,14 +625,12 @@ class ItemApiControllerTest extends ControllerTestUtility {
|
|||
)
|
||||
)));
|
||||
$this->itemAPI = new ItemApiController(
|
||||
$this->api,
|
||||
$this->appName,
|
||||
$request,
|
||||
$this->itemBusinessLayer
|
||||
$this->itemBusinessLayer,
|
||||
$this->user
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->at(0))
|
||||
->method('star')
|
||||
->with($this->equalTo(2),
|
||||
|
|
|
@ -40,7 +40,8 @@ require_once(__DIR__ . "/../../classloader.php");
|
|||
|
||||
class ItemControllerTest extends ControllerTestUtility {
|
||||
|
||||
private $api;
|
||||
private $appName;
|
||||
private $settings;
|
||||
private $itemBusinessLayer;
|
||||
private $feedBusinessLayer;
|
||||
private $request;
|
||||
|
@ -52,7 +53,12 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
* Gets run before each test
|
||||
*/
|
||||
public function setUp(){
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->appName = 'news';
|
||||
$this->user = 'jackob';
|
||||
$this->settings = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Settings')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->itemBusinessLayer =
|
||||
$this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -62,9 +68,9 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getRequest();
|
||||
$this->controller = new ItemController($this->api, $this->request,
|
||||
$this->feedBusinessLayer, $this->itemBusinessLayer);
|
||||
$this->user = 'jackob';
|
||||
$this->controller = new ItemController($this->appName, $this->request,
|
||||
$this->feedBusinessLayer, $this->itemBusinessLayer, $this->user,
|
||||
$this->settings);
|
||||
$this->newestItemId = 12312;
|
||||
}
|
||||
|
||||
|
@ -75,8 +81,9 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
|
||||
$request = $this->getRequest($post);
|
||||
return new ItemController($this->api, $request,
|
||||
$this->feedBusinessLayer, $this->itemBusinessLayer);
|
||||
return new ItemController($this->appName, $request,
|
||||
$this->feedBusinessLayer, $this->itemBusinessLayer, $this->user,
|
||||
$this->settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,9 +132,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('read')
|
||||
->with($url['itemId'], true, $this->user);
|
||||
|
@ -145,9 +149,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
$msg = 'hi';
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('read')
|
||||
->will($this->throwException(new BusinessLayerException($msg)));
|
||||
|
@ -168,9 +169,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('read')
|
||||
->with($url['itemId'], false, $this->user);
|
||||
|
@ -187,9 +185,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
$msg = 'hi';
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('read')
|
||||
->will($this->throwException(new BusinessLayerException($msg)));
|
||||
|
@ -211,9 +206,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('star')
|
||||
->with(
|
||||
|
@ -235,9 +227,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
$msg = 'ho';
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('star')
|
||||
->will($this->throwException(new BusinessLayerException($msg)));;
|
||||
|
@ -258,9 +247,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('star')
|
||||
->with(
|
||||
|
@ -282,9 +268,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
$msg = 'ho';
|
||||
$this->controller = $this->getPostController(array(), $url);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('star')
|
||||
->will($this->throwException(new BusinessLayerException($msg)));;
|
||||
|
@ -308,9 +291,6 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
'feeds' => array($feed)
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('readAll')
|
||||
->with($this->equalTo($post['highestItemId']),
|
||||
|
@ -327,18 +307,15 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
|
||||
|
||||
private function itemsApiExpects($id, $type){
|
||||
$this->api->expects($this->once())
|
||||
$this->settings->expects($this->once())
|
||||
->method('getUserValue')
|
||||
->with($this->equalTo('showAll'))
|
||||
->will($this->returnValue('1'));
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->api->expects($this->at(2))
|
||||
$this->settings->expects($this->at(1))
|
||||
->method('setUserValue')
|
||||
->with($this->equalTo('lastViewedFeedId'),
|
||||
$this->equalTo($id));
|
||||
$this->api->expects($this->at(3))
|
||||
$this->settings->expects($this->at(2))
|
||||
->method('setUserValue')
|
||||
->with($this->equalTo('lastViewedFeedType'),
|
||||
$this->equalTo($type));
|
||||
|
@ -467,13 +444,10 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController($post);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
$this->settings->expects($this->once())
|
||||
->method('getUserValue')
|
||||
->with($this->equalTo('showAll'))
|
||||
->will($this->returnValue('1'));
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
|
||||
$this->feedBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
|
@ -515,13 +489,10 @@ class ItemControllerTest extends ControllerTestUtility {
|
|||
);
|
||||
$this->controller = $this->getPostController($post);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
$this->settings->expects($this->once())
|
||||
->method('getUserValue')
|
||||
->with($this->equalTo('showAll'))
|
||||
->will($this->returnValue('1'));
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
|
||||
$this->itemBusinessLayer->expects($this->once())
|
||||
->method('getNewestItemId')
|
||||
|
|
|
@ -36,19 +36,27 @@ require_once(__DIR__ . "/../../classloader.php");
|
|||
|
||||
class PageControllerTest extends ControllerTestUtility {
|
||||
|
||||
private $api;
|
||||
private $settings;
|
||||
private $appName;
|
||||
private $request;
|
||||
private $controller;
|
||||
private $user;
|
||||
private $l10n;
|
||||
|
||||
|
||||
/**
|
||||
* Gets run before each test
|
||||
*/
|
||||
public function setUp(){
|
||||
$this->api = $this->getAPIMock();
|
||||
$this->appName = 'news';
|
||||
$this->l10n = $this->getMock('L10N', array('findLanguage'));
|
||||
$this->settings = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Settings')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getRequest();
|
||||
$this->controller = new PageController($this->api, $this->request);
|
||||
$this->controller = new PageController($this->appName, $this->request,
|
||||
$this->settings, $this->l10n);
|
||||
$this->user = 'becka';
|
||||
}
|
||||
|
||||
|
@ -82,18 +90,14 @@ class PageControllerTest extends ControllerTestUtility {
|
|||
'language' => 'de'
|
||||
);
|
||||
|
||||
$lang = $this->getMock('Lang', array('findLanguage'));
|
||||
$lang->expects($this->once())
|
||||
$this->l10n->expects($this->once())
|
||||
->method('findLanguage')
|
||||
->will($this->returnValue('de'));
|
||||
$this->api->expects($this->once())
|
||||
->method('getTrans')
|
||||
->will($this->returnValue($lang));
|
||||
$this->api->expects($this->at(0))
|
||||
$this->settings->expects($this->at(0))
|
||||
->method('getUserValue')
|
||||
->with($this->equalTo('showAll'))
|
||||
->will($this->returnValue('1'));
|
||||
$this->api->expects($this->at(1))
|
||||
$this->settings->expects($this->at(1))
|
||||
->method('getUserValue')
|
||||
->with($this->equalTo('compact'))
|
||||
->will($this->returnValue('1'));
|
||||
|
@ -109,13 +113,14 @@ class PageControllerTest extends ControllerTestUtility {
|
|||
'showAll' => true,
|
||||
'compact' => true
|
||||
)));
|
||||
$this->controller = new PageController($this->api, $request);
|
||||
$this->controller = new PageController($this->appName, $request,
|
||||
$this->settings, $this->l10n);
|
||||
|
||||
$this->api->expects($this->at(0))
|
||||
$this->settings->expects($this->at(0))
|
||||
->method('setUserValue')
|
||||
->with($this->equalTo('showAll'),
|
||||
$this->equalTo(true));
|
||||
$this->api->expects($this->at(1))
|
||||
$this->settings->expects($this->at(1))
|
||||
->method('setUserValue')
|
||||
->with($this->equalTo('compact'),
|
||||
$this->equalTo(true));
|
||||
|
@ -129,9 +134,10 @@ class PageControllerTest extends ControllerTestUtility {
|
|||
$request = $this->getRequest(array('post' => array(
|
||||
'showAll' => true
|
||||
)));
|
||||
$this->controller = new PageController($this->api, $request);
|
||||
$this->controller = new PageController($this->appName, $request,
|
||||
$this->settings, $this->l10n);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
$this->settings->expects($this->once())
|
||||
->method('setUserValue')
|
||||
->with($this->equalTo('showAll'),
|
||||
$this->equalTo(true));
|
||||
|
|
|
@ -36,7 +36,7 @@ class FeedMapperTest extends \OCA\News\Utility\MapperTestUtility {
|
|||
protected function setUp(){
|
||||
$this->beforeEach();
|
||||
|
||||
$this->mapper = new FeedMapper($this->api);
|
||||
$this->mapper = new FeedMapper($this->db);
|
||||
|
||||
// create mock feeds
|
||||
$feed1 = new Feed();
|
||||
|
|
|
@ -37,7 +37,7 @@ class FolderMapperTest extends \OCA\News\Utility\MapperTestUtility {
|
|||
protected function setUp(){
|
||||
$this->beforeEach();
|
||||
|
||||
$this->folderMapper = new FolderMapper($this->api);
|
||||
$this->folderMapper = new FolderMapper($this->db);
|
||||
|
||||
// create mock folders
|
||||
$folder1 = new Folder();
|
||||
|
|
|
@ -44,7 +44,7 @@ class ItemMapperTest extends \OCA\News\Utility\MapperTestUtility {
|
|||
{
|
||||
$this->beforeEach();
|
||||
|
||||
$this->mapper = new ItemMapper($this->api);
|
||||
$this->mapper = new ItemMapper($this->db);
|
||||
|
||||
// create mock items
|
||||
$item1 = new Item();
|
||||
|
|
|
@ -31,42 +31,47 @@ require_once(__DIR__ . "/../../classloader.php");
|
|||
|
||||
class MapperFactoryTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $db;
|
||||
private $settings;
|
||||
|
||||
public function setUp() {
|
||||
$this->api = $this->getMockBuilder('\OCA\News\Core\API')
|
||||
$this->settings = $this->getMockBuilder('\OCA\News\Core\Settings')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->db = $this->getMockBuilder('\OCA\News\Core\Db')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
|
||||
public function testGetItemMapperSqlite() {
|
||||
$this->api->expects($this->once())
|
||||
$this->settings->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with($this->equalTo('dbtype'))
|
||||
->will($this->returnValue('sqlite'));
|
||||
$factory = new MapperFactory($this->api);
|
||||
$factory = new MapperFactory($this->settings, $this->db);
|
||||
|
||||
$this->assertTrue($factory->getItemMapper() instanceof ItemMapper);
|
||||
}
|
||||
|
||||
|
||||
public function testGetItemMapperMysql() {
|
||||
$this->api->expects($this->once())
|
||||
$this->settings->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with($this->equalTo('dbtype'))
|
||||
->will($this->returnValue('mysql'));
|
||||
$factory = new MapperFactory($this->api);
|
||||
$factory = new MapperFactory($this->settings, $this->db);
|
||||
|
||||
$this->assertTrue($factory->getItemMapper() instanceof ItemMapper);
|
||||
}
|
||||
|
||||
|
||||
public function testGetItemMapperPostgres() {
|
||||
$this->api->expects($this->once())
|
||||
$this->settings->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with($this->equalTo('dbtype'))
|
||||
->will($this->returnValue('pgsql'));
|
||||
$factory = new MapperFactory($this->api);
|
||||
$factory = new MapperFactory($this->settings, $this->db);
|
||||
|
||||
$this->assertTrue($factory->getItemMapper() instanceof \OCA\News\Db\Postgres\ItemMapper);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
namespace OCA\News\Db;
|
||||
|
||||
use OCA\News\Core\API;
|
||||
use OCA\News\Core\Db;
|
||||
use OCA\News\Utility\MapperTestUtility;
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@ class Example extends Entity {
|
|||
|
||||
|
||||
class ExampleMapper extends Mapper {
|
||||
public function __construct(API $api){ parent::__construct($api, 'table'); }
|
||||
public function __construct(Db $db){ parent::__construct($db, 'table'); }
|
||||
public function find($table, $id){ return $this->findOneQuery($table, $id); }
|
||||
public function findOneEntity($table, $id){ return $this->findEntity($table, $id); }
|
||||
public function findAll($table){ return $this->findAllQuery($table); }
|
||||
|
@ -54,7 +54,11 @@ class MapperTest extends MapperTestUtility {
|
|||
|
||||
public function setUp(){
|
||||
$this->beforeEach();
|
||||
$this->mapper = new ExampleMapper($this->api);
|
||||
$this->db = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Db')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->mapper = new ExampleMapper($this->db);
|
||||
}
|
||||
|
||||
|
||||
|
@ -141,11 +145,11 @@ class MapperTest extends MapperTestUtility {
|
|||
|
||||
|
||||
public function testCreate(){
|
||||
$this->api->expects($this->once())
|
||||
$this->db->expects($this->once())
|
||||
->method('getInsertId')
|
||||
->with($this->equalTo('*PREFIX*table'))
|
||||
->will($this->returnValue(3));
|
||||
$this->mapper = new ExampleMapper($this->api);
|
||||
$this->mapper = new ExampleMapper($this->db);
|
||||
|
||||
$sql = 'INSERT INTO `*PREFIX*table`(`pre_name`,`email`) ' .
|
||||
'VALUES(?,?)';
|
||||
|
@ -161,11 +165,11 @@ class MapperTest extends MapperTestUtility {
|
|||
|
||||
|
||||
public function testCreateShouldReturnItemWithCorrectInsertId(){
|
||||
$this->api->expects($this->once())
|
||||
$this->db->expects($this->once())
|
||||
->method('getInsertId')
|
||||
->with($this->equalTo('*PREFIX*table'))
|
||||
->will($this->returnValue(3));
|
||||
$this->mapper = new ExampleMapper($this->api);
|
||||
$this->mapper = new ExampleMapper($this->db);
|
||||
|
||||
$sql = 'INSERT INTO `*PREFIX*table`(`pre_name`,`email`) ' .
|
||||
'VALUES(?,?)';
|
||||
|
|
|
@ -48,7 +48,7 @@ class ItemMapperTest extends \OCA\News\Utility\MapperTestUtility {
|
|||
{
|
||||
$this->beforeEach();
|
||||
|
||||
$this->mapper = new ItemMapper($this->api);
|
||||
$this->mapper = new ItemMapper($this->db);
|
||||
|
||||
// create mock items
|
||||
$item1 = new Item();
|
||||
|
|
|
@ -31,7 +31,7 @@ use \OCA\News\Db\Feed;
|
|||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class FeedFetcherTest extends \OCA\News\Utility\TestUtility {
|
||||
class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $fetcher;
|
||||
private $core;
|
||||
|
@ -128,8 +128,7 @@ class FeedFetcherTest extends \OCA\News\Utility\TestUtility {
|
|||
$this->config->expects($this->any())
|
||||
->method('getFeedFetcherTimeout')
|
||||
->will($this->returnValue($this->fetchTimeout));
|
||||
$this->fetcher = new FeedFetcher($this->getAPIMock(),
|
||||
$this->coreFactory,
|
||||
$this->fetcher = new FeedFetcher($this->coreFactory,
|
||||
$this->faviconFetcher,
|
||||
$timeFactory,
|
||||
$this->cacheDirectory,
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace OCA\News\Fetcher;
|
|||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class FetcherTest extends \OCA\News\Utility\TestUtility {
|
||||
class FetcherTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $fetcher;
|
||||
|
||||
|
|
|
@ -28,15 +28,15 @@ namespace OCA\News\Utility;
|
|||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class ConfigFetcherTest extends \OCA\News\Utility\TestUtility {
|
||||
class ConfigFetcherTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $fileSystem;
|
||||
private $config;
|
||||
private $configPath;
|
||||
|
||||
public function setUp() {
|
||||
$this->api = $this->getMockBuilder(
|
||||
'\OCA\News\Core\API')
|
||||
$this->logger = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Logger')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->fileSystem = $this->getMock('FileSystem', array(
|
||||
|
@ -44,7 +44,7 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility {
|
|||
'file_put_contents',
|
||||
'file_exists'
|
||||
));
|
||||
$this->config = new Config($this->fileSystem, $this->api);
|
||||
$this->config = new Config($this->fileSystem, $this->logger);
|
||||
$this->configPath = 'config.json';
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility {
|
|||
->method('file_get_contents')
|
||||
->with($this->equalTo($this->configPath))
|
||||
->will($this->returnValue('autoPurgeCounts = 3'));
|
||||
$this->api->expects($this->once())
|
||||
$this->logger->expects($this->once())
|
||||
->method('log')
|
||||
->with($this->equalTo('Configuration value "autoPurgeCounts" ' .
|
||||
'does not exist. Ignored value.'),
|
||||
|
@ -109,7 +109,7 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility {
|
|||
->method('file_get_contents')
|
||||
->with($this->equalTo($this->configPath))
|
||||
->will($this->returnValue(''));
|
||||
$this->api->expects($this->once())
|
||||
$this->logger->expects($this->once())
|
||||
->method('log')
|
||||
->with($this->equalTo('Configuration invalid. Ignoring values.'),
|
||||
$this->equalTo('warn'));
|
||||
|
|
|
@ -31,7 +31,7 @@ use \OCA\News\Db\Feed;
|
|||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class OPMLExporterTest extends \OCA\News\Utility\TestUtility {
|
||||
class OPMLExporterTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $exporter;
|
||||
private $feed1;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
namespace OCA\News\Utility;
|
||||
|
||||
use \OCA\News\Core\API;
|
||||
use \OCA\News\Core\Logger;
|
||||
|
||||
|
||||
class Config {
|
||||
|
@ -43,17 +43,17 @@ class Config {
|
|||
private $proxyPort;
|
||||
private $proxyUser;
|
||||
private $proxyPassword;
|
||||
private $api;
|
||||
private $logger;
|
||||
|
||||
|
||||
public function __construct($fileSystem, API $api) {
|
||||
public function __construct($fileSystem, Logger $logger) {
|
||||
$this->fileSystem = $fileSystem;
|
||||
$this->autoPurgeMinimumInterval = 60;
|
||||
$this->autoPurgeCount = 200;
|
||||
$this->simplePieCacheDuration = 30*60;
|
||||
$this->feedFetcherTimeout = 60;
|
||||
$this->useCronUpdates = true;
|
||||
$this->api = $api;
|
||||
$this->logger = $logger;
|
||||
$this->proxyHost = '';
|
||||
$this->proxyPort = 8080;
|
||||
$this->proxyUser = '';
|
||||
|
@ -162,7 +162,7 @@ class Config {
|
|||
$configValues = parse_ini_string($content);
|
||||
|
||||
if($configValues === false || count($configValues) === 0) {
|
||||
$this->api->log('Configuration invalid. Ignoring values.' , 'warn');
|
||||
$this->logger->log('Configuration invalid. Ignoring values.' , 'warn');
|
||||
} else {
|
||||
|
||||
foreach($configValues as $key => $value) {
|
||||
|
@ -171,7 +171,7 @@ class Config {
|
|||
settype($value, $type);
|
||||
$this->$key = $value;
|
||||
} else {
|
||||
$this->api->log('Configuration value "' . $key .
|
||||
$this->logger->log('Configuration value "' . $key .
|
||||
'" does not exist. Ignored value.' , 'warn');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ use OCP\AppFramework\Http\Response;
|
|||
/**
|
||||
* Simple utility class for testing controllers
|
||||
*/
|
||||
abstract class ControllerTestUtility extends TestUtility {
|
||||
abstract class ControllerTestUtility extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,16 +24,16 @@
|
|||
|
||||
namespace OCA\News\Utility;
|
||||
|
||||
use OCA\News\Core\Api;
|
||||
use OCA\News\Core\Db;
|
||||
|
||||
|
||||
/**
|
||||
* Simple utility class for testing mappers
|
||||
*/
|
||||
abstract class MapperTestUtility extends TestUtility {
|
||||
abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
|
||||
protected $api;
|
||||
protected $db;
|
||||
private $query;
|
||||
private $pdoResult;
|
||||
private $queryAt;
|
||||
|
@ -44,12 +44,13 @@ abstract class MapperTestUtility extends TestUtility {
|
|||
|
||||
/**
|
||||
* Run this function before the actual test to either set or initialize the
|
||||
* api. After this the api can be accessed by using $this->api
|
||||
* db. After this the db can be accessed by using $this->db
|
||||
*/
|
||||
protected function beforeEach(){
|
||||
$this->api = $this->getMock('\OCA\News\Core\API',
|
||||
array('prepareQuery', 'getInsertId'),
|
||||
array('a'));
|
||||
$this->db = $this->getMockBuilder(
|
||||
'\OCA\News\Core\Db')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->query = $this->getMock('Query', array('execute', 'bindValue'));
|
||||
$this->pdoResult = $this->getMock('Result', array('fetchRow'));
|
||||
|
@ -127,24 +128,24 @@ abstract class MapperTestUtility extends TestUtility {
|
|||
$this->queryAt++;
|
||||
|
||||
if($limit === null && $offset === null) {
|
||||
$this->api->expects($this->at($this->prepareAt))
|
||||
$this->db->expects($this->at($this->prepareAt))
|
||||
->method('prepareQuery')
|
||||
->with($this->equalTo($sql))
|
||||
->will(($this->returnValue($this->query)));
|
||||
} elseif($limit !== null && $offset === null) {
|
||||
$this->api->expects($this->at($this->prepareAt))
|
||||
$this->db->expects($this->at($this->prepareAt))
|
||||
->method('prepareQuery')
|
||||
->with($this->equalTo($sql), $this->equalTo($limit))
|
||||
->will(($this->returnValue($this->query)));
|
||||
} elseif($limit === null && $offset !== null) {
|
||||
$this->api->expects($this->at($this->prepareAt))
|
||||
$this->db->expects($this->at($this->prepareAt))
|
||||
->method('prepareQuery')
|
||||
->with($this->equalTo($sql),
|
||||
$this->equalTo(null),
|
||||
$this->equalTo($offset))
|
||||
->will(($this->returnValue($this->query)));
|
||||
} else {
|
||||
$this->api->expects($this->at($this->prepareAt))
|
||||
$this->db->expects($this->at($this->prepareAt))
|
||||
->method('prepareQuery')
|
||||
->with($this->equalTo($sql),
|
||||
$this->equalTo($limit),
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\News\Utility;
|
||||
|
||||
/**
|
||||
* Simple utility class for testing anything using an api
|
||||
*/
|
||||
abstract class TestUtility extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
|
||||
/**
|
||||
* Boilerplate function for getting an API Mock class
|
||||
* @param string $apiClass the class inclusive namespace of the api that we
|
||||
* want to use
|
||||
* @param array $constructor constructor parameters of the api class
|
||||
*/
|
||||
protected function getAPIMock($apiClass='OCA\News\Core\API',
|
||||
array $constructor=array('appname')){
|
||||
$methods = get_class_methods($apiClass);
|
||||
return $this->getMock($apiClass, $methods, $constructor);
|
||||
}
|
||||
|
||||
|
||||
}
|
Загрузка…
Ссылка в новой задаче