summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-20 15:09:15 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-20 15:09:15 +0200
commit381f8efd1096001f34810414c1054a00a64179c8 (patch)
treea8bd92117dfd7352bfae3e06cacf57287312036a /tests
parent4d4a27969705b8ff14c139795228d2f05e017b87 (diff)
set autopurge limit to 200 and purge per feed rather than per user or per all items, fix #98
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/businesslayer/ItemBusinessLayerTest.php13
-rw-r--r--tests/unit/db/ItemMapperTest.php81
2 files changed, 66 insertions, 28 deletions
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php
index 9bff8acfc..e3ae280a6 100644
--- a/tests/unit/businesslayer/ItemBusinessLayerTest.php
+++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php
@@ -249,18 +249,9 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
public function testAutoPurgeOldWillPurgeOld(){
- $item = new Item();
- $item->setId(3);
- $unread = array(
- new Item(), $item
- );
- $this->mapper->expects($this->once())
- ->method('getReadOlderThanThreshold')
- ->with($this->equalTo($this->threshold))
- ->will($this->returnValue($unread));
$this->mapper->expects($this->once())
- ->method('deleteReadOlderThanId')
- ->with($this->equalTo($item->getId()));
+ ->method('deleteReadOlderThanThreshold')
+ ->with($this->equalTo($this->threshold));
$result = $this->itemBusinessLayer->autoPurgeOld();
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index ed47f175c..f46533c58 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -280,31 +280,78 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
}
- public function testGetReadOlderThanThreshold(){
+ public function testDeleteReadOlderThanThresholdDoesNotDeleteBelowThreshold(){
$status = StatusFlag::STARRED | StatusFlag::UNREAD;
- $sql = 'SELECT * FROM `*PREFIX*news_items` ' .
- 'WHERE NOT ((`status` & ?) > 0)';
+ $sql = 'SELECT COUNT(*) `size`, `feed_id` ' .
+ 'FROM `*PREFIX*news_items` ' .
+ 'AND NOT ((`status` & ?) > 0) ' .
+ 'GROUP BY `feed_id` ' .
+ 'HAVING COUNT(*) > ?';
+
$threshold = 10;
- $feed = new Feed();
- $feed->setId(30);
- $rows = array(array('id' => 30));
- $params = array($status);
+ $rows = array(array('feed_id' => 30, 'size' => 11));
+ $params = array($status, $threshold);
$this->setMapperResult($sql, $params, $rows);
- $result = $this->mapper->getReadOlderThanThreshold($threshold);
-
- $this->assertEquals($feed->getId(), $result[0]->getId());
+ $this->mapper->deleteReadOlderThanThreshold($threshold);
}
- public function testDeleteReadOlderThanId(){
- $id = 10;
+ public function testDeleteReadOlderThanThreshold(){
+ $threshold = 10;
$status = StatusFlag::STARRED | StatusFlag::UNREAD;
- $sql = 'DELETE FROM `*PREFIX*news_items` WHERE `id` < ? ' .
- 'AND NOT ((`status` & ?) > 0)';
- $params = array($id, $status);
- $this->setMapperResult($sql, $params);
- $this->mapper->deleteReadOlderThanId($id);
+ $sql1 = 'SELECT COUNT(*) `size`, `feed_id` ' .
+ 'FROM `*PREFIX*news_items` ' .
+ 'AND NOT ((`status` & ?) > 0) ' .
+ 'GROUP BY `feed_id` ' .
+ 'HAVING COUNT(*) > ?';
+ $params1 = array($status, $threshold);
+
+
+ $row = array('feed_id' => 30, 'size' => 9);
+
+ $sql2 = 'DELETE FROM `*PREFIX*news_items` `items` ' .
+ 'WHERE NOT ((`status` & ?) > 0) ' .
+ 'AND `feed_id` = ? ' .
+ 'ORDER BY `items`.`id` ASC';
+ $params2 = array($status, 30);
+
+
+ $pdoResult = $this->getMock('Result',
+ array('fetchRow'));
+
+ $pdoResult->expects($this->at(0))
+ ->method('fetchRow')
+ ->will($this->returnValue($row));
+ $pdoResult->expects($this->at(1))
+ ->method('fetchRow')
+ ->will($this->returnValue(false));
+
+ $query = $this->getMock('Query',
+ array('execute'));
+ $query->expects($this->at(0))
+ ->method('execute')
+ ->with($this->equalTo($params1))
+ ->will($this->returnValue($pdoResult));
+
+ $this->api->expects($this->at(0))
+ ->method('prepareQuery')
+ ->with($this->equalTo($sql1))
+ ->will(($this->returnValue($query)));
+
+ $query2 = $this->getMock('Query',
+ array('execute'));
+ $query2->expects($this->at(0))
+ ->method('execute')
+ ->with($this->equalTo($params2));
+
+ $this->api->expects($this->at(1))
+ ->method('prepareQuery')
+ ->with($this->equalTo($sql2))
+ ->will(($this->returnValue($query2)));
+
+ $result = $this->mapper->deleteReadOlderThanThreshold($threshold);
}
+
} \ No newline at end of file