From 7375daf213b09b6cfb8ee7e3ec6ce7b53db1b100 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 27 Oct 2014 10:39:51 +0100 Subject: allow to turn of autopurge --- tests/unit/service/ItemServiceTest.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/unit/service/ItemServiceTest.php b/tests/unit/service/ItemServiceTest.php index 4f5672e20..1b6eb6c00 100644 --- a/tests/unit/service/ItemServiceTest.php +++ b/tests/unit/service/ItemServiceTest.php @@ -29,34 +29,31 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { private $status; private $time; private $newestItemId; + private $config; protected function setUp(){ $this->time = 222; - $timeFactory = $this->getMock('TimeFactory', ['getTime']); - $timeFactory->expects($this->any()) + $this->timeFactory = $this->getMock('TimeFactory', ['getTime']); + $this->timeFactory->expects($this->any()) ->method('getTime') ->will($this->returnValue($this->time)); $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); - $statusFlag = $this->getMockBuilder('\OCA\News\Db\StatusFlag') + $this->statusFlag = $this->getMockBuilder('\OCA\News\Db\StatusFlag') ->disableOriginalConstructor() ->getMock(); $this->status = StatusFlag::STARRED; - $statusFlag->expects($this->any()) + $this->statusFlag->expects($this->any()) ->method('typeToStatus') ->will($this->returnValue($this->status)); - $this->threshold = 2; - $config = $this->getMockBuilder( + $this->config = $this->getMockBuilder( '\OCA\News\Config\Config') ->disableOriginalConstructor() ->getMock(); - $config->expects($this->any()) - ->method('getAutoPurgeCount') - ->will($this->returnValue($this->threshold)); $this->itemService = new ItemService($this->mapper, - $statusFlag, $timeFactory, $config); + $this->statusFlag, $this->timeFactory, $this->config); $this->user = 'jack'; $this->id = 3; $this->updatedSince = 20333; @@ -356,9 +353,22 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { public function testAutoPurgeOldWillPurgeOld(){ + $this->config->expects($this->once()) + ->method('getAutoPurgeCount') + ->will($this->returnValue(2)); $this->mapper->expects($this->once()) ->method('deleteReadOlderThanThreshold') - ->with($this->equalTo($this->threshold)); + ->with($this->equalTo(2)); + + $this->itemService->autoPurgeOld(); + } + + public function testAutoPurgeOldWontPurgeOld(){ + $this->config->expects($this->once()) + ->method('getAutoPurgeCount') + ->will($this->returnValue(-1)); + $this->mapper->expects($this->never()) + ->method('deleteReadOlderThanThreshold'); $this->itemService->autoPurgeOld(); } -- cgit v1.2.3