diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-09 12:57:35 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-09 12:57:35 +0200 |
commit | b8b4dfb4969e1baf84a14fb65a5dc153b0f5fae4 (patch) | |
tree | 27e211e26f442efd72a7f34903953ad57b1a9b76 /tests/unit/controller | |
parent | fe0de2ab84a88cb4c742f4f10fd43716934b7282 (diff) |
only make one request for mark all read and mark folder read, fix #171, fix a bug that prevented readding of feeds when its folder was deleted, fix a bug that would not allow mark read for feeds when the app was started for the first time
Diffstat (limited to 'tests/unit/controller')
-rw-r--r-- | tests/unit/controller/FeedControllerTest.php | 81 | ||||
-rw-r--r-- | tests/unit/controller/FolderControllerTest.php | 52 | ||||
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 38 |
3 files changed, 145 insertions, 26 deletions
diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index 403d9c3c8..c89d432d6 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -65,7 +65,8 @@ class FeedControllerTest extends ControllerTestUtility { ->getMock(); $this->request = new Request(); $this->controller = new FeedController($this->api, $this->request, - $this->feedBusinessLayer, $this->folderBusinessLayer, + $this->folderBusinessLayer, + $this->feedBusinessLayer, $this->itemBusinessLayer); $this->user = 'jack'; } @@ -83,8 +84,10 @@ class FeedControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new FeedController($this->api, $request, $this->feedBusinessLayer, - $this->folderBusinessLayer, $this->itemBusinessLayer); + return new FeedController($this->api, $request, + $this->folderBusinessLayer, + $this->feedBusinessLayer, + $this->itemBusinessLayer); } @@ -122,6 +125,10 @@ class FeedControllerTest extends ControllerTestUtility { $this->assertFeedControllerAnnotations('importGoogleReader'); } + public function testReadAnnotations(){ + $this->assertFeedControllerAnnotations('read'); + } + public function testFeeds(){ $result = array( 'feeds' => array( @@ -287,6 +294,40 @@ class FeedControllerTest extends ControllerTestUtility { public function testCreate(){ $result = array( + 'feeds' => array(new Feed()), + 'newestItemId' => 3 + ); + + $post = array( + 'url' => 'hi', + 'parentFolderId' => 4 + ); + $this->controller = $this->getPostController($post); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->will($this->returnValue($result['newestItemId'])); + + $this->feedBusinessLayer->expects($this->once()) + ->method('create') + ->with($this->equalTo($post['url']), + $this->equalTo($post['parentFolderId']), + $this->equalTo($this->user)) + ->will($this->returnValue($result['feeds'][0])); + + $response = $this->controller->create(); + + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testCreateNoItems(){ + $result = array( 'feeds' => array(new Feed()) ); @@ -300,6 +341,10 @@ class FeedControllerTest extends ControllerTestUtility { ->method('getUserId') ->will($this->returnValue($this->user)); + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->will($this->throwException(new BusinessLayerException(''))); + $this->feedBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($post['url']), @@ -508,4 +553,34 @@ class FeedControllerTest extends ControllerTestUtility { $this->assertTrue($response instanceof JSONResponse); } + + public function testReadFeed(){ + $url = array( + 'feedId' => 4 + ); + $post = array( + 'highestItemId' => 5 + ); + $this->controller = $this->getPostController($post, $url); + $expected = array( + 'feeds' => array( + array( + 'id' => 4, + 'unreadCount' => 0 + ) + ) + ); + + $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); + + $response = $this->controller->read(); + $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($expected, $response->getParams()); + } + }
\ No newline at end of file diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index 67529edbc..30edf737f 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -32,6 +32,7 @@ use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; +use \OCA\News\Db\Feed; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\BusinessLayerExistsException; @@ -42,6 +43,8 @@ class FolderControllerTest extends ControllerTestUtility { private $api; private $folderBusinessLayer; + private $itemBusinessLayer; + private $feedBusinessLayer; private $request; private $controller; private $msg; @@ -55,9 +58,17 @@ class FolderControllerTest extends ControllerTestUtility { $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); + $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') + ->disableOriginalConstructor() + ->getMock(); + $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') + ->disableOriginalConstructor() + ->getMock(); $this->request = new Request(); $this->controller = new FolderController($this->api, $this->request, - $this->folderBusinessLayer); + $this->folderBusinessLayer, + $this->feedBusinessLayer, + $this->itemBusinessLayer); $this->user = 'jack'; $this->msg = 'ron'; } @@ -76,7 +87,10 @@ class FolderControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new FolderController($this->api, $request, $this->folderBusinessLayer); + return new FolderController($this->api, $request, + $this->folderBusinessLayer, + $this->feedBusinessLayer, + $this->itemBusinessLayer); } public function testFoldersAnnotations(){ @@ -109,6 +123,9 @@ class FolderControllerTest extends ControllerTestUtility { } + public function testReadAnnotations(){ + $this->assertFolderControllerAnnotations('read'); + } public function testFolders(){ $return = array( @@ -325,4 +342,35 @@ class FolderControllerTest extends ControllerTestUtility { } + public function testRead(){ + $feed = new Feed(); + $url = array( + 'folderId' => 4 + ); + $post = array( + 'highestItemId' => 5 + ); + $this->controller = $this->getPostController($post, $url); + $expected = array( + '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']), + $this->equalTo($post['highestItemId']), + $this->equalTo($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue(array($feed))); + + $response = $this->controller->read(); + $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($expected, $response->getParams()); + } + }
\ No newline at end of file diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index 16df210e0..e0e90af1e 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -62,7 +62,7 @@ class ItemControllerTest extends ControllerTestUtility { ->getMock(); $this->request = new Request(); $this->controller = new ItemController($this->api, $this->request, - $this->itemBusinessLayer, $this->feedBusinessLayer); + $this->feedBusinessLayer, $this->itemBusinessLayer); $this->user = 'jackob'; $this->newestItemId = 12312; } @@ -74,8 +74,8 @@ class ItemControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new ItemController($this->api, $request, $this->itemBusinessLayer, - $this->feedBusinessLayer); + return new ItemController($this->api, $request, + $this->feedBusinessLayer, $this->itemBusinessLayer); } @@ -108,9 +108,8 @@ class ItemControllerTest extends ControllerTestUtility { $this->assertItemControllerAnnotations('unread'); } - - public function testReadFeedAnnotations(){ - $this->assertItemControllerAnnotations('readFeed'); + public function testReadAllAnnotations(){ + $this->assertItemControllerAnnotations('readAll'); } @@ -293,37 +292,34 @@ class ItemControllerTest extends ControllerTestUtility { } - public function testReadFeed(){ - $url = array( - 'feedId' => 4 - ); + public function testReadAll(){ + $feed = new Feed(); $post = array( 'highestItemId' => 5 ); - $this->controller = $this->getPostController($post, $url); + $this->controller = $this->getPostController($post); $expected = array( - 'feeds' => array( - array( - 'id' => 4, - 'unreadCount' => 0 - ) - ) + 'feeds' => array($feed) ); $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); + ->method('readAll') + ->with($this->equalTo($post['highestItemId']), + $this->equalTo($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue(array($feed))); - $response = $this->controller->readFeed(); + $response = $this->controller->readAll(); $this->assertTrue($response instanceof JSONResponse); $this->assertEquals($expected, $response->getParams()); } - private function itemsApiExpects($id, $type){ $this->api->expects($this->once()) ->method('getUserValue') |