From 3fc18156ae0b586e8de0c82949acfa6291317536 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 29 Apr 2013 13:25:04 +0200 Subject: go back to order by id, fix #138, use a newest item id to prevent marking items as read that the user didnt see yet fix #141, also update the starred count periodically --- tests/unit/businesslayer/FeedBusinessLayerTest.php | 2 + tests/unit/businesslayer/ItemBusinessLayerTest.php | 40 ++++++----- tests/unit/controller/FeedControllerTest.php | 55 +++++++++++++-- tests/unit/controller/ItemControllerTest.php | 35 ++-------- tests/unit/db/ItemMapperTest.php | 78 +++++++++++++++------- 5 files changed, 134 insertions(+), 76 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 0f8f61e4f..e6fb5bb7b 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -677,4 +677,6 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->assertEquals($feed, $result); } + + } diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php index 8a47fd599..e32a3b308 100644 --- a/tests/unit/businesslayer/ItemBusinessLayerTest.php +++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php @@ -130,21 +130,20 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { } - public function testFindAllFeed(){ + public function testFindAllFeed(){ $type = FeedType::FEED; $this->mapper->expects($this->once()) ->method('findAllFeed') ->with($this->equalTo($this->id), $this->equalTo($this->limit), $this->equalTo($this->offset), - $this->equalTo($this->newestItemId), $this->equalTo($this->status), $this->equalTo($this->user)) ->will($this->returnValue($this->response)); $result = $this->itemBusinessLayer->findAll( $this->id, $type, $this->limit, - $this->offset, $this->newestItemId, $this->showAll, + $this->offset, $this->showAll, $this->user); $this->assertEquals($this->response, $result); } @@ -157,14 +156,13 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { ->with($this->equalTo($this->id), $this->equalTo($this->limit), $this->equalTo($this->offset), - $this->equalTo($this->newestItemId), $this->equalTo($this->status), $this->equalTo($this->user)) ->will($this->returnValue($this->response)); $result = $this->itemBusinessLayer->findAll( $this->id, $type, $this->limit, - $this->offset, $this->newestItemId, $this->showAll, + $this->offset, $this->showAll, $this->user); $this->assertEquals($this->response, $result); } @@ -176,33 +174,18 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { ->method('findAll') ->with( $this->equalTo($this->limit), $this->equalTo($this->offset), - $this->equalTo($this->newestItemId), $this->equalTo($this->status), $this->equalTo($this->user)) ->will($this->returnValue($this->response)); $result = $this->itemBusinessLayer->findAll( $this->id, $type, $this->limit, - $this->offset, $this->newestItemId, $this->showAll, + $this->offset, $this->showAll, $this->user); $this->assertEquals($this->response, $result); } - public function testStarredCount(){ - $star = 18; - - $this->mapper->expects($this->once()) - ->method('starredCount') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($star)); - - $result = $this->itemBusinessLayer->starredCount($this->user); - - $this->assertEquals($star, $result); - } - - public function testStar(){ $itemId = 3; $feedId = 5; @@ -310,6 +293,21 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->itemBusinessLayer->getNewestItemId($this->user); } + + public function testStarredCount(){ + $star = 18; + + $this->mapper->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($star)); + + $result = $this->itemBusinessLayer->starredCount($this->user); + + $this->assertEquals($star, $result); + } + + } diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index b41977962..14c31b545 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -46,6 +46,7 @@ class FeedControllerTest extends ControllerTestUtility { private $request; private $controller; private $folderBusinessLayer; + private $itemBusinessLayer; /** @@ -53,6 +54,9 @@ class FeedControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); + $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') + ->disableOriginalConstructor() + ->getMock(); $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') ->disableOriginalConstructor() ->getMock(); @@ -61,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->feedBusinessLayer, $this->folderBusinessLayer, + $this->itemBusinessLayer); $this->user = 'jack'; } @@ -78,7 +83,8 @@ class FeedControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new FeedController($this->api, $request, $this->feedBusinessLayer, $this->folderBusinessLayer); + return new FeedController($this->api, $request, $this->feedBusinessLayer, + $this->folderBusinessLayer, $this->itemBusinessLayer); } @@ -119,8 +125,40 @@ class FeedControllerTest extends ControllerTestUtility { public function testFeeds(){ $result = array( 'feeds' => array( - array('a feed') - ) + array('a feed'), + ), + '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)) + ->will($this->returnValue($result['feeds'])); + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->with($this->equalTo($this->user)) + ->will($this->throwException(new BusinessLayerException(''))); + $this->itemBusinessLayer->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($result['starred'])); + + $response = $this->controller->feeds(); + + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testFeedsHighestItemIdExists(){ + $result = array( + 'feeds' => array( + array('a feed'), + ), + 'starred' => 13, + 'newestItemId' => 5 ); $this->api->expects($this->once()) ->method('getUserId') @@ -129,6 +167,14 @@ class FeedControllerTest extends ControllerTestUtility { ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['feeds'])); + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($result['newestItemId'])); + $this->itemBusinessLayer->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($result['starred'])); $response = $this->controller->feeds(); @@ -137,6 +183,7 @@ class FeedControllerTest extends ControllerTestUtility { } + private function activeInitMocks($id, $type){ $this->api->expects($this->at(0)) ->method('getUserId') diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index 451053317..b0d2a52bc 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -89,11 +89,6 @@ class ItemControllerTest extends ControllerTestUtility { } - public function testStarredAnnotations(){ - $this->assertItemControllerAnnotations('starred'); - } - - public function testStarAnnotations(){ $this->assertItemControllerAnnotations('star'); } @@ -230,24 +225,6 @@ class ItemControllerTest extends ControllerTestUtility { } - public function testStarred(){ - $result = array( - 'starred' => 3 - ); - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); - $this->itemBusinessLayer->expects($this->once()) - ->method('starredCount') - ->with($this->user) - ->will($this->returnValue($result['starred'])); - $response = $this->controller->starred(); - - $this->assertEquals($result, $response->getParams()); - $this->assertTrue($response instanceof JSONResponse); - } - - private function itemsApiExpects($id, $type){ $this->api->expects($this->once()) @@ -273,14 +250,14 @@ class ItemControllerTest extends ControllerTestUtility { $result = array( 'items' => array(new Item()), 'feeds' => $feeds, - 'newestItemId' => $this->newestItemId + 'newestItemId' => $this->newestItemId, + 'starred' => 3111 ); $post = array( 'limit' => 3, 'type' => FeedType::FEED, 'id' => 2, 'offset' => 0, - 'newestItemId' => 3 ); $this->controller = $this->getPostController($post); @@ -296,6 +273,11 @@ class ItemControllerTest extends ControllerTestUtility { ->with($this->equalTo($this->user)) ->will($this->returnValue($this->newestItemId)); + $this->itemBusinessLayer->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue(3111)); + $this->itemBusinessLayer->expects($this->once()) ->method('findAll') ->with( @@ -303,7 +285,6 @@ class ItemControllerTest extends ControllerTestUtility { $this->equalTo($post['type']), $this->equalTo($post['limit']), $this->equalTo($post['offset']), - $this->equalTo($this->newestItemId), $this->equalTo(true), $this->equalTo($this->user)) ->will($this->returnValue($result['items'])); @@ -323,7 +304,6 @@ class ItemControllerTest extends ControllerTestUtility { 'type' => FeedType::FEED, 'id' => 2, 'offset' => 10, - 'newestItemId' => 3 ); $this->controller = $this->getPostController($post); @@ -335,7 +315,6 @@ class ItemControllerTest extends ControllerTestUtility { $this->equalTo($post['type']), $this->equalTo($post['limit']), $this->equalTo($post['offset']), - $this->equalTo($post['newestItemId']), $this->equalTo(true), $this->equalTo($this->user)) ->will($this->returnValue($result['items'])); diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php index ff5bb1f4c..764042d36 100644 --- a/tests/unit/db/ItemMapperTest.php +++ b/tests/unit/db/ItemMapperTest.php @@ -194,17 +194,28 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { } - public function testFindAll(){ - $sql = 'AND `items`.`id` < ? ' . - 'ORDER BY `items`.`pub_date` DESC, `items`.`id` DESC '; + public function testFindAllFeed(){ + $sql = 'AND `items`.`feed_id` = ? ' . + 'AND `items`.`id` < ? ' . + 'ORDER BY `items`.`id` DESC '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->newestItemId); - $this->setMapperResult($sql, $params, $this->rows, - $this->limit, $this->offset); + $params = array($this->user, $this->id, $this->offset); + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->mapper->findAllFeed($this->id, $this->limit, + $this->offset, $this->status, $this->user); + + $this->assertEquals($this->items, $result); + } - $result = $this->mapper->findAll($this->limit, - $this->offset, $this->newestItemId, - $this->status, $this->user); + + public function testFindAllFeedOffsetZero(){ + $sql = 'AND `items`.`feed_id` = ? ' . + 'ORDER BY `items`.`id` DESC '; + $sql = $this->makeSelectQueryStatus($sql, $this->status); + $params = array($this->user, $this->id); + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->mapper->findAllFeed($this->id, $this->limit, + 0, $this->status, $this->user); $this->assertEquals($this->items, $result); } @@ -213,37 +224,58 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { public function testFindAllFolder(){ $sql = 'AND `feeds`.`folder_id` = ? ' . 'AND `items`.`id` < ? ' . - 'ORDER BY `items`.`pub_date` DESC, `items`.`id` DESC '; + 'ORDER BY `items`.`id` DESC '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->id, $this->newestItemId); + $params = array($this->user, $this->id, + $this->offset); + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->mapper->findAllFolder($this->id, $this->limit, + $this->offset, $this->status, $this->user); + + $this->assertEquals($this->items, $result); + } - $this->setMapperResult($sql, $params, $this->rows, - $this->limit, $this->offset); + public function testFindAllFolderOffsetZero(){ + $sql = 'AND `feeds`.`folder_id` = ? ' . + 'ORDER BY `items`.`id` DESC '; + $sql = $this->makeSelectQueryStatus($sql, $this->status); + $params = array($this->user, $this->id); + $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllFolder($this->id, $this->limit, - $this->offset, $this->newestItemId, $this->status, $this->user); + 0, $this->status, $this->user); $this->assertEquals($this->items, $result); } - public function testFindAllFeed(){ - $sql = 'AND `items`.`feed_id` = ? ' . - 'AND `items`.`id` < ? ' . - 'ORDER BY `items`.`pub_date` DESC, `items`.`id` DESC '; + public function testFindAll(){ + $sql = 'AND `items`.`id` < ? ' . + 'ORDER BY `items`.`id` DESC '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->id, $this->newestItemId); - $this->setMapperResult($sql, $params, $this->rows, $this->limit, - $this->offset); + $params = array($this->user, $this->offset); + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->mapper->findAll($this->limit, + $this->offset, $this->status, $this->user); - $result = $this->mapper->findAllFeed($this->id, $this->limit, - $this->offset, $this->newestItemId, $this->status, $this->user); + $this->assertEquals($this->items, $result); + } + + + public function testFindAllOffsetZero(){ + $sql = 'ORDER BY `items`.`id` DESC '; + $sql = $this->makeSelectQueryStatus($sql, $this->status); + $params = array($this->user); + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->mapper->findAll($this->limit, + 0, $this->status, $this->user); $this->assertEquals($this->items, $result); } + public function testFindByGuidHash(){ $hash = md5('test'); $feedId = 3; -- cgit v1.2.3