summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-26 10:46:32 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-26 11:52:50 +0200
commit5cc47b4f414026ecf16d8c7025571422367f7c58 (patch)
treef555d0769e0a594f3a8f873ff8b455e0bf2a00ee /tests
parent5d41833874a69d2c9322a20ebb7815b6bb1b5adf (diff)
use last_modified column for finding new items (so we also see if they were updated or starred), use offset to paginate rather than item id
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/businesslayer/ItemBusinessLayerTest.php33
-rw-r--r--tests/unit/controller/ItemControllerTest.php70
-rw-r--r--tests/unit/db/ItemMapperTest.php134
3 files changed, 148 insertions, 89 deletions
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php
index 17c477398..5b5598abd 100644
--- a/tests/unit/businesslayer/ItemBusinessLayerTest.php
+++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php
@@ -27,6 +27,7 @@ namespace OCA\News\BusinessLayer;
require_once(__DIR__ . "/../../classloader.php");
+use \OCA\AppFramework\Db\DoesNotExistException;
use \OCA\News\Db\Item;
use \OCA\News\Db\StatusFlag;
@@ -42,6 +43,7 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
private $response;
private $status;
private $time;
+ private $newestItemId;
protected function setUp(){
@@ -74,6 +76,7 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->showAll = true;
$this->offset = 5;
$this->limit = 20;
+ $this->newestItemId = 4;
}
@@ -134,13 +137,14 @@ 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->showAll,
+ $this->offset, $this->newestItemId, $this->showAll,
$this->user);
$this->assertEquals($this->response, $result);
}
@@ -153,13 +157,14 @@ 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->showAll,
+ $this->offset, $this->newestItemId, $this->showAll,
$this->user);
$this->assertEquals($this->response, $result);
}
@@ -171,13 +176,14 @@ 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->showAll,
+ $this->offset, $this->newestItemId, $this->showAll,
$this->user);
$this->assertEquals($this->response, $result);
}
@@ -283,6 +289,27 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
}
+ public function testGetNewestItemId() {
+ $this->mapper->expects($this->once())
+ ->method('getNewestItemId')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue(12));
+
+ $result = $this->itemBusinessLayer->getNewestItemId($this->user);
+ $this->assertEquals(12, $result);
+ }
+
+
+ public function testGetNewestItemIdDoesNotExist() {
+ $this->mapper->expects($this->once())
+ ->method('getNewestItemId')
+ ->with($this->equalTo($this->user))
+ ->will($this->throwException(new DoesNotExistException('There are no items')));
+
+ $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException');
+ $this->itemBusinessLayer->getNewestItemId($this->user);
+ }
+
}
diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php
index 00d455830..451053317 100644
--- a/tests/unit/controller/ItemControllerTest.php
+++ b/tests/unit/controller/ItemControllerTest.php
@@ -32,6 +32,7 @@ use \OCA\AppFramework\Utility\ControllerTestUtility;
use \OCA\News\Db\Item;
use \OCA\News\Db\Feed;
use \OCA\News\Db\FeedType;
+use \OCA\News\BusinessLayer\BusinessLayerException;
require_once(__DIR__ . "/../../classloader.php");
@@ -43,6 +44,7 @@ class ItemControllerTest extends ControllerTestUtility {
private $feedBusinessLayer;
private $request;
private $controller;
+ private $newestItemId;
/**
@@ -62,6 +64,7 @@ class ItemControllerTest extends ControllerTestUtility {
$this->controller = new ItemController($this->api, $this->request,
$this->itemBusinessLayer, $this->feedBusinessLayer);
$this->user = 'jackob';
+ $this->newestItemId = 12312;
}
private function getPostController($postValue, $url=array()){
@@ -269,36 +272,49 @@ class ItemControllerTest extends ControllerTestUtility {
$feeds = array(new Feed());
$result = array(
'items' => array(new Item()),
- 'feeds' => $feeds
+ 'feeds' => $feeds,
+ 'newestItemId' => $this->newestItemId
);
$post = array(
'limit' => 3,
'type' => FeedType::FEED,
'id' => 2,
- 'offset' => 0
+ 'offset' => 0,
+ 'newestItemId' => 3
);
$this->controller = $this->getPostController($post);
$this->itemsApiExpects($post['id'], $post['type']);
- $this->itemBusinessLayer->expects($this->once())
- ->method('findAll')
- ->with($post['id'], $post['type'], $post['limit'],
- $post['offset'], true, $this->user)
- ->will($this->returnValue($result['items']));
-
$this->feedBusinessLayer->expects($this->once())
->method('findAll')
->with($this->equalTo($this->user))
->will($this->returnValue($feeds));
+ $this->itemBusinessLayer->expects($this->once())
+ ->method('getNewestItemId')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($this->newestItemId));
+
+ $this->itemBusinessLayer->expects($this->once())
+ ->method('findAll')
+ ->with(
+ $this->equalTo($post['id']),
+ $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']));
+
$response = $this->controller->items();
$this->assertEquals($result, $response->getParams());
$this->assertTrue($response instanceof JSONResponse);
}
- public function testItemsDoesNotReturnFeedsIfOffsetNotZero(){
+ public function testItemsOffsetNotZero(){
$result = array(
'items' => array(new Item())
);
@@ -306,7 +322,8 @@ class ItemControllerTest extends ControllerTestUtility {
'limit' => 3,
'type' => FeedType::FEED,
'id' => 2,
- 'offset' => 10
+ 'offset' => 10,
+ 'newestItemId' => 3
);
$this->controller = $this->getPostController($post);
@@ -314,8 +331,13 @@ class ItemControllerTest extends ControllerTestUtility {
$this->itemBusinessLayer->expects($this->once())
->method('findAll')
- ->with($post['id'], $post['type'], $post['limit'],
- $post['offset'], true, $this->user)
+ ->with($this->equalTo($post['id']),
+ $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']));
$this->feedBusinessLayer->expects($this->never())
@@ -326,28 +348,30 @@ class ItemControllerTest extends ControllerTestUtility {
$this->assertTrue($response instanceof JSONResponse);
}
- public function testItemsNew(){
- $result = array(
- 'items' => array(new Item())
- );
+
+ public function testGetItemsNoNewestItemsId(){
+ $result = array();
$post = array(
+ 'limit' => 3,
'type' => FeedType::FEED,
'id' => 2,
- 'updatedSince' => 3333
+ 'offset' => 0,
+ 'newestItemId' => 3
);
$this->controller = $this->getPostController($post);
$this->itemsApiExpects($post['id'], $post['type']);
-
+
$this->itemBusinessLayer->expects($this->once())
- ->method('findAllNew')
- ->with($post['id'], $post['type'], $post['updatedSince'],
- true, $this->user)
- ->will($this->returnValue($result['items']));
+ ->method('getNewestItemId')
+ ->with($this->equalTo($this->user))
+ ->will($this->throwException(new BusinessLayerException('')));
$response = $this->controller->items();
$this->assertEquals($result, $response->getParams());
- $this->assertTrue($response instanceof JSONResponse);
+ $this->assertTrue($response instanceof JSONResponse);
}
+
+
} \ No newline at end of file
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index 8619731c0..ff5bb1f4c 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -32,6 +32,13 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
private $mapper;
private $items;
+ private $newestItemId;
+ private $limit;
+ private $user;
+ private $offset;
+ private $updatedSince;
+ private $status;
+
public function setUp()
{
@@ -67,6 +74,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->id = 11;
$this->status = 333;
$this->updatedSince = 323;
+ $this->newestItemId = 2;
}
@@ -146,7 +154,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
}
public function testFindAllNew(){
- $sql = 'AND `items`.`id` >= ?';
+ $sql = 'AND `items`.`last_modified` >= ?';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
$params = array($this->user, $this->updatedSince);
@@ -158,23 +166,9 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
}
- public function testFindAllNewFeed(){
- $sql = 'AND `items`.`feed_id` = ? ' .
- 'AND `items`.`id` >= ?';
- $sql = $this->makeSelectQueryStatus($sql, $this->status);
- $params = array($this->user, $this->id, $this->updatedSince);
-
- $this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllNewFeed($this->id, $this->updatedSince,
- $this->status, $this->user);
-
- $this->assertEquals($this->items, $result);
- }
-
-
public function testFindAllNewFolder(){
$sql = 'AND `feeds`.`folder_id` = ? ' .
- 'AND `items`.`id` >= ?';
+ 'AND `items`.`last_modified` >= ?';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
$params = array($this->user, $this->id, $this->updatedSince);
@@ -186,28 +180,31 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
}
- public function testFindAllFeed(){
+ public function testFindAllNewFeed(){
$sql = 'AND `items`.`feed_id` = ? ' .
- 'AND `items`.`id` < ? ' .
- 'ORDER BY `items`.`id` DESC ';
+ 'AND `items`.`last_modified` >= ?';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
- $params = array($this->user, $this->id, $this->offset);
+ $params = array($this->user, $this->id, $this->updatedSince);
+
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllFeed($this->id, $this->limit,
- $this->offset, $this->status, $this->user);
+ $result = $this->mapper->findAllNewFeed($this->id, $this->updatedSince,
+ $this->status, $this->user);
$this->assertEquals($this->items, $result);
}
- public function testFindAllFeedOffsetZero(){
- $sql = 'AND `items`.`feed_id` = ? ' .
- 'ORDER BY `items`.`id` DESC ';
+ public function testFindAll(){
+ $sql = 'AND `items`.`id` < ? ' .
+ 'ORDER BY `items`.`pub_date` DESC, `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);
+ $params = array($this->user, $this->newestItemId);
+ $this->setMapperResult($sql, $params, $this->rows,
+ $this->limit, $this->offset);
+
+ $result = $this->mapper->findAll($this->limit,
+ $this->offset, $this->newestItemId,
+ $this->status, $this->user);
$this->assertEquals($this->items, $result);
}
@@ -216,56 +213,37 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllFolder(){
$sql = 'AND `feeds`.`folder_id` = ? ' .
'AND `items`.`id` < ? ' .
- 'ORDER BY `items`.`id` DESC ';
+ 'ORDER BY `items`.`pub_date` DESC, `items`.`id` DESC ';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
- $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);
- }
+ $params = array($this->user, $this->id, $this->newestItemId);
+ $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,
- 0, $this->status, $this->user);
+ $this->offset, $this->newestItemId, $this->status, $this->user);
$this->assertEquals($this->items, $result);
}
- public function testFindAll(){
- $sql = 'AND `items`.`id` < ? ' .
- 'ORDER BY `items`.`id` DESC ';
+ public function testFindAllFeed(){
+ $sql = 'AND `items`.`feed_id` = ? ' .
+ 'AND `items`.`id` < ? ' .
+ 'ORDER BY `items`.`pub_date` DESC, `items`.`id` DESC ';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
- $params = array($this->user, $this->offset);
- $this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAll($this->limit,
- $this->offset, $this->status, $this->user);
-
- $this->assertEquals($this->items, $result);
- }
-
+ $params = array($this->user, $this->id, $this->newestItemId);
+ $this->setMapperResult($sql, $params, $this->rows, $this->limit,
+ $this->offset);
- 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);
+ $result = $this->mapper->findAllFeed($this->id, $this->limit,
+ $this->offset, $this->newestItemId, $this->status, $this->user);
$this->assertEquals($this->items, $result);
}
+
public function testFindByGuidHash(){
$hash = md5('test');
$feedId = 3;
@@ -354,4 +332,34 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$result = $this->mapper->deleteReadOlderThanThreshold($threshold);
}
+
+ public function testGetNewestItem() {
+ $sql = 'SELECT MAX(`items`.`id`) AS `max_id` FROM `*PREFIX*news_items` `items` '.
+ 'JOIN `*PREFIX*news_feeds` `feeds` ' .
+ 'ON `feeds`.`id` = `items`.`feed_id` '.
+ 'AND `feeds`.`user_id` = ?';
+ $params = array($this->user);
+ $rows = array(array('max_id' => 3));
+
+ $this->setMapperResult($sql, $params, $rows);
+
+ $result = $this->mapper->getNewestItemId($this->user);
+ $this->assertEquals(3, $result);
+ }
+
+
+ public function testGetNewestItemIdNotFound() {
+ $sql = 'SELECT MAX(`items`.`id`) AS `max_id` FROM `*PREFIX*news_items` `items` '.
+ 'JOIN `*PREFIX*news_feeds` `feeds` ' .
+ 'ON `feeds`.`id` = `items`.`feed_id` '.
+ 'AND `feeds`.`user_id` = ?';
+ $params = array($this->user);
+ $rows = array();
+
+ $this->setMapperResult($sql, $params, $rows);
+ $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
+
+ $result = $this->mapper->getNewestItemId($this->user);
+ }
+
} \ No newline at end of file