diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/businesslayer/ItemBusinessLayerTest.php | 26 | ||||
-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 | ||||
-rw-r--r-- | tests/unit/db/ItemMapperTest.php | 44 | ||||
-rw-r--r-- | tests/unit/external/FolderAPITest.php | 86 | ||||
-rw-r--r-- | tests/unit/external/ItemAPITest.php | 28 |
7 files changed, 286 insertions, 69 deletions
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php index 2094456b7..54b7bc5fc 100644 --- a/tests/unit/businesslayer/ItemBusinessLayerTest.php +++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php @@ -259,6 +259,32 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { } + public function testReadAll(){ + $highestItemId = 6; + + $this->mapper->expects($this->once()) + ->method('readAll') + ->with($this->equalTo($highestItemId), + $this->equalTo($this->user)); + + $this->itemBusinessLayer->readAll($highestItemId, $this->user); + } + + + public function testReadFolder(){ + $folderId = 3; + $highestItemId = 6; + + $this->mapper->expects($this->once()) + ->method('readFolder') + ->with($this->equalTo($folderId), + $this->equalTo($highestItemId), + $this->equalTo($this->user)); + + $this->itemBusinessLayer->readFolder($folderId, $highestItemId, $this->user); + } + + public function testReadFeed(){ $feedId = 3; $highestItemId = 6; 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') diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php index 764042d36..6d0de6459 100644 --- a/tests/unit/db/ItemMapperTest.php +++ b/tests/unit/db/ItemMapperTest.php @@ -125,34 +125,54 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { } - public function testReadFeed(){ + public function testReadAll(){ $sql = 'UPDATE `*PREFIX*news_items` ' . 'SET `status` = `status` & ? ' . - 'WHERE `feed_id` = ? ' . - 'AND `id` <= ? ' . - 'AND EXISTS (' . - 'SELECT * FROM `*PREFIX*news_feeds` ' . - 'WHERE `user_id` = ? ' . - 'AND `id` = ? ) '; - $params = array(~StatusFlag::UNREAD, 3, 6, $this->user, 3); + 'WHERE `id` IN (' . + 'SELECT `items`.`id` FROM `*PREFIX*news_items` `items` ' . + 'JOIN `*PREFIX*news_feeds` `feeds` ' . + 'ON `feeds`.`id` = `items`.`feed_id` '. + 'AND `items`.`id` <= ? ' . + 'AND `feeds`.`user_id` = ? ' . + ') '; + $params = array(~StatusFlag::UNREAD, 3, $this->user); $this->setMapperResult($sql, $params); - $this->mapper->readFeed(3, 6, $this->user); + $this->mapper->readAll(3, $this->user); + } + + + public function testReadFolder(){ + $sql = 'UPDATE `*PREFIX*news_items` ' . + 'SET `status` = `status` & ? ' . + 'WHERE `id` IN (' . + 'SELECT `items`.`id` FROM `*PREFIX*news_items` `items` ' . + 'JOIN `*PREFIX*news_feeds` `feeds` ' . + 'ON `feeds`.`id` = `items`.`feed_id` '. + 'AND `feeds`.`folder_id` = ? ' . + 'AND `items`.`id` <= ? ' . + 'AND `feeds`.`user_id` = ? ' . + ') '; + $params = array(~StatusFlag::UNREAD, 3, 6, $this->user); + $this->setMapperResult($sql, $params); + $this->mapper->readFolder(3, 6, $this->user); } - public function testReadFeedShouldMarkAllAsReadWhenIdZero(){ + public function testReadFeed(){ $sql = 'UPDATE `*PREFIX*news_items` ' . 'SET `status` = `status` & ? ' . 'WHERE `feed_id` = ? ' . + 'AND `id` <= ? ' . 'AND EXISTS (' . 'SELECT * FROM `*PREFIX*news_feeds` ' . 'WHERE `user_id` = ? ' . 'AND `id` = ? ) '; - $params = array(~StatusFlag::UNREAD, 3,$this->user, 3); + $params = array(~StatusFlag::UNREAD, 3, 6, $this->user, 3); $this->setMapperResult($sql, $params); - $this->mapper->readFeed(3, 0, $this->user); + $this->mapper->readFeed(3, 6, $this->user); } + public function testFindAllNew(){ $sql = 'AND `items`.`last_modified` >= ?'; $sql = $this->makeSelectQueryStatus($sql, $this->status); diff --git a/tests/unit/external/FolderAPITest.php b/tests/unit/external/FolderAPITest.php index 8b7a7b797..654a4fbae 100644 --- a/tests/unit/external/FolderAPITest.php +++ b/tests/unit/external/FolderAPITest.php @@ -40,6 +40,7 @@ require_once(__DIR__ . "/../../classloader.php"); class FolderAPITest extends \PHPUnit_Framework_TestCase { private $folderBusinessLayer; + private $itemBusinessLayer; private $folderAPI; private $api; private $user; @@ -59,13 +60,21 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { '\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); + $this->itemBusinessLayer = $this->getMockBuilder( + '\OCA\News\BusinessLayer\ItemBusinessLayer') + ->disableOriginalConstructor() + ->getMock(); $this->folderAPI = new FolderAPI( $this->api, $this->request, - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); $this->user = 'tom'; $this->msg = 'test'; + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); } @@ -74,9 +83,6 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { 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)) @@ -102,12 +108,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { new Request(array('params' => array( 'name' => $folderName ))), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($folderName), $this->equalTo($this->user)) @@ -123,9 +127,6 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { public function testCreateAlreadyExists() { $msg = 'exists'; - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException(new BusinessLayerExistsException($msg))); @@ -146,12 +147,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { new Request(array('urlParams' => array( 'folderId' => $folderId ))), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $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)); @@ -170,12 +169,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { new Request(array('urlParams' => array( 'folderId' => $folderId ))), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $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))); @@ -205,12 +202,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { ) ) ), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('rename') ->with($this->equalTo($folderId), @@ -241,12 +236,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { ) ) ), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $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))); @@ -276,12 +269,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { ) ) ), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('rename') ->will($this->throwException(new BusinessLayerExistsException($this->msg))); @@ -293,4 +284,37 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { $this->assertEquals(NewsAPIResult::EXISTS_ERROR, $response->getStatusCode()); } + + public function testRead() { + $request = new Request(array( + 'urlParams' => array( + 'folderId' => 3 + ), + 'params' => array( + 'newestItemId' => 30, + ) + )); + $this->folderAPI = new FolderAPI( + $this->api, + $request, + $this->folderBusinessLayer, + $this->itemBusinessLayer + ); + + + $this->itemBusinessLayer->expects($this->once()) + ->method('readFolder') + ->with( + $this->equalTo(3), + $this->equalTo(30), + $this->equalTo($this->user)); + + $response = $this->folderAPI->read(); + + $this->assertNull($response->getData()); + $this->assertNull($response->getMessage()); + $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode()); + } + + }
\ No newline at end of file diff --git a/tests/unit/external/ItemAPITest.php b/tests/unit/external/ItemAPITest.php index a6cd96018..94c91eea0 100644 --- a/tests/unit/external/ItemAPITest.php +++ b/tests/unit/external/ItemAPITest.php @@ -336,4 +336,32 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase { $this->assertEquals(NewsAPIResult::NOT_FOUND_ERROR, $response->getStatusCode()); } + + public function testReadAll() { + $request = new Request(array( + 'params' => array( + 'newestItemId' => 30, + ) + )); + $this->itemAPI = new ItemAPI( + $this->api, + $request, + $this->itemBusinessLayer + ); + + + $this->itemBusinessLayer->expects($this->once()) + ->method('readAll') + ->with( + $this->equalTo(30), + $this->equalTo($this->user)); + + $response = $this->itemAPI->readAll(); + + $this->assertNull($response->getData()); + $this->assertNull($response->getMessage()); + $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode()); + } + + }
\ No newline at end of file |