From 21bd539847f33c3889c4f58f14afd672f54a410a Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 9 Apr 2014 01:44:12 +0200 Subject: ported to owncloud internal appframework classes, confused with how to start the app and define deps --- CHANGELOG | 3 +- README.rst | 30 +- api/feedapi.php | 16 +- api/folderapi.php | 16 +- api/itemapi.php | 17 +- api/newsapi.php | 19 +- appinfo/app.php | 2 +- appinfo/info.xml | 2 +- appinfo/routes.php | 2 +- businesslayer/feedbusinesslayer.php | 3 +- businesslayer/folderbusinesslayer.php | 3 +- controller/exportcontroller.php | 18 +- controller/feedcontroller.php | 16 +- controller/foldercontroller.php | 16 +- controller/itemcontroller.php | 16 +- controller/pagecontroller.php | 10 +- controller/usersettingscontroller.php | 15 +- core/api.php | 546 +++++++++++++++++++++ db/feedmapper.php | 2 +- db/foldermapper.php | 2 +- db/itemmapper.php | 2 +- db/mapper.php | 2 +- db/mapperfactory.php | 2 +- db/postgres/itemmapper.php | 3 +- dependencyinjection/dicontainer.php | 6 + fetcher/feedfetcher.php | 3 +- http/downloadresponse.php | 51 ++ http/textdownloadresponse.php | 59 +++ http/textresponse.php | 57 +++ middleware/corsmiddleware.php | 2 +- tests/classloader.php | 9 +- tests/integration/db/ItemMapperIntegrationTest.php | 4 +- tests/unit/api/FeedAPITest.php | 28 +- tests/unit/api/FolderAPITest.php | 28 +- tests/unit/api/ItemAPITest.php | 48 +- tests/unit/api/NewsAPITest.php | 16 +- tests/unit/articleenhancer/EnhancerTest.php | 2 +- .../articleenhancer/RegexArticleEnhancerTest.php | 2 +- .../articleenhancer/XPathArticleEnhancerTest.php | 2 +- tests/unit/businesslayer/BusinessLayerTest.php | 2 +- tests/unit/businesslayer/FeedBusinessLayerTest.php | 2 +- .../unit/businesslayer/FolderBusinessLayerTest.php | 2 +- tests/unit/businesslayer/ItemBusinessLayerTest.php | 2 +- tests/unit/businesslayer/StatusFlagTest.php | 4 +- tests/unit/controller/ExportControllerTest.php | 11 +- tests/unit/controller/FeedControllerTest.php | 12 +- tests/unit/controller/FolderControllerTest.php | 12 +- tests/unit/controller/ItemControllerTest.php | 10 +- tests/unit/controller/PageControllerTest.php | 8 +- .../unit/controller/UserSettingsControllerTest.php | 12 +- tests/unit/db/FeedMapperTest.php | 2 +- tests/unit/db/FolderMapperTest.php | 2 +- tests/unit/db/ItemMapperTest.php | 2 +- tests/unit/db/MapperFactoryTest.php | 2 +- tests/unit/db/MapperTest.php | 4 +- tests/unit/db/postgres/ItemMapperTest.php | 2 +- tests/unit/fetcher/FeedFetcherTest.php | 2 +- tests/unit/fetcher/FetcherTest.php | 2 +- tests/unit/http/DownloadResponseTest.php | 51 ++ tests/unit/http/TextDownloadResponseTest.php | 44 ++ tests/unit/http/TextResponseTest.php | 57 +++ tests/unit/utility/ConfigTest.php | 4 +- tests/unit/utility/OPMLExporterTest.php | 2 +- utility/config.php | 2 +- utility/controllertestutility.php | 115 +++++ utility/mappertestutility.php | 180 +++++++ utility/methodannotationreader.php | 61 +++ utility/simplepieapifactory.php | 2 +- utility/testutility.php | 46 ++ 69 files changed, 1507 insertions(+), 232 deletions(-) create mode 100644 core/api.php create mode 100644 http/downloadresponse.php create mode 100644 http/textdownloadresponse.php create mode 100644 http/textresponse.php create mode 100644 tests/unit/http/DownloadResponseTest.php create mode 100644 tests/unit/http/TextDownloadResponseTest.php create mode 100644 tests/unit/http/TextResponseTest.php create mode 100644 utility/controllertestutility.php create mode 100644 utility/mappertestutility.php create mode 100644 utility/methodannotationreader.php create mode 100644 utility/testutility.php diff --git a/CHANGELOG b/CHANGELOG index 1b9dded19..8253e06f4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,8 +2,9 @@ owncloud-news (2.001) * Delete folders, feeds and articles if a user is deleted * Also remember collapsed folders on postgres * Fix bug that would prevent articles from being deleted if a folder is marked as deleted on sqlite and postgres -* Require ownCloud 6.0.2 +* Require ownCloud 6.0.3 * Remove html tags from feed titles +* Port to built in core App Framework and thus removing the need to install the App Framework owncloud-news (1.808) * Also focus article area when clicking on all unread link diff --git a/README.rst b/README.rst index b057a6cdb..5859fb436 100644 --- a/README.rst +++ b/README.rst @@ -22,7 +22,7 @@ Minimum PHP Version Minimum ownCloud Version ------------------- -* >= 6.0.2 +* >= 6.0.3 Supported Webservers -------------------- @@ -40,7 +40,6 @@ Bugs Before reporting bugs: * We do not support Internet Explorer and Safari (Patches accepted though, except for IE < 10) -* get the newest version of the App Framework * get the newest version of the News app * `check if they have already been reported `_ @@ -65,7 +64,7 @@ Before you install the app check that the following requirements are met: - You can use a cron or webcron to call Background Jobs in ownCloud - Your **data/** directory is owned by your webserver user and write/readable - You have installed **php-curl** and activated it in the **php.ini** -- Install ownCloud **5.0.6+** (important!) +- Install ownCloud **6.0.3+** (important!) Should you have upgraded from a prior version, disable the CSS and JavaScript caching by adding this to :file:`owncloud/config/config.php`:: @@ -81,12 +80,12 @@ Installation ~~~~~~~~~~~~ - Go to the ownCloud apps page -- Activate the **App Framework** App first, then activate the **News** app in the apps menu +- Activate the **News** app in the apps menu - `Set up ownCloud Background Jobs `_ to enable feed updates. A recommended timespan for feed updates is 15-30 Minutes. Keep up to date ~~~~~~~~~~~~~~~ -Both the **News** and **App Framework** App can be updated through the ownCloud apps page. +The **News** App can be updated through the ownCloud apps page. Git (development version) @@ -95,33 +94,16 @@ Git (development version) Installation ~~~~~~~~~~~~ -- Clone the **App Framework** app into the **/var/www** directory:: - - git clone https://github.com/owncloud/appframework.git - -- Clone the **News** app into the **/var/www** directory:: +- Clone the **News** app into the **/var/www/owncloud/apps** directory:: git clone https://github.com/owncloud/news.git - -- Link both into ownCloud's apps folder:: - - ln -s /var/www/appframework /var/www/owncloud/apps - ln -s /var/www/news /var/www/owncloud/apps - -- Activate the **App Framework** App first, then activate the **News** app in the apps menu +- Activate the **News** app in the apps menu - `Set up ownCloud Background Jobs `_ to enable feed updates. A recommended timespan for feed updates is 15-30 Minutes. Keep up to date ~~~~~~~~~~~~~~~ - -To get the newest update you can use git. To update the appframework use:: - - cd /var/www/appframework - git pull --rebase origin master - - To update the News app use:: cd /var/www/news diff --git a/api/feedapi.php b/api/feedapi.php index 0880434d8..e77efef2e 100644 --- a/api/feedapi.php +++ b/api/feedapi.php @@ -25,12 +25,12 @@ namespace OCA\News\API; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Core\API; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\ItemBusinessLayer; @@ -43,16 +43,18 @@ class FeedAPI extends Controller { private $itemBusinessLayer; private $feedBusinessLayer; private $folderBusinessLayer; + private $api; public function __construct(API $api, - Request $request, + IRequest $request, FolderBusinessLayer $folderBusinessLayer, FeedBusinessLayer $feedBusinessLayer, ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api, $request); + parent::__construct($api->getAppName(), $request); $this->folderBusinessLayer = $folderBusinessLayer; $this->feedBusinessLayer = $feedBusinessLayer; $this->itemBusinessLayer = $itemBusinessLayer; + $this->api = $api; } diff --git a/api/folderapi.php b/api/folderapi.php index 12e400a76..67efa59ea 100644 --- a/api/folderapi.php +++ b/api/folderapi.php @@ -25,12 +25,12 @@ namespace OCA\News\API; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +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,14 +42,16 @@ class FolderAPI extends Controller { private $folderBusinessLayer; private $itemBusinessLayer; + private $api; public function __construct(API $api, - Request $request, + IRequest $request, FolderBusinessLayer $folderBusinessLayer, ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api, $request); + parent::__construct($api->getAppName(), $request); $this->folderBusinessLayer = $folderBusinessLayer; $this->itemBusinessLayer = $itemBusinessLayer; + $this->api = $api; } diff --git a/api/itemapi.php b/api/itemapi.php index 335132d60..821fdd382 100644 --- a/api/itemapi.php +++ b/api/itemapi.php @@ -25,25 +25,26 @@ namespace OCA\News\API; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; - +use \OCA\News\Core\API; class ItemAPI extends Controller { private $itemBusinessLayer; + private $api; public function __construct(API $api, - Request $request, + IRequest $request, ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api, $request); + parent::__construct($api->getAppName(), $request); $this->itemBusinessLayer = $itemBusinessLayer; + $this->api = $api; } diff --git a/api/newsapi.php b/api/newsapi.php index aaed92926..322defead 100644 --- a/api/newsapi.php +++ b/api/newsapi.php @@ -25,23 +25,24 @@ namespace OCA\News\API; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Response; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCP\AppFramework\Http\Response; use \OCA\News\Utility\Updater; - +use \OCA\News\Core\API; class NewsAPI extends Controller { private $updater; + private $api; - public function __construct(API $api, Request $request, Updater $updater){ - parent::__construct($api, $request); + public function __construct(API $api, IRequest $request, Updater $updater){ + parent::__construct($api->getAppName(), $request); $this->updater = $updater; + $this->api = $api; } diff --git a/appinfo/app.php b/appinfo/app.php index 6e9d0396d..b68ed51f0 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -24,7 +24,7 @@ namespace OCA\News; -use \OCA\AppFramework\Core\API; +use \OCA\News\Core\API; // dont break owncloud when the appframework is not enabled diff --git a/appinfo/info.xml b/appinfo/info.xml index 6b8dbb08a..76cbb4521 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -2,7 +2,7 @@ news News - An RSS/Atom feed reader. Requires the App Framework app and backgroundjobs need to be enabled. See the README.rst in the apps top directory + An RSS/Atom feed reader. Requires ownCloud backgroundjobs or an updater script to be enabled to update your feeds. See the README.rst in the apps top directory AGPL Alessandro Cosentino, Bernhard Posselt, Jan-Christoph Borchardt. Powered by SimplePie (Ryan Parman, Geoffrey Sneddon, Ryan McCue and contributors). 1.809 diff --git a/appinfo/routes.php b/appinfo/routes.php index fc60a717c..1eb0af953 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -25,7 +25,7 @@ namespace OCA\News; -use \OCA\AppFramework\App; +use \OCP\AppFramework\App; use \OCA\News\DependencyInjection\DIContainer; diff --git a/businesslayer/feedbusinesslayer.php b/businesslayer/feedbusinesslayer.php index 72f16d6b4..76763aae7 100644 --- a/businesslayer/feedbusinesslayer.php +++ b/businesslayer/feedbusinesslayer.php @@ -25,8 +25,7 @@ namespace OCA\News\BusinessLayer; -use \OCA\AppFramework\Core\API; - +use \OCA\News\Core\API; use \OCA\News\Db\DoesNotExistException; use \OCA\News\Db\Feed; use \OCA\News\Db\Item; diff --git a/businesslayer/folderbusinesslayer.php b/businesslayer/folderbusinesslayer.php index 64ddac4a3..c8611917a 100644 --- a/businesslayer/folderbusinesslayer.php +++ b/businesslayer/folderbusinesslayer.php @@ -25,8 +25,7 @@ namespace OCA\News\BusinessLayer; -use \OCA\AppFramework\Core\API; - +use \OCA\News\Core\API; use \OCA\News\Db\Folder; use \OCA\News\Db\FolderMapper; use \OCA\News\Utility\TimeFactory; diff --git a/controller/exportcontroller.php b/controller/exportcontroller.php index 357c54d54..e16a5b513 100644 --- a/controller/exportcontroller.php +++ b/controller/exportcontroller.php @@ -25,12 +25,14 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\TextDownloadResponse; -use \OCA\AppFramework\Http\JSONResponse; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http; +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; @@ -42,17 +44,19 @@ class ExportController extends Controller { private $folderBusinessLayer; private $feedBusinessLayer; private $itemBusinessLayer; + private $api; - public function __construct(API $api, Request $request, + public function __construct(API $api, IRequest $request, FeedBusinessLayer $feedBusinessLayer, FolderBusinessLayer $folderBusinessLayer, ItemBusinessLayer $itemBusinessLayer, OPMLExporter $opmlExporter){ - parent::__construct($api, $request); + parent::__construct($api->getAppName(), $request); $this->feedBusinessLayer = $feedBusinessLayer; $this->folderBusinessLayer = $folderBusinessLayer; $this->opmlExporter = $opmlExporter; $this->itemBusinessLayer = $itemBusinessLayer; + $this->api = $api; } diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index b0b856b79..29f60b8ea 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.php @@ -25,12 +25,12 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Core\API; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; @@ -44,15 +44,17 @@ class FeedController extends Controller { private $feedBusinessLayer; private $folderBusinessLayer; private $itemBusinessLayer; + private $api; - public function __construct(API $api, Request $request, + public function __construct(API $api, IRequest $request, FolderBusinessLayer $folderBusinessLayer, FeedBusinessLayer $feedBusinessLayer, ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api, $request); + parent::__construct($api->getAppName(), $request); $this->feedBusinessLayer = $feedBusinessLayer; $this->folderBusinessLayer = $folderBusinessLayer; $this->itemBusinessLayer = $itemBusinessLayer; + $this->api = $api; } diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php index 09d226920..4a133c6b2 100644 --- a/controller/foldercontroller.php +++ b/controller/foldercontroller.php @@ -25,12 +25,12 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +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,15 +43,17 @@ class FolderController extends Controller { private $folderBusinessLayer; private $feedBusinessLayer; private $itemBusinessLayer; + private $api; - public function __construct(API $api, Request $request, + public function __construct(API $api, IRequest $request, FolderBusinessLayer $folderBusinessLayer, FeedBusinessLayer $feedBusinessLayer, ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api, $request); + parent::__construct($api->getAppName(), $request); $this->folderBusinessLayer = $folderBusinessLayer; $this->feedBusinessLayer = $feedBusinessLayer; $this->itemBusinessLayer = $itemBusinessLayer; + $this->api = $api; } diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php index 637c5fd49..a813d92ca 100644 --- a/controller/itemcontroller.php +++ b/controller/itemcontroller.php @@ -25,12 +25,12 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Core\API; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; @@ -40,13 +40,15 @@ class ItemController extends Controller { private $itemBusinessLayer; private $feedBusinessLayer; + private $api; - public function __construct(API $api, Request $request, + public function __construct(API $api, IRequest $request, FeedBusinessLayer $feedBusinessLayer, ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api, $request); + parent::__construct($api->getAppName(), $request); $this->itemBusinessLayer = $itemBusinessLayer; $this->feedBusinessLayer = $feedBusinessLayer; + $this->api = $api; } diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php index 6f82e0640..f0d6b78e3 100644 --- a/controller/pagecontroller.php +++ b/controller/pagecontroller.php @@ -25,16 +25,16 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Http\Request; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; +use \OCA\News\Core\API; class PageController extends Controller { - public function __construct(API $api, Request $request){ - parent::__construct($api, $request); + public function __construct(API $api, IRequest $request){ + parent::__construct($api->getAppName(), $request); } diff --git a/controller/usersettingscontroller.php b/controller/usersettingscontroller.php index a34d5397e..11799aca1 100644 --- a/controller/usersettingscontroller.php +++ b/controller/usersettingscontroller.php @@ -25,16 +25,19 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Controller\Controller; -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http\JSONResponse; + +use \OCA\News\Core\API; class UserSettingsController extends Controller { + private $api; - public function __construct(API $api, Request $request){ - parent::__construct($api, $request); + public function __construct(API $api, IRequest $request){ + parent::__construct($api->getAppName(), $request); + $this->api = $api; } diff --git a/core/api.php b/core/api.php new file mode 100644 index 000000000..96b534a4c --- /dev/null +++ b/core/api.php @@ -0,0 +1,546 @@ +. + * + */ + + +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); + } +} diff --git a/db/feedmapper.php b/db/feedmapper.php index ef2a98f8c..4d88a4667 100644 --- a/db/feedmapper.php +++ b/db/feedmapper.php @@ -25,7 +25,7 @@ namespace OCA\News\Db; -use \OCA\AppFramework\Core\API; +use \OCA\News\Core\API; class FeedMapper extends Mapper implements IMapper { diff --git a/db/foldermapper.php b/db/foldermapper.php index f44ff3905..d273ce159 100644 --- a/db/foldermapper.php +++ b/db/foldermapper.php @@ -25,7 +25,7 @@ namespace OCA\News\Db; -use \OCA\AppFramework\Core\API; +use \OCA\News\Core\API; class FolderMapper extends Mapper implements IMapper { diff --git a/db/itemmapper.php b/db/itemmapper.php index 8da5d27e1..aea0180d7 100644 --- a/db/itemmapper.php +++ b/db/itemmapper.php @@ -24,7 +24,7 @@ namespace OCA\News\Db; -use \OCA\AppFramework\Core\API; +use \OCA\News\Core\API; class ItemMapper extends Mapper implements IMapper { diff --git a/db/mapper.php b/db/mapper.php index a0988bd54..42f1efa93 100644 --- a/db/mapper.php +++ b/db/mapper.php @@ -26,7 +26,7 @@ namespace OCA\News\Db; -use OCA\AppFramework\Core\API; +use \OCA\News\Core\API; /** diff --git a/db/mapperfactory.php b/db/mapperfactory.php index cf64f90d6..564819356 100644 --- a/db/mapperfactory.php +++ b/db/mapperfactory.php @@ -25,7 +25,7 @@ namespace OCA\News\Db; -use \OCA\AppFramework\Core\API; +use \OCA\News\Core\API; class MapperFactory { diff --git a/db/postgres/itemmapper.php b/db/postgres/itemmapper.php index be200ce93..e24ea373d 100644 --- a/db/postgres/itemmapper.php +++ b/db/postgres/itemmapper.php @@ -24,8 +24,7 @@ namespace OCA\News\Db\Postgres; -use \OCA\AppFramework\Core\API; - +use \OCA\News\Core\API; use \OCA\News\Db\DoesNotExistException; use \OCA\News\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Mapper; diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php index b34c17a3c..377b0f376 100644 --- a/dependencyinjection/dicontainer.php +++ b/dependencyinjection/dicontainer.php @@ -30,6 +30,8 @@ use \OC\Files\View; use \OCA\AppFramework\DependencyInjection\DIContainer as BaseContainer; use \OCA\AppFramework\Middleware\MiddlewareDispatcher; +use \OCA\News\Core\API; + use \OCA\News\Controller\PageController; use \OCA\News\Controller\FolderController; use \OCA\News\Controller\FeedController; @@ -83,6 +85,10 @@ class DIContainer extends BaseContainer { // tell parent container about the app name parent::__construct('news'); + $this['API'] = $this->share(function($c){ + return new API($c['news']); + }); + /** * Configuration values */ diff --git a/fetcher/feedfetcher.php b/fetcher/feedfetcher.php index 2ca4c999e..42caa75ec 100644 --- a/fetcher/feedfetcher.php +++ b/fetcher/feedfetcher.php @@ -25,8 +25,7 @@ namespace OCA\News\Fetcher; -use \OCA\AppFramework\Core\API; - +use \OCA\News\Core\API; use \OCA\News\Utility\FaviconFetcher; use \OCA\News\Utility\SimplePieAPIFactory; use \OCA\News\Utility\TimeFactory; diff --git a/http/downloadresponse.php b/http/downloadresponse.php new file mode 100644 index 000000000..56a46b15b --- /dev/null +++ b/http/downloadresponse.php @@ -0,0 +1,51 @@ +. + * + */ + + +namespace OCA\News\Http; + +use \OCP\AppFramework\Http\Response; + +/** + * Prompts the user to download the a file + */ +class DownloadResponse extends Response { + + private $filename; + private $contentType; + + /** + * Creates a response that prompts the user to download the file + * @param string $filename the name that the downloaded file should have + * @param string $contentType the mimetype that the downloaded file should have + */ + public function __construct($filename, $contentType) { + $this->filename = $filename; + $this->contentType = $contentType; + + $this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); + $this->addHeader('Content-Type', $contentType); + } + + +} diff --git a/http/textdownloadresponse.php b/http/textdownloadresponse.php new file mode 100644 index 000000000..07de87ba1 --- /dev/null +++ b/http/textdownloadresponse.php @@ -0,0 +1,59 @@ +. + * + */ + + +namespace OCA\News\Http; + + +/** + * Prompts the user to download the a textfile + */ +class TextDownloadResponse extends DownloadResponse { + + private $content; + private $filename; + private $contentType; + + /** + * Creates a response that prompts the user to download a file which + * contains the passed string + * @param string $content the content that should be written into the file + * @param string $filename the name that the downloaded file should have + * @param string $contentType the mimetype that the downloaded file should have + */ + public function __construct($content, $filename, $contentType){ + parent::__construct($filename, $contentType); + $this->content = $content; + } + + + /** + * Simply sets the headers and returns the file contents + * @return string the file contents + */ + public function render(){ + return $this->content; + } + + +} diff --git a/http/textresponse.php b/http/textresponse.php new file mode 100644 index 000000000..41d9c40e0 --- /dev/null +++ b/http/textresponse.php @@ -0,0 +1,57 @@ +. + * + */ + + +namespace OCA\News\Http; + +use \OCP\AppFramework\Http\Response; + +/** + * Just outputs text to the browser + */ +class TextResponse extends Response { + + private $content; + + /** + * Creates a response that just outputs text + * @param string $content the content that should be written into the file + * @param string $contentType the mimetype. text/ is added automatically so + * only plain or html can be added to get text/plain or text/html + */ + public function __construct($content, $contentType='plain'){ + $this->content = $content; + $this->addHeader('Content-type', 'text/' . $contentType); + } + + + /** + * Simply sets the headers and returns the file contents + * @return string the file contents + */ + public function render(){ + return $this->content; + } + + +} diff --git a/middleware/corsmiddleware.php b/middleware/corsmiddleware.php index 9b84e9dc4..2c6919b91 100644 --- a/middleware/corsmiddleware.php +++ b/middleware/corsmiddleware.php @@ -27,8 +27,8 @@ namespace OCA\News\Middleware; use OCA\AppFramework\Http\Request; use OCA\AppFramework\Http\Response; use OCA\AppFramework\Middleware\Middleware; -use OCA\AppFramework\Utility\MethodAnnotationReader; +use OCA\News\Utility\MethodAnnotationReader; class CORSMiddleware extends Middleware { diff --git a/tests/classloader.php b/tests/classloader.php index 7c0f82212..b59ecd85a 100644 --- a/tests/classloader.php +++ b/tests/classloader.php @@ -21,7 +21,7 @@ * */ -require_once __DIR__ . '/../../appframework/3rdparty/SimplePie/autoloader.php'; +require_once __DIR__ . '/../3rdparty/simplepie/autoloader.php'; // to execute without owncloud, we need to create our own classloader spl_autoload_register(function ($className){ @@ -30,6 +30,13 @@ spl_autoload_register(function ($className){ $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); $relPath = __DIR__ . '/../..' . $path; + if(file_exists($relPath)){ + require_once $relPath; + } + } else if(strpos($className, 'OCP\\') === 0) { + $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); + $relPath = __DIR__ . '/../../../lib/public' . $path; + if(file_exists($relPath)){ require_once $relPath; } diff --git a/tests/integration/db/ItemMapperIntegrationTest.php b/tests/integration/db/ItemMapperIntegrationTest.php index c883473bf..186dca14f 100644 --- a/tests/integration/db/ItemMapperIntegrationTest.php +++ b/tests/integration/db/ItemMapperIntegrationTest.php @@ -25,7 +25,7 @@ namespace OCA\News\Db; -use \OCA\AppFramework\Utility\MapperTestUtility; +use \OCA\News\Utility\MapperTestUtility; require_once(__DIR__ . "/../../classloader.php"); @@ -64,7 +64,7 @@ class ItemMapperIntegrationTest extends MapperTestUtility { return $db->prepare($sql); }; - $this->api = $this->getMock('OCA\AppFramework\Core\API', + $this->api = $this->getMock('OCA\News\Core\API', array('prepareQuery', 'getInsertId'), array('news')); $this->api->expects($this->any()) ->method('prepareQuery') diff --git a/tests/unit/api/FeedAPITest.php b/tests/unit/api/FeedAPITest.php index 6b2187657..03dd762cb 100644 --- a/tests/unit/api/FeedAPITest.php +++ b/tests/unit/api/FeedAPITest.php @@ -25,11 +25,11 @@ namespace OCA\News\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; -use \OCA\AppFramework\Utility\ControllerTestUtility; +use \OCP\IRequest; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\BusinessLayerConflictException; use \OCA\News\Db\Folder; @@ -52,11 +52,11 @@ class FeedAPITest extends ControllerTestUtility { protected function setUp() { $this->api = $this->getMockBuilder( - '\OCA\AppFramework\Core\API') + '\OCA\News\Core\API') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCA\AppFramework\Http\Request') + '\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); $this->folderBusinessLayer = $this->getMockBuilder( @@ -192,7 +192,7 @@ class FeedAPITest extends ControllerTestUtility { public function testDelete() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'feedId' => 2 ))); $this->feedAPI = new FeedAPI( @@ -220,7 +220,7 @@ class FeedAPITest extends ControllerTestUtility { public function testDeleteDoesNotExist() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'feedId' => 2 ))); $this->feedAPI = new FeedAPI( @@ -250,7 +250,7 @@ class FeedAPITest extends ControllerTestUtility { $feeds = array( new Feed() ); - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'url' => 'ho', 'folderId' => 3 ))); @@ -294,7 +294,7 @@ class FeedAPITest extends ControllerTestUtility { $feeds = array( new Feed() ); - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'url' => 'ho', 'folderId' => 3 ))); @@ -370,7 +370,7 @@ class FeedAPITest extends ControllerTestUtility { public function testRead() { - $request = new Request(array( + $request = $this->getRequest(array( 'urlParams' => array( 'feedId' => 3 ), @@ -404,7 +404,7 @@ class FeedAPITest extends ControllerTestUtility { public function testMove() { - $request = new Request(array( + $request = $this->getRequest(array( 'urlParams' => array( 'feedId' => 3 ), @@ -441,7 +441,7 @@ class FeedAPITest extends ControllerTestUtility { $feedId = 3; $feedTitle = 'test'; - $request = new Request(array( + $request = $this->getRequest(array( 'urlParams' => array( 'feedId' => $feedId ), @@ -508,7 +508,7 @@ class FeedAPITest extends ControllerTestUtility { public function testUpdate() { $feedId = 3; $userId = 'hi'; - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'feedId' => $feedId, 'userId' => $userId ))); diff --git a/tests/unit/api/FolderAPITest.php b/tests/unit/api/FolderAPITest.php index 8c33233b0..843ac004f 100644 --- a/tests/unit/api/FolderAPITest.php +++ b/tests/unit/api/FolderAPITest.php @@ -25,11 +25,11 @@ namespace OCA\News\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Utility\ControllerTestUtility; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\BusinessLayerConflictException; use \OCA\News\BusinessLayer\BusinessLayerValidationException; @@ -53,11 +53,11 @@ class FolderAPITest extends ControllerTestUtility { protected function setUp() { $this->api = $this->getMockBuilder( - '\OCA\AppFramework\Core\API') + '\OCA\News\Core\API') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCA\AppFramework\Http\Request') + '\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); $this->folderBusinessLayer = $this->getMockBuilder( @@ -141,7 +141,7 @@ class FolderAPITest extends ControllerTestUtility { ); $this->folderAPI = new FolderAPI( $this->api, - new Request(array('params' => array( + $this->getRequest(array('params' => array( 'name' => $folderName ))), $this->folderBusinessLayer, @@ -214,7 +214,7 @@ class FolderAPITest extends ControllerTestUtility { $this->folderAPI = new FolderAPI( $this->api, - new Request(array('urlParams' => array( + $this->getRequest(array('urlParams' => array( 'folderId' => $folderId ))), $this->folderBusinessLayer, @@ -239,7 +239,7 @@ class FolderAPITest extends ControllerTestUtility { $this->folderAPI = new FolderAPI( $this->api, - new Request(array('urlParams' => array( + $this->getRequest(array('urlParams' => array( 'folderId' => $folderId ))), $this->folderBusinessLayer, @@ -267,7 +267,7 @@ class FolderAPITest extends ControllerTestUtility { $this->folderAPI = new FolderAPI( $this->api, - new Request( + $this->getRequest( array( 'urlParams' => array( 'folderId' => $folderId @@ -303,7 +303,7 @@ class FolderAPITest extends ControllerTestUtility { $this->folderAPI = new FolderAPI( $this->api, - new Request( + $this->getRequest( array( 'urlParams' => array( 'folderId' => $folderId @@ -339,7 +339,7 @@ class FolderAPITest extends ControllerTestUtility { $this->folderAPI = new FolderAPI( $this->api, - new Request( + $this->getRequest( array( 'urlParams' => array( 'folderId' => $folderId @@ -375,7 +375,7 @@ class FolderAPITest extends ControllerTestUtility { $this->folderAPI = new FolderAPI( $this->api, - new Request( + $this->getRequest( array( 'urlParams' => array( 'folderId' => $folderId @@ -406,7 +406,7 @@ class FolderAPITest extends ControllerTestUtility { public function testRead() { - $request = new Request(array( + $request = $this->getRequest(array( 'urlParams' => array( 'folderId' => 3 ), diff --git a/tests/unit/api/ItemAPITest.php b/tests/unit/api/ItemAPITest.php index b172d5752..5bbf7edf1 100644 --- a/tests/unit/api/ItemAPITest.php +++ b/tests/unit/api/ItemAPITest.php @@ -25,11 +25,11 @@ namespace OCA\News\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; -use \OCA\AppFramework\Utility\ControllerTestUtility; +use \OCP\IRequest; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\Db\Item; @@ -47,11 +47,11 @@ class ItemAPITest extends ControllerTestUtility { protected function setUp() { $this->api = $this->getMockBuilder( - '\OCA\AppFramework\Core\API') + '\OCA\News\Core\API') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCA\AppFramework\Http\Request') + '\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); $this->itemBusinessLayer = $this->getMockBuilder( @@ -134,7 +134,7 @@ class ItemAPITest extends ControllerTestUtility { $items = array( new Item() ); - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'batchSize' => 30, 'offset' => 20, 'type' => 1, @@ -174,7 +174,7 @@ class ItemAPITest extends ControllerTestUtility { $items = array( new Item() ); - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'offset' => 20, 'type' => 1, 'id' => 2, @@ -213,7 +213,7 @@ class ItemAPITest extends ControllerTestUtility { $items = array( new Item() ); - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'lastModified' => 30, 'type' => 1, 'id' => 2, @@ -247,7 +247,7 @@ class ItemAPITest extends ControllerTestUtility { public function testRead() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'itemId' => 2 ))); $this->itemAPI = new ItemAPI( @@ -275,7 +275,7 @@ class ItemAPITest extends ControllerTestUtility { public function testReadDoesNotExist() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'itemId' => 2 ))); $this->itemAPI = new ItemAPI( @@ -300,7 +300,7 @@ class ItemAPITest extends ControllerTestUtility { public function testUnread() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'itemId' => 2 ))); $this->itemAPI = new ItemAPI( @@ -328,7 +328,7 @@ class ItemAPITest extends ControllerTestUtility { public function testUnreadDoesNotExist() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'itemId' => 2 ))); $this->itemAPI = new ItemAPI( @@ -353,7 +353,7 @@ class ItemAPITest extends ControllerTestUtility { public function testStar() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'feedId' => 2, 'guidHash' => 'hash' ))); @@ -383,7 +383,7 @@ class ItemAPITest extends ControllerTestUtility { public function testStarDoesNotExist() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'feedId' => 2, 'guidHash' => 'hash' ))); @@ -409,7 +409,7 @@ class ItemAPITest extends ControllerTestUtility { public function testUnstar() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'feedId' => 2, 'guidHash' => 'hash' ))); @@ -439,7 +439,7 @@ class ItemAPITest extends ControllerTestUtility { public function testUnstarDoesNotExist() { - $request = new Request(array('urlParams' => array( + $request = $this->getRequest(array('urlParams' => array( 'feedId' => 2, 'guidHash' => 'hash' ))); @@ -465,7 +465,7 @@ class ItemAPITest extends ControllerTestUtility { public function testReadAll() { - $request = new Request(array( + $request = $this->getRequest(array( 'params' => array( 'newestItemId' => 30, ) @@ -494,7 +494,7 @@ class ItemAPITest extends ControllerTestUtility { public function testReadMultiple() { - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'items' => array(2, 4) ))); $this->itemAPI = new ItemAPI( @@ -522,7 +522,7 @@ class ItemAPITest extends ControllerTestUtility { public function testReadMultipleDoesntCareAboutException() { - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'items' => array(2, 4) ))); $this->itemAPI = new ItemAPI( @@ -547,7 +547,7 @@ class ItemAPITest extends ControllerTestUtility { public function testUnreadMultiple() { - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'items' => array(2, 4) ))); $this->itemAPI = new ItemAPI( @@ -575,7 +575,7 @@ class ItemAPITest extends ControllerTestUtility { public function testStarMultiple() { - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'items' => array( array( 'feedId' => 2, @@ -614,7 +614,7 @@ class ItemAPITest extends ControllerTestUtility { public function testStarMultipleDoesntCareAboutException() { - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'items' => array( array( 'feedId' => 2, @@ -649,7 +649,7 @@ class ItemAPITest extends ControllerTestUtility { public function testUnstarMultiple() { - $request = new Request(array('params' => array( + $request = $this->getRequest(array('params' => array( 'items' => array( array( 'feedId' => 2, diff --git a/tests/unit/api/NewsAPITest.php b/tests/unit/api/NewsAPITest.php index 412f5e580..9fa467913 100644 --- a/tests/unit/api/NewsAPITest.php +++ b/tests/unit/api/NewsAPITest.php @@ -25,9 +25,11 @@ namespace OCA\News\API; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Utility\ControllerTestUtility; +use \OCP\IRequest; +use \OCP\AppFramework\Http\JSONResponse; + + +use \OCA\News\Utility\ControllerTestUtility; require_once(__DIR__ . "/../../classloader.php"); @@ -41,11 +43,11 @@ class NewsAPITest extends ControllerTestUtility { protected function setUp() { $this->api = $this->getMockBuilder( - '\OCA\AppFramework\Core\API') + '\OCA\News\Core\API') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCA\AppFramework\Http\Request') + '\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); $this->updater = $this->getMockBuilder( @@ -114,7 +116,7 @@ class NewsAPITest extends ControllerTestUtility { public function testCors() { - $this->request = new Request(array('server' => array())); + $this->request = $this->getRequest(array('server' => array())); $this->newsAPI = new NewsAPI($this->api, $this->request, $this->updater); $response = $this->newsAPI->cors(); @@ -129,7 +131,7 @@ class NewsAPITest extends ControllerTestUtility { public function testCorsUsesOriginIfGiven() { - $this->request = new Request(array('server' => array('HTTP_ORIGIN' => 'test'))); + $this->request = $this->getRequest(array('server' => array('HTTP_ORIGIN' => 'test'))); $this->newsAPI = new NewsAPI($this->api, $this->request, $this->updater); $response = $this->newsAPI->cors(); diff --git a/tests/unit/articleenhancer/EnhancerTest.php b/tests/unit/articleenhancer/EnhancerTest.php index 84cbe2a7c..7f782cf55 100644 --- a/tests/unit/articleenhancer/EnhancerTest.php +++ b/tests/unit/articleenhancer/EnhancerTest.php @@ -30,7 +30,7 @@ use \OCA\News\Db\Item; require_once(__DIR__ . "/../../classloader.php"); -class EnhancerTest extends \OCA\AppFramework\Utility\TestUtility { +class EnhancerTest extends \OCA\News\Utility\TestUtility { private $enhancer; private $articleEnhancer; diff --git a/tests/unit/articleenhancer/RegexArticleEnhancerTest.php b/tests/unit/articleenhancer/RegexArticleEnhancerTest.php index 2d985edf1..a43f92b1c 100644 --- a/tests/unit/articleenhancer/RegexArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/RegexArticleEnhancerTest.php @@ -30,7 +30,7 @@ use \OCA\News\Db\Item; require_once(__DIR__ . "/../../classloader.php"); -class RegexArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { +class RegexArticleEnhancerTest extends \OCA\News\Utility\TestUtility { public function testRegexEnhancer() { diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php index c7e61e7b8..e594e105f 100644 --- a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php @@ -30,7 +30,7 @@ use \OCA\News\Db\Item; require_once(__DIR__ . "/../../classloader.php"); -class XPathArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { +class XPathArticleEnhancerTest extends \OCA\News\Utility\TestUtility { private $testEnhancer; private $fileFactory; diff --git a/tests/unit/businesslayer/BusinessLayerTest.php b/tests/unit/businesslayer/BusinessLayerTest.php index 2208e34f8..7f3677d18 100644 --- a/tests/unit/businesslayer/BusinessLayerTest.php +++ b/tests/unit/businesslayer/BusinessLayerTest.php @@ -39,7 +39,7 @@ class TestBusinessLayer extends BusinessLayer { } } -class BusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { +class BusinessLayerTest extends \OCA\News\Utility\TestUtility { protected $api; protected $mapper; diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 99ecee9f2..4e35326d6 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -34,7 +34,7 @@ use \OCA\News\Db\Item; use \OCA\News\Fetcher\Fetcher; use \OCA\News\Fetcher\FetcherException; -class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { +class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility { private $feedMapper; private $feedBusinessLayer; diff --git a/tests/unit/businesslayer/FolderBusinessLayerTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php index 398365739..c68d0e768 100644 --- a/tests/unit/businesslayer/FolderBusinessLayerTest.php +++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php @@ -31,7 +31,7 @@ require_once(__DIR__ . "/../../classloader.php"); use \OCA\News\Db\Folder; -class FolderBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { +class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility { private $folderMapper; private $folderBusinessLayer; diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php index 2909dae28..349ad865c 100644 --- a/tests/unit/businesslayer/ItemBusinessLayerTest.php +++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php @@ -33,7 +33,7 @@ use \OCA\News\Db\StatusFlag; use \OCA\News\Db\FeedType; -class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { +class ItemBusinessLayerTest extends \OCA\News\Utility\TestUtility { private $api; private $mapper; diff --git a/tests/unit/businesslayer/StatusFlagTest.php b/tests/unit/businesslayer/StatusFlagTest.php index 2e7b9d4d8..d503b6630 100644 --- a/tests/unit/businesslayer/StatusFlagTest.php +++ b/tests/unit/businesslayer/StatusFlagTest.php @@ -25,13 +25,11 @@ namespace OCA\News\Db; -use \OCA\AppFramework\Utility\TestUtility; - require_once(__DIR__ . "/../../classloader.php"); -class StatusFlagTest extends TestUtility { +class StatusFlagTest extends \OCA\News\Utility\TestUtility { private $statusFlag; diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index 542053edf..0970993ca 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -25,11 +25,12 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\TextDownloadResponse; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Utility\ControllerTestUtility; +use \OCP\IRequest; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Http\TextDownloadResponse; +use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\Utility\OPMLExporter; use \OCA\News\Db\Item; use \OCA\News\Db\Feed; @@ -62,7 +63,7 @@ class ExportControllerTest extends ControllerTestUtility { $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->request = new Request(); + $this->request = $this->getRequest(); $this->opmlExporter = new OPMLExporter(); $this->controller = new ExportController($this->api, $this->request, $this->feedBusinessLayer, $this->folderBusinessLayer, diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index aa6756e99..899cebfc0 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -25,13 +25,11 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; -use \OCA\AppFramework\Utility\ControllerTestUtility; -use \OCA\AppFramework\Db\DoesNotExistException; -use \OCA\AppFramework\Db\MultipleObjectsReturnedException; +use \OCP\IRequest; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedType; use \OCA\News\BusinessLayer\BusinessLayerException; @@ -64,7 +62,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->request = new Request(); + $this->request = $this->getRequest(); $this->controller = new FeedController($this->api, $this->request, $this->folderBusinessLayer, $this->feedBusinessLayer, diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index bcfa61c67..12a9078ea 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -25,13 +25,11 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Utility\ControllerTestUtility; -use \OCA\AppFramework\Db\DoesNotExistException; -use \OCA\AppFramework\Db\MultipleObjectsReturnedException; -use \OCA\AppFramework\Http\Http; +use \OCP\IRequest; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\Db\Folder; use \OCA\News\Db\Feed; use \OCA\News\BusinessLayer\BusinessLayerException; @@ -66,7 +64,7 @@ class FolderControllerTest extends ControllerTestUtility { $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->request = new Request(); + $this->request = $this->getRequest(); $this->controller = new FolderController($this->api, $this->request, $this->folderBusinessLayer, $this->feedBusinessLayer, diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index a7db42d5c..14c1a3fa4 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -25,11 +25,11 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Http\Http; -use \OCA\AppFramework\Utility\ControllerTestUtility; +use \OCP\IRequest; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\Db\Item; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedType; @@ -61,7 +61,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->request = new Request(); + $this->request = $this->getRequest(); $this->controller = new ItemController($this->api, $this->request, $this->feedBusinessLayer, $this->itemBusinessLayer); $this->user = 'jackob'; diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index ddb9f9c88..d2cd4b8af 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -25,10 +25,10 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\TemplateResponse; -use \OCA\AppFramework\Utility\ControllerTestUtility; +use \OCP\IRequest; +use \OCP\AppFramework\Http\TemplateResponse; +use \OCA\News\Utility\ControllerTestUtility; require_once(__DIR__ . "/../../classloader.php"); @@ -45,7 +45,7 @@ class PageControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->request = new Request(); + $this->request = $this->getRequest(); $this->controller = new PageController($this->api, $this->request); } diff --git a/tests/unit/controller/UserSettingsControllerTest.php b/tests/unit/controller/UserSettingsControllerTest.php index d6c76ddb9..9a8dcf5fd 100644 --- a/tests/unit/controller/UserSettingsControllerTest.php +++ b/tests/unit/controller/UserSettingsControllerTest.php @@ -25,10 +25,10 @@ namespace OCA\News\Controller; -use \OCA\AppFramework\Http\Request; -use \OCA\AppFramework\Http\JSONResponse; -use \OCA\AppFramework\Utility\ControllerTestUtility; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; +use \OCA\News\Utility\ControllerTestUtility; require_once(__DIR__ . "/../../classloader.php"); @@ -45,7 +45,7 @@ class UserSettingsControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->request = new Request(); + $this->request = $this->getRequest(); $this->controller = new UserSettingsController($this->api, $this->request); $this->user = 'becka'; } @@ -154,7 +154,7 @@ class UserSettingsControllerTest extends ControllerTestUtility { public function testUnsetCompactView(){ - $request = new Request(array('post' => array( + $request = $this->getRequest(array('post' => array( 'compact' => false ))); $this->controller = new UserSettingsController($this->api, $request); @@ -168,7 +168,7 @@ class UserSettingsControllerTest extends ControllerTestUtility { } public function testSetCompactView(){ - $request = new Request(array('post' => array( + $request = $this->getRequest(array('post' => array( 'compact' => true ))); $this->controller = new UserSettingsController($this->api, $request); diff --git a/tests/unit/db/FeedMapperTest.php b/tests/unit/db/FeedMapperTest.php index d38d4c230..c424e57e7 100644 --- a/tests/unit/db/FeedMapperTest.php +++ b/tests/unit/db/FeedMapperTest.php @@ -28,7 +28,7 @@ namespace OCA\News\Db; require_once(__DIR__ . "/../../classloader.php"); -class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { +class FeedMapperTest extends \OCA\News\Utility\MapperTestUtility { private $mapper; private $feeds; diff --git a/tests/unit/db/FolderMapperTest.php b/tests/unit/db/FolderMapperTest.php index e4d1e5542..b27cf80ab 100644 --- a/tests/unit/db/FolderMapperTest.php +++ b/tests/unit/db/FolderMapperTest.php @@ -28,7 +28,7 @@ namespace OCA\News\Db; require_once(__DIR__ . "/../../classloader.php"); -class FolderMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { +class FolderMapperTest extends \OCA\News\Utility\MapperTestUtility { private $folderMapper; private $folders; diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php index cfef4c929..fbb77ea12 100644 --- a/tests/unit/db/ItemMapperTest.php +++ b/tests/unit/db/ItemMapperTest.php @@ -28,7 +28,7 @@ namespace OCA\News\Db; require_once(__DIR__ . "/../../classloader.php"); -class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { +class ItemMapperTest extends \OCA\News\Utility\MapperTestUtility { private $mapper; private $items; diff --git a/tests/unit/db/MapperFactoryTest.php b/tests/unit/db/MapperFactoryTest.php index c553b2aff..51e70f526 100644 --- a/tests/unit/db/MapperFactoryTest.php +++ b/tests/unit/db/MapperFactoryTest.php @@ -33,7 +33,7 @@ class MapperFactoryTest extends \PHPUnit_Framework_TestCase { public function setUp() { - $this->api = $this->getMockBuilder('\OCA\AppFramework\Core\API') + $this->api = $this->getMockBuilder('\OCA\News\Core\API') ->disableOriginalConstructor() ->getMock(); } diff --git a/tests/unit/db/MapperTest.php b/tests/unit/db/MapperTest.php index b41348194..3e483d764 100644 --- a/tests/unit/db/MapperTest.php +++ b/tests/unit/db/MapperTest.php @@ -24,8 +24,8 @@ namespace OCA\News\Db; -use OCA\AppFramework\Core\API; -use OCA\AppFramework\Utility\MapperTestUtility; +use OCA\News\Core\API; +use OCA\News\Utility\MapperTestUtility; require_once(__DIR__ . "/../../classloader.php"); diff --git a/tests/unit/db/postgres/ItemMapperTest.php b/tests/unit/db/postgres/ItemMapperTest.php index 1e3207387..ff8651233 100644 --- a/tests/unit/db/postgres/ItemMapperTest.php +++ b/tests/unit/db/postgres/ItemMapperTest.php @@ -32,7 +32,7 @@ use \OCA\News\Db\StatusFlag; require_once(__DIR__ . "/../../../classloader.php"); -class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { +class ItemMapperTest extends \OCA\News\Utility\MapperTestUtility { private $mapper; private $items; diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php index b26c42a8d..806c2012a 100644 --- a/tests/unit/fetcher/FeedFetcherTest.php +++ b/tests/unit/fetcher/FeedFetcherTest.php @@ -31,7 +31,7 @@ use \OCA\News\Db\Feed; require_once(__DIR__ . "/../../classloader.php"); -class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility { +class FeedFetcherTest extends \OCA\News\Utility\TestUtility { private $fetcher; private $core; diff --git a/tests/unit/fetcher/FetcherTest.php b/tests/unit/fetcher/FetcherTest.php index 41f33129c..f5756aaf7 100644 --- a/tests/unit/fetcher/FetcherTest.php +++ b/tests/unit/fetcher/FetcherTest.php @@ -28,7 +28,7 @@ namespace OCA\News\Fetcher; require_once(__DIR__ . "/../../classloader.php"); -class FetcherTest extends \OCA\AppFramework\Utility\TestUtility { +class FetcherTest extends \OCA\News\Utility\TestUtility { private $fetcher; diff --git a/tests/unit/http/DownloadResponseTest.php b/tests/unit/http/DownloadResponseTest.php new file mode 100644 index 000000000..f72505bd3 --- /dev/null +++ b/tests/unit/http/DownloadResponseTest.php @@ -0,0 +1,51 @@ +. + * + */ + + +namespace OCA\News\Http; + + +require_once(__DIR__ . "/../../classloader.php"); + + +class ChildDownloadResponse extends DownloadResponse {}; + + +class DownloadResponseTest extends \PHPUnit_Framework_TestCase { + + protected $response; + + protected function setUp(){ + $this->response = new ChildDownloadResponse('file', 'content'); + } + + + public function testHeaders() { + $headers = $this->response->getHeaders(); + + $this->assertContains('attachment; filename="file"', $headers['Content-Disposition']); + $this->assertContains('content', $headers['Content-Type']); + } + + +} \ No newline at end of file diff --git a/tests/unit/http/TextDownloadResponseTest.php b/tests/unit/http/TextDownloadResponseTest.php new file mode 100644 index 000000000..3363c1df5 --- /dev/null +++ b/tests/unit/http/TextDownloadResponseTest.php @@ -0,0 +1,44 @@ +. + * + */ + + +namespace OCA\News\Http; + + +require_once(__DIR__ . "/../../classloader.php"); +require_once(__DIR__ . "/DownloadResponseTest.php"); + + +class TextDownloadResponseTest extends DownloadResponseTest { + + + protected function setUp() { + $this->response = new TextDownloadResponse('sometext', 'file', 'content'); + } + + + public function testRender() { + $this->assertEquals('sometext', $this->response->render()); + } + +} \ No newline at end of file diff --git a/tests/unit/http/TextResponseTest.php b/tests/unit/http/TextResponseTest.php new file mode 100644 index 000000000..ccffb9a1b --- /dev/null +++ b/tests/unit/http/TextResponseTest.php @@ -0,0 +1,57 @@ +. + * + */ + + +namespace OCA\News\Http; + + +require_once(__DIR__ . "/../../classloader.php"); + + +class TextResponseTest extends \PHPUnit_Framework_TestCase { + + + protected function setUp() { + $this->response = new TextResponse('sometext'); + } + + + public function testRender() { + $this->assertEquals('sometext', $this->response->render()); + } + + public function testContentTypeDefaultsToText(){ + $headers = $this->response->getHeaders(); + + $this->assertEquals('text/plain', $headers['Content-type']); + } + + + public function testContentTypeIsSetableViaConstructor(){ + $response = new TextResponse('sometext', 'html'); + $headers = $response->getHeaders(); + + $this->assertEquals('text/html', $headers['Content-type']); + } + +} \ No newline at end of file diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php index 479acabb5..8ef688844 100644 --- a/tests/unit/utility/ConfigTest.php +++ b/tests/unit/utility/ConfigTest.php @@ -28,7 +28,7 @@ namespace OCA\News\Utility; require_once(__DIR__ . "/../../classloader.php"); -class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility { +class ConfigFetcherTest extends \OCA\News\Utility\TestUtility { private $fileSystem; private $config; @@ -36,7 +36,7 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility { public function setUp() { $this->api = $this->getMockBuilder( - '\OCA\AppFramework\Core\API') + '\OCA\News\Core\API') ->disableOriginalConstructor() ->getMock(); $this->fileSystem = $this->getMock('FileSystem', array( diff --git a/tests/unit/utility/OPMLExporterTest.php b/tests/unit/utility/OPMLExporterTest.php index fbf1bcd1d..cf20f6347 100644 --- a/tests/unit/utility/OPMLExporterTest.php +++ b/tests/unit/utility/OPMLExporterTest.php @@ -31,7 +31,7 @@ use \OCA\News\Db\Feed; require_once(__DIR__ . "/../../classloader.php"); -class OPMLExporterTest extends \OCA\AppFramework\Utility\TestUtility { +class OPMLExporterTest extends \OCA\News\Utility\TestUtility { private $exporter; private $feed1; diff --git a/utility/config.php b/utility/config.php index 54145c993..193411592 100644 --- a/utility/config.php +++ b/utility/config.php @@ -25,7 +25,7 @@ namespace OCA\News\Utility; -use \OCA\AppFramework\Core\API; +use \OCA\News\Core\API; class Config { diff --git a/utility/controllertestutility.php b/utility/controllertestutility.php new file mode 100644 index 000000000..07de3e4e9 --- /dev/null +++ b/utility/controllertestutility.php @@ -0,0 +1,115 @@ +. + * + */ + + +namespace OCA\News\Utility; + +use OCP\IRequest; +use OCP\AppFramework\Http\Response; + + +/** + * Simple utility class for testing controllers + */ +abstract class ControllerTestUtility extends TestUtility { + + + /** + * Checks if a controllermethod has the expected annotations + * @param Controller/string $controller name or instance of the controller + * @param array $expected an array containing the expected annotations + * @param array $valid if you define your own annotations, pass them here + */ + protected function assertAnnotations($controller, $method, array $expected, + array $valid=array()){ + $standard = array( + 'Ajax', + 'CSRFExemption', + 'IsAdminExemption', + 'IsSubAdminExemption', + 'IsLoggedInExemption', + 'API' + ); + + $possible = array_merge($standard, $valid); + + // check if expected annotations are valid + foreach($expected as $annotation){ + $this->assertTrue(in_array($annotation, $possible)); + } + + $reader = new MethodAnnotationReader($controller, $method); + foreach($expected as $annotation){ + $this->assertTrue($reader->hasAnnotation($annotation)); + } + } + + + /** + * Shortcut for testing expected headers of a response + * @param array $expected an array with the expected headers + * @param Response $response the response which we want to test for headers + */ + protected function assertHeaders(array $expected=array(), Response $response){ + $headers = $reponse->getHeaders(); + foreach($expected as $header){ + $this->assertTrue(in_array($header, $headers)); + } + } + + + /** + * Instead of using positional parameters this function instantiates + * a request by using a hashmap so its easier to only set specific params + * @param array $params a hashmap with the parameters for request + * @return Request a request instance + */ + protected function getRequest(array $params=array()) { + $mock = $this->getMockBuilder('\OCP\IRequest') + ->getMock(); + + $merged = array(); + + foreach ($params as $key => $value) { + $merged = array_merge($value, $merged); + } + + $mock->expects($this->any()) + ->method('getParam') + ->will($this->returnCallback(function($index, $default) use ($merged) { + if (array_key_exists($index, $merged)) { + return $merged[$index]; + } else { + return $default; + } + })); + + // attribute access + if(array_key_exists('server', $params)) { + $mock->server = $params['server']; + } + + return $mock; + } + +} diff --git a/utility/mappertestutility.php b/utility/mappertestutility.php new file mode 100644 index 000000000..d78e717aa --- /dev/null +++ b/utility/mappertestutility.php @@ -0,0 +1,180 @@ +. + * + */ + + +namespace OCA\News\Utility; + +use OCA\News\Core\Api; + + +/** + * Simple utility class for testing mappers + */ +abstract class MapperTestUtility extends TestUtility { + + + protected $api; + private $query; + private $pdoResult; + private $queryAt; + private $prepareAt; + private $fetchAt; + private $iterators; + + + /** + * 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 + */ + protected function beforeEach(){ + $this->api = $this->getMock('\OCA\News\Core\API', + array('prepareQuery', 'getInsertId'), + array('a')); + + $this->query = $this->getMock('Query', array('execute', 'bindValue')); + $this->pdoResult = $this->getMock('Result', array('fetchRow')); + $this->queryAt = 0; + $this->prepareAt = 0; + $this->iterators = array(); + $this->fetchAt = 0; + } + + + /** + * Create mocks and set expected results for database queries + * @param string $sql the sql query that you expect to receive + * @param array $arguments the expected arguments for the prepare query + * method + * @param array $returnRows the rows that should be returned for the result + * of the database query. If not provided, it wont be assumed that fetchRow + * will be called on the result + */ + protected function setMapperResult($sql, $arguments=array(), $returnRows=array(), + $limit=null, $offset=null){ + + $this->iterators[] = new ArgumentIterator($returnRows); + + $iterators = $this->iterators; + $fetchAt = $this->fetchAt; + + $this->pdoResult->expects($this->any()) + ->method('fetchRow') + ->will($this->returnCallback( + function() use ($iterators, $fetchAt){ + $iterator = $iterators[$fetchAt]; + $result = $iterator->next(); + + if($result === false) { + $fetchAt++; + } + + return $result; + } + )); + + $index = 1; + foreach($arguments as $argument) { + switch (gettype($argument)) { + case 'integer': + $pdoConstant = \PDO::PARAM_INT; + break; + + case 'NULL': + $pdoConstant = \PDO::PARAM_NULL; + break; + + case 'boolean': + $pdoConstant = \PDO::PARAM_BOOL; + break; + + default: + $pdoConstant = \PDO::PARAM_STR; + break; + } + $this->query->expects($this->at($this->queryAt)) + ->method('bindValue') + ->with($this->equalTo($index), + $this->equalTo($argument), + $this->equalTo($pdoConstant)); + $index++; + $this->queryAt++; + } + + $this->query->expects($this->at($this->queryAt)) + ->method('execute') + ->with() + ->will($this->returnValue($this->pdoResult)); + $this->queryAt++; + + if($limit === null && $offset === null) { + $this->api->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)) + ->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)) + ->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)) + ->method('prepareQuery') + ->with($this->equalTo($sql), + $this->equalTo($limit), + $this->equalTo($offset)) + ->will(($this->returnValue($this->query))); + } + $this->prepareAt++; + $this->fetchAt++; + + } + + +} + + +class ArgumentIterator { + + private $arguments; + + public function __construct($arguments){ + $this->arguments = $arguments; + } + + public function next(){ + $result = array_shift($this->arguments); + if($result === null){ + return false; + } else { + return $result; + } + } +} + diff --git a/utility/methodannotationreader.php b/utility/methodannotationreader.php new file mode 100644 index 000000000..dc2347b3d --- /dev/null +++ b/utility/methodannotationreader.php @@ -0,0 +1,61 @@ +. + * + */ + + +namespace OCA\News\Utility; + + +/** + * Reads and parses annotations from doc comments + */ +class MethodAnnotationReader { + + private $annotations; + + /** + * @param object $object an object or classname + * @param string $method the method which we want to inspect for annotations + */ + public function __construct($object, $method){ + $this->annotations = array(); + + $reflection = new \ReflectionMethod($object, $method); + $docs = $reflection->getDocComment(); + + // extract everythin prefixed by @ and first letter uppercase + preg_match_all('/@([A-Z]\w+)/', $docs, $matches); + $this->annotations = $matches[1]; + } + + + /** + * Check if a method contains an annotation + * @param string $name the name of the annotation + * @return bool true if the annotation is found + */ + public function hasAnnotation($name){ + return in_array($name, $this->annotations); + } + + +} \ No newline at end of file diff --git a/utility/simplepieapifactory.php b/utility/simplepieapifactory.php index 70e833a4e..5014838d1 100644 --- a/utility/simplepieapifactory.php +++ b/utility/simplepieapifactory.php @@ -1,7 +1,7 @@ . + * + */ + + +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); + } + + +} \ No newline at end of file -- cgit v1.2.3