summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-04 13:12:07 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-04 13:12:07 +0200
commit4b994c97ad878cc3886ffbea1a6a2bf6b4a98def (patch)
tree85d464146ad809a68372abed3a4026578d4006ad /tests
parent312796b1ca251567159368dddcaed1a3f0ddafc0 (diff)
autopurge all read items which are not starred if there are more than 1000
Diffstat (limited to 'tests')
-rw-r--r--tests/bl/FeedBlTest.php37
-rw-r--r--tests/db/FeedMapperTest.php26
2 files changed, 55 insertions, 8 deletions
diff --git a/tests/bl/FeedBlTest.php b/tests/bl/FeedBlTest.php
index 818562fb9..5ad02e789 100644
--- a/tests/bl/FeedBlTest.php
+++ b/tests/bl/FeedBlTest.php
@@ -41,15 +41,16 @@ use \OCA\News\Utility\FetcherException;
class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
- protected $api;
- protected $mapper;
- protected $bl;
- protected $user;
- protected $response;
- protected $fetcher;
- protected $itemMapper;
+ private $mapper;
+ private $bl;
+ private $user;
+ private $response;
+ private $fetcher;
+ private $itemMapper;
+ private $threshold;
protected function setUp(){
+ $this->threshold = 2;
$this->api = $this->getAPIMock();
$this->mapper = $this->getMockBuilder('\OCA\News\Db\FeedMapper')
->disableOriginalConstructor()
@@ -61,9 +62,11 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
->disableOriginalConstructor()
->getMock();
$this->bl = new FeedBl($this->mapper,
- $this->fetcher, $this->itemMapper, $this->api);
+ $this->fetcher, $this->itemMapper, $this->api,
+ $this->threshold);
$this->user = 'jack';
$response = 'hi';
+
}
@@ -302,6 +305,24 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
}
+ public function testAutoPurgeOldWillPurgeOld(){
+ $feed = new Feed();
+ $feed->setId(3);
+ $unread = array(
+ new Feed(), $feed
+ );
+ $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($feed->getId()));
+
+ $result = $this->bl->autoPurgeOld();
+
+ }
+
}
} \ No newline at end of file
diff --git a/tests/db/FeedMapperTest.php b/tests/db/FeedMapperTest.php
index 11afbbe7f..de414d9c8 100644
--- a/tests/db/FeedMapperTest.php
+++ b/tests/db/FeedMapperTest.php
@@ -249,4 +249,30 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
}
+ public function testGetReadOlderThanThreshold(){
+ $status = StatusFlag::STARRED | StatusFlag::UNREAD;
+ $sql = 'SELECT * FROM `*PREFIX*news_items` ' .
+ 'WHERE NOT ((`status` & ?) > 0)';
+ $threshold = 10;
+ $feed = new Feed();
+ $feed->setId(30);
+ $rows = array(array('id' => 30));
+ $params = array($status);
+
+ $this->setMapperResult($sql, $params, $rows);
+ $result = $this->mapper->getReadOlderThanThreshold($threshold);
+
+ $this->assertEquals($feed->getId(), $result[0]->getId());
+ }
+
+
+ public function testDeleteReadOlderThanId(){
+ $id = 10;
+ $sql = 'DELETE FROM `*PREFIX*news_items` WHERE `id` < ?';
+ $params = array($id);
+
+ $this->setMapperResult($sql, $params);
+ $this->mapper->deleteReadOlderThanId($id);
+ }
+
} \ No newline at end of file