From 517e4ca5435106ab5304849248cbea4e9dffd4b0 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 19 Apr 2014 13:20:54 +0200 Subject: split up api class for easier testing and clearer code --- tests/integration/db/ItemMapperIntegrationTest.php | 81 ----------- tests/unit/articleenhancer/EnhancerTest.php | 2 +- .../articleenhancer/RegexArticleEnhancerTest.php | 2 +- .../articleenhancer/XPathArticleEnhancerTest.php | 2 +- tests/unit/businesslayer/BusinessLayerTest.php | 4 +- tests/unit/businesslayer/FeedBusinessLayerTest.php | 26 ++-- .../unit/businesslayer/FolderBusinessLayerTest.php | 19 +-- tests/unit/businesslayer/ItemBusinessLayerTest.php | 4 +- tests/unit/businesslayer/StatusFlagTest.php | 2 +- tests/unit/controller/ApiControllerTest.php | 19 ++- tests/unit/controller/ExportControllerTest.php | 16 +-- tests/unit/controller/FeedApiControllerTest.php | 102 ++++++-------- tests/unit/controller/FeedControllerTest.php | 87 +++--------- tests/unit/controller/FolderApiControllerTest.php | 87 ++++-------- tests/unit/controller/FolderControllerTest.php | 55 ++------ tests/unit/controller/ItemApiControllerTest.php | 156 ++++++++------------- tests/unit/controller/ItemControllerTest.php | 67 +++------ tests/unit/controller/PageControllerTest.php | 36 +++-- tests/unit/db/FeedMapperTest.php | 2 +- tests/unit/db/FolderMapperTest.php | 2 +- tests/unit/db/ItemMapperTest.php | 2 +- tests/unit/db/MapperFactoryTest.php | 19 ++- tests/unit/db/MapperTest.php | 18 ++- tests/unit/db/postgres/ItemMapperTest.php | 2 +- tests/unit/fetcher/FeedFetcherTest.php | 5 +- tests/unit/fetcher/FetcherTest.php | 2 +- tests/unit/utility/ConfigTest.php | 12 +- tests/unit/utility/OPMLExporterTest.php | 2 +- 28 files changed, 277 insertions(+), 556 deletions(-) delete mode 100644 tests/integration/db/ItemMapperIntegrationTest.php (limited to 'tests') diff --git a/tests/integration/db/ItemMapperIntegrationTest.php b/tests/integration/db/ItemMapperIntegrationTest.php deleted file mode 100644 index 186dca14f..000000000 --- a/tests/integration/db/ItemMapperIntegrationTest.php +++ /dev/null @@ -1,81 +0,0 @@ -. -* -*/ - -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'); - } - - -} \ No newline at end of file diff --git a/tests/unit/articleenhancer/EnhancerTest.php b/tests/unit/articleenhancer/EnhancerTest.php index 7f782cf55..663714590 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\News\Utility\TestUtility { +class EnhancerTest extends \PHPUnit_Framework_TestCase { private $enhancer; private $articleEnhancer; diff --git a/tests/unit/articleenhancer/RegexArticleEnhancerTest.php b/tests/unit/articleenhancer/RegexArticleEnhancerTest.php index a43f92b1c..38c570cfb 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\News\Utility\TestUtility { +class RegexArticleEnhancerTest extends \PHPUnit_Framework_TestCase { public function testRegexEnhancer() { diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php index dbd752518..dd84c31fd 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\News\Utility\TestUtility { +class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase { private $testEnhancer; private $fileFactory; diff --git a/tests/unit/businesslayer/BusinessLayerTest.php b/tests/unit/businesslayer/BusinessLayerTest.php index 7f3677d18..54ca11cba 100644 --- a/tests/unit/businesslayer/BusinessLayerTest.php +++ b/tests/unit/businesslayer/BusinessLayerTest.php @@ -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(); diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 19ff7da7f..f856f2ca6 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\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)) diff --git a/tests/unit/businesslayer/FolderBusinessLayerTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php index 17eb1b8ae..22b9e53d0 100644 --- a/tests/unit/businesslayer/FolderBusinessLayerTest.php +++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php @@ -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)) diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php index a3e7f7a14..f0f9d1906 100644 --- a/tests/unit/businesslayer/ItemBusinessLayerTest.php +++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php @@ -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(); diff --git a/tests/unit/businesslayer/StatusFlagTest.php b/tests/unit/businesslayer/StatusFlagTest.php index d503b6630..d96f40a6b 100644 --- a/tests/unit/businesslayer/StatusFlagTest.php +++ b/tests/unit/businesslayer/StatusFlagTest.php @@ -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; diff --git a/tests/unit/controller/ApiControllerTest.php b/tests/unit/controller/ApiControllerTest.php index 722830a23..6aa6ee4ea 100644 --- a/tests/unit/controller/ApiControllerTest.php +++ b/tests/unit/controller/ApiControllerTest.php @@ -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(); diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index b79574ff2..bc3baf4cf 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -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 { " \n" . "\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)) diff --git a/tests/unit/controller/FeedApiControllerTest.php b/tests/unit/controller/FeedApiControllerTest.php index 8bb8447bd..752eb575b 100644 --- a/tests/unit/controller/FeedApiControllerTest.php +++ b/tests/unit/controller/FeedApiControllerTest.php @@ -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')); diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index 90c1b8e14..2135c5366 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -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))); diff --git a/tests/unit/controller/FolderApiControllerTest.php b/tests/unit/controller/FolderApiControllerTest.php index cc799dc18..702699b98 100644 --- a/tests/unit/controller/FolderApiControllerTest.php +++ b/tests/unit/controller/FolderApiControllerTest.php @@ -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( diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index dba656e7b..142f8e2c4 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -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))); diff --git a/tests/unit/controller/ItemApiControllerTest.php b/tests/unit/controller/ItemApiControllerTest.php index 6a8c2a5cd..ead262cd4 100644 --- a/tests/unit/controller/ItemApiControllerTest.php +++ b/tests/unit/controller/ItemApiControllerTest.php @@ -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), diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index 9fa2e1a63..c3296b2f6 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -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->getPostContr