From 4b994c97ad878cc3886ffbea1a6a2bf6b4a98def Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 4 Apr 2013 13:12:07 +0200 Subject: autopurge all read items which are not starred if there are more than 1000 --- tests/bl/FeedBlTest.php | 37 +++++++++++++++++++++++++++++-------- tests/db/FeedMapperTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 8 deletions(-) (limited to 'tests') 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 -- cgit v1.2.3