diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-15 16:02:32 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-15 16:02:32 +0200 |
commit | 464ff6c4c1bda3edbd0f132c4d3d866539d3a117 (patch) | |
tree | 96b8fd57e24ebaab762a190a933cd98e1c7a4881 /tests | |
parent | 89c31ab5fcb2f931fecc5ce82608ff7c8129510a (diff) |
renamed bl to businesslayer, handle exception in update routine, fix #69
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/businesslayer/BusinessLayerTest.php (renamed from tests/unit/bl/BlTest.php) | 22 | ||||
-rw-r--r-- | tests/unit/businesslayer/FeedBusinessLayerTest.php (renamed from tests/unit/bl/FeedBlTest.php) | 94 | ||||
-rw-r--r-- | tests/unit/businesslayer/FolderBusinessLayerTest.php (renamed from tests/unit/bl/FolderBlTest.php) | 24 | ||||
-rw-r--r-- | tests/unit/businesslayer/ItemBusinessLayerTest.php (renamed from tests/unit/bl/ItemBlTest.php) | 30 | ||||
-rw-r--r-- | tests/unit/businesslayer/StatusFlagTest.php (renamed from tests/unit/bl/StatusFlagTest.php) | 0 | ||||
-rw-r--r-- | tests/unit/controller/ExportControllerTest.php | 14 | ||||
-rw-r--r-- | tests/unit/controller/FeedControllerTest.php | 64 | ||||
-rw-r--r-- | tests/unit/controller/FolderControllerTest.php | 30 | ||||
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 24 |
9 files changed, 197 insertions, 105 deletions
diff --git a/tests/unit/bl/BlTest.php b/tests/unit/businesslayer/BusinessLayerTest.php index 05d78794a..7c064b377 100644 --- a/tests/unit/bl/BlTest.php +++ b/tests/unit/businesslayer/BusinessLayerTest.php @@ -23,7 +23,7 @@ * */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; require_once(__DIR__ . "/../../classloader.php"); @@ -33,24 +33,24 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; -class TestBl extends BL { +class TestBusinessLayer extends BusinessLayer { public function __construct($mapper){ parent::__construct($mapper); } } -class BlTest extends \OCA\AppFramework\Utility\TestUtility { +class BusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { protected $api; protected $mapper; - protected $newsBl; + protected $newsBusinessLayer; protected function setUp(){ $this->api = $this->getAPIMock(); $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); - $this->newsBl = new TestBl($this->mapper); + $this->newsBusinessLayer = new TestBusinessLayer($this->mapper); } @@ -68,7 +68,7 @@ class BlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($this->equalTo($id), $this->equalTo($user)) ->will($this->returnValue($folder)); - $result = $this->newsBl->delete($id, $user); + $result = $this->newsBusinessLayer->delete($id, $user); } @@ -80,7 +80,7 @@ class BlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('find') ->with($this->equalTo($id), $this->equalTo($user)); - $result = $this->newsBl->find($id, $user); + $result = $this->newsBusinessLayer->find($id, $user); } @@ -91,8 +91,8 @@ class BlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('find') ->will($this->throwException($ex)); - $this->setExpectedException('\OCA\News\Bl\BLException'); - $this->newsBl->find(1, ''); + $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException'); + $this->newsBusinessLayer->find(1, ''); } @@ -103,8 +103,8 @@ class BlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('find') ->will($this->throwException($ex)); - $this->setExpectedException('\OCA\News\Bl\BLException'); - $this->newsBl->find(1, ''); + $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException'); + $this->newsBusinessLayer->find(1, ''); } } diff --git a/tests/unit/bl/FeedBlTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index a5ce1c624..3f1ed9a56 100644 --- a/tests/unit/bl/FeedBlTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -24,7 +24,7 @@ */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; require_once(__DIR__ . "/../../classloader.php"); @@ -35,10 +35,10 @@ use \OCA\News\Db\Item; use \OCA\News\Utility\Fetcher; use \OCA\News\Utility\FetcherException; -class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { +class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { private $mapper; - private $bl; + private $businessLayer; private $user; private $response; private $fetcher; @@ -56,7 +56,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->itemMapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); - $this->bl = new FeedBl($this->mapper, + $this->businessLayer = new FeedBusinessLayer($this->mapper, $this->fetcher, $this->itemMapper, $this->api); $this->user = 'jack'; $response = 'hi'; @@ -70,7 +70,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($this->equalTo($this->user)) ->will($this->returnValue($this->response)); - $result = $this->bl->findAll($this->user); + $result = $this->businessLayer->findAll($this->user); $this->assertEquals($this->response, $result); } @@ -92,8 +92,8 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('fetch') ->with($this->equalTo($url)) ->will($this->throwException($ex)); - $this->setExpectedException('\OCA\News\Bl\BLException'); - $this->bl->create($url, 1, $this->user); + $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException'); + $this->businessLayer->create($url, 1, $this->user); } public function testCreate(){ @@ -126,7 +126,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('insert') ->with($this->equalTo($return[1][0])); - $feed = $this->bl->create($url, $folderId, $this->user); + $feed = $this->businessLayer->create($url, $folderId, $this->user); $this->assertEquals($feed->getFolderId(), $folderId); $this->assertEquals($feed->getUrl(), $url); @@ -143,8 +143,8 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->mapper->expects($this->once()) ->method('findByUrlHash') ->with($this->equalTo(md5($url)), $this->equalTo($this->user)); - $this->setExpectedException('\OCA\News\Bl\BLException'); - $this->bl->create($url, 1, $this->user); + $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException'); + $this->businessLayer->create($url, 1, $this->user); } @@ -187,7 +187,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($feed->getId(), $this->user) ->will($this->returnValue($feed)); - $return = $this->bl->update($feed->getId(), $this->user); + $return = $this->businessLayer->update($feed->getId(), $this->user); $this->assertEquals($return, $feed); } @@ -231,7 +231,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($feed->getId(), $this->user) ->will($this->returnValue($feed)); - $return = $this->bl->update($feed->getId(), $this->user); + $return = $this->businessLayer->update($feed->getId(), $this->user); $this->assertEquals($return, $feed); } @@ -281,7 +281,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($feed->getId(), $this->user) ->will($this->returnValue($feed)); - $return = $this->bl->update($feed->getId(), $this->user); + $return = $this->businessLayer->update($feed->getId(), $this->user); $this->assertEquals($return, $feed); $this->assertTrue($item->isUnread()); @@ -310,11 +310,75 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($feed->getId(), $this->user) ->will($this->returnValue($feed)); - $return = $this->bl->update($feed->getId(), $this->user); + $return = $this->businessLayer->update($feed->getId(), $this->user); $this->assertEquals($return, $feed); } + + public function testUpdateDoesNotFindEntry() { + $feed = new Feed(); + $feed->setId(3); + $feed->getUrl('test'); + + $ex = new DoesNotExistException(''); + + $this->mapper->expects($this->at(0)) + ->method('find') + ->with($this->equalTo($feed->getId()), + $this->equalTo($this->user)) + ->will($this->throwException($ex)); + + $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException'); + $return = $this->businessLayer->update($feed->getId(), $this->user); + } + + + public function testUpdateDoesNotFindUpdatedEntry() { + $feed = new Feed(); + $feed->setId(3); + $feed->getUrl('test'); + + $item = new Item(); + $item->setGuidHash(md5('hi')); + $item->setPubDate(3333); + $item->setId(4); + $items = array( + $item + ); + + $item2 = new Item(); + $item2->setPubDate(111); + + $fetchReturn = array($feed, $items); + $ex = new DoesNotExistException(''); + + $this->mapper->expects($this->at(0)) + ->method('find') + ->with($this->equalTo($feed->getId()), + $this->equalTo($this->user)) + ->will($this->returnValue($feed)); + $this->fetcher->expects($this->once()) + ->method('fetch') + ->will($this->returnValue($fetchReturn)); + $this->itemMapper->expects($this->once()) + ->method('findByGuidHash') + ->with($this->equalTo($item->getGuidHash()), + $this->equalTo($feed->getId()), + $this->equalTo($this->user)) + ->will($this->returnValue($item2));; + + $this->mapper->expects($this->at(1)) + ->method('find') + ->with($this->equalTo($feed->getId()), + $this->equalTo($this->user)) + ->will($this->throwException($ex)); + + $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException'); + $return = $this->businessLayer->update($feed->getId(), $this->user); + } + + public function testMove(){ $feedId = 3; $folderId = 4; @@ -331,7 +395,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('update') ->with($this->equalTo($feed)); - $this->bl->move($feedId, $folderId, $this->user); + $this->businessLayer->move($feedId, $folderId, $this->user); $this->assertEquals($folderId, $feed->getFolderId()); } diff --git a/tests/unit/bl/FolderBlTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php index ded6e1ddf..ad4e188e4 100644 --- a/tests/unit/bl/FolderBlTest.php +++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php @@ -23,7 +23,7 @@ * */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; require_once(__DIR__ . "/../../classloader.php"); @@ -31,11 +31,11 @@ require_once(__DIR__ . "/../../classloader.php"); use \OCA\News\Db\Folder; -class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { +class FolderBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { protected $api; protected $folderMapper; - protected $folderBl; + protected $folderBusinessLayer; protected function setUp(){ $this->api = $this->getAPIMock(); @@ -43,7 +43,7 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { '\OCA\News\Db\FolderMapper') ->disableOriginalConstructor() ->getMock(); - $this->folderBl = new FolderBl($this->folderMapper, $this->api); + $this->folderBusinessLayer = new FolderBusinessLayer($this->folderMapper, $this->api); } @@ -55,7 +55,7 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($this->equalTo($userId)) ->will($this->returnValue($return)); - $result = $this->folderBl->findAll($userId); + $result = $this->folderBusinessLayer->findAll($userId); $this->assertEquals($return, $result); } @@ -73,7 +73,7 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($this->equalTo($folder)) ->will($this->returnValue($folder)); - $result = $this->folderBl->create('hey', 'john', 5); + $result = $this->folderBusinessLayer->create('hey', 'john', 5); $this->assertEquals($folder, $result); } @@ -96,8 +96,8 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($this->equalTo($folderName)) ->will($this->returnValue($rows)); - $this->setExpectedException('\OCA\News\Bl\BLException'); - $result = $this->folderBl->create($folderName, 'john', 3); + $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException'); + $result = $this->folderBusinessLayer->create($folderName, 'john', 3); } @@ -113,7 +113,7 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('update') ->with($this->equalTo($folder)); - $this->folderBl->open(3, false, ''); + $this->folderBusinessLayer->open(3, false, ''); $this->assertFalse($folder->getOpened()); @@ -133,7 +133,7 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('update') ->with($this->equalTo($folder)); - $this->folderBl->rename(3, 'bogus', ''); + $this->folderBusinessLayer->rename(3, 'bogus', ''); $this->assertEquals('bogus', $folder->getName()); } @@ -156,8 +156,8 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($this->equalTo($folderName)) ->will($this->returnValue($rows)); - $this->setExpectedException('\OCA\News\Bl\BLException'); - $result = $this->folderBl->rename(3, $folderName, 'john'); + $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException'); + $result = $this->folderBusinessLayer->rename(3, $folderName, 'john'); } diff --git a/tests/unit/bl/ItemBlTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php index 80b1281e7..9bff8acfc 100644 --- a/tests/unit/bl/ItemBlTest.php +++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php @@ -23,7 +23,7 @@ * */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; require_once(__DIR__ . "/../../classloader.php"); @@ -33,11 +33,11 @@ use \OCA\News\Db\StatusFlag; use \OCA\News\Db\FeedType; -class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { +class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { private $api; private $mapper; - private $bl; + private $itemBusinessLayer; private $user; private $response; private $status; @@ -56,7 +56,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('typeToStatus') ->will($this->returnValue($this->status)); $this->threshold = 2; - $this->bl = new ItemBl($this->mapper, $statusFlag, $this->threshold); + $this->itemBusinessLayer = new ItemBusinessLayer($this->mapper, $statusFlag, $this->threshold); $this->user = 'jack'; $response = 'hi'; $this->id = 3; @@ -77,7 +77,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($this->user)) ->will($this->returnValue($this->response)); - $result = $this->bl->findAllNew( + $result = $this->itemBusinessLayer->findAllNew( $this->id, $type, $this->updatedSince, $this->showAll, $this->user); $this->assertEquals($this->response, $result); @@ -94,7 +94,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($this->user)) ->will($this->returnValue($this->response)); - $result = $this->bl->findAllNew( + $result = $this->itemBusinessLayer->findAllNew( $this->id, $type, $this->updatedSince, $this->showAll, $this->user); $this->assertEquals($this->response, $result); @@ -110,7 +110,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($this->user)) ->will($this->returnValue($this->response)); - $result = $this->bl->findAllNew( + $result = $this->itemBusinessLayer->findAllNew( $this->id, $type, $this->updatedSince, $this->showAll, $this->user); $this->assertEquals($this->response, $result); @@ -128,7 +128,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($this->user)) ->will($this->returnValue($this->response)); - $result = $this->bl->findAll( + $result = $this->itemBusinessLayer->findAll( $this->id, $type, $this->limit, $this->offset, $this->showAll, $this->user); @@ -147,7 +147,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($this->user)) ->will($this->returnValue($this->response)); - $result = $this->bl->findAll( + $result = $this->itemBusinessLayer->findAll( $this->id, $type, $this->limit, $this->offset, $this->showAll, $this->user); @@ -165,7 +165,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($this->user)) ->will($this->returnValue($this->response)); - $result = $this->bl->findAll( + $result = $this->itemBusinessLayer->findAll( $this->id, $type, $this->limit, $this->offset, $this->showAll, $this->user); @@ -181,7 +181,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { ->with($this->equalTo($this->user)) ->will($this->returnValue($star)); - $result = $this->bl->starredCount($this->user); + $result = $this->itemBusinessLayer->starredCount($this->user); $this->assertEquals($star, $result); } @@ -207,7 +207,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('update') ->with($this->equalTo($item)); - $this->bl->star($feedId, $guidHash, false, $this->user); + $this->itemBusinessLayer->star($feedId, $guidHash, false, $this->user); $this->assertTrue($item->isUnstarred()); } @@ -228,7 +228,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('update') ->with($this->equalTo($item)); - $this->bl->read($itemId, false, $this->user); + $this->itemBusinessLayer->read($itemId, false, $this->user); $this->assertTrue($item->isUnread()); } @@ -244,7 +244,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($highestItemId), $this->equalTo($this->user)); - $this->bl->readFeed($feedId, $highestItemId, $this->user); + $this->itemBusinessLayer->readFeed($feedId, $highestItemId, $this->user); } @@ -262,7 +262,7 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('deleteReadOlderThanId') ->with($this->equalTo($item->getId())); - $result = $this->bl->autoPurgeOld(); + $result = $this->itemBusinessLayer->autoPurgeOld(); } diff --git a/tests/unit/bl/StatusFlagTest.php b/tests/unit/businesslayer/StatusFlagTest.php index 12e78d8cc..12e78d8cc 100644 --- a/tests/unit/bl/StatusFlagTest.php +++ b/tests/unit/businesslayer/StatusFlagTest.php diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index b835e585a..74cce1d71 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -42,8 +42,8 @@ class ExportControllerTest extends ControllerTestUtility { private $request; private $controller; private $user; - private $feedBl; - private $folderBl; + private $feedBusinessLayer; + private $folderBusinessLayer; private $opmlExporter; /** @@ -51,16 +51,16 @@ class ExportControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->feedBl = $this->getMockBuilder('\OCA\News\Bl\FeedBl') + $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->folderBl = $this->getMockBuilder('\OCA\News\Bl\FolderBl') + $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); $this->opmlExporter = new OPMLExporter(); $this->controller = new ExportController($this->api, $this->request, - $this->feedBl, $this->folderBl, $this->opmlExporter); + $this->feedBusinessLayer, $this->folderBusinessLayer, $this->opmlExporter); $this->user = 'john'; } @@ -76,11 +76,11 @@ class ExportControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->feedBl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue(array())); - $this->folderBl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue(array())); diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index e7c7c29e3..c7c69fb03 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -33,7 +33,7 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedType; -use \OCA\News\Bl\BLException; +use \OCA\News\BusinessLayer\BusinessLayerException; require_once(__DIR__ . "/../../classloader.php"); @@ -42,10 +42,10 @@ require_once(__DIR__ . "/../../classloader.php"); class FeedControllerTest extends ControllerTestUtility { private $api; - private $bl; + private $feedBusinessLayer; private $request; private $controller; - private $folderBl; + private $folderBusinessLayer; /** @@ -53,15 +53,15 @@ class FeedControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->bl = $this->getMockBuilder('\OCA\News\Bl\FeedBl') + $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->folderBl = $this->getMockBuilder('\OCA\News\Bl\FolderBl') + $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); $this->controller = new FeedController($this->api, $this->request, - $this->bl, $this->folderBl); + $this->feedBusinessLayer, $this->folderBusinessLayer); $this->user = 'jack'; } @@ -78,7 +78,7 @@ class FeedControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new FeedController($this->api, $request, $this->bl, $this->folderBl); + return new FeedController($this->api, $request, $this->feedBusinessLayer, $this->folderBusinessLayer); } @@ -121,7 +121,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['feeds'])); @@ -170,14 +170,14 @@ class FeedControllerTest extends ControllerTestUtility { public function testActiveFeedDoesNotExist(){ $id = 3; $type = FeedType::FEED; - $ex = new BLException('hiu'); + $ex = new BusinessLayerException('hiu'); $result = array( 'activeFeed' => array( 'id' => 0, 'type' => FeedType::SUBSCRIPTIONS ) ); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('find') ->with($this->equalTo($id), $this->equalTo($this->user)) ->will($this->throwException($ex)); @@ -194,14 +194,14 @@ class FeedControllerTest extends ControllerTestUtility { public function testActiveFolderDoesNotExist(){ $id = 3; $type = FeedType::FOLDER; - $ex = new BLException('hiu'); + $ex = new BusinessLayerException('hiu'); $result = array( 'activeFeed' => array( 'id' => 0, 'type' => FeedType::SUBSCRIPTIONS ) ); - $this->folderBl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('find') ->with($this->equalTo($id), $this->equalTo($this->user)) ->will($this->throwException($ex)); @@ -249,7 +249,7 @@ class FeedControllerTest extends ControllerTestUtility { ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($post['url']), $this->equalTo($post['parentFolderId']), @@ -265,8 +265,8 @@ class FeedControllerTest extends ControllerTestUtility { public function testCreateReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BLException($msg); - $this->bl->expects($this->once()) + $ex = new BusinessLayerException($msg); + $this->feedBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -288,7 +288,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('delete') ->with($this->equalTo($url['feedId'])); @@ -312,7 +312,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('update') ->with($this->equalTo($url['feedId']), $this->equalTo($this->user)) ->will($this->returnValue($result['feeds'][0])); @@ -324,6 +324,34 @@ class FeedControllerTest extends ControllerTestUtility { } + public function testUpdateReturnsJSONError(){ + $result = array( + 'feeds' => array( + new Feed() + ) + ); + + $url = array( + 'feedId' => 4 + ); + $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)) + ->will($this->throwException(new BusinessLayerException('NO!'))); + + $response = $this->controller->update(); + $render = $response->render(); + + $this->assertEquals('{"status":"error","data":[],"msg":"NO!"}', $render); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testMove(){ $post = array( 'parentFolderId' => 3 @@ -336,7 +364,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('move') ->with($this->equalTo($url['feedId']), $this->equalTo($post['parentFolderId']), diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index 231cc9187..b71c522e0 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -32,7 +32,7 @@ use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; -use \OCA\News\Bl\BLException; +use \OCA\News\BusinessLayer\BusinessLayerException; require_once(__DIR__ . "/../../classloader.php"); @@ -40,7 +40,7 @@ require_once(__DIR__ . "/../../classloader.php"); class FolderControllerTest extends ControllerTestUtility { private $api; - private $bl; + private $folderBusinessLayer; private $request; private $controller; @@ -50,12 +50,12 @@ class FolderControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->bl = $this->getMockBuilder('\OCA\News\Bl\FolderBl') + $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); $this->controller = new FolderController($this->api, $this->request, |