From 031ba0ce524f35c70b776173917ae4ce3819951e Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 21 May 2013 21:10:45 +0200 Subject: When creating a feed or folder the it should purge the deleted Edit fix #176 --- tests/unit/businesslayer/FeedBusinessLayerTest.php | 20 ++++++++++++++++++++ .../unit/businesslayer/FolderBusinessLayerTest.php | 21 +++++++++++++++++++++ tests/unit/controller/FeedControllerTest.php | 6 +++--- tests/unit/controller/FolderControllerTest.php | 4 ++-- tests/unit/db/FeedMapperTest.php | 16 +++++++++++++++- tests/unit/db/FolderMapperTest.php | 17 ++++++++++++++++- tests/unit/external/FeedAPITest.php | 6 +++--- tests/unit/external/FolderAPITest.php | 4 ++-- 8 files changed, 82 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 882106693..9f8683d9b 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -740,4 +740,24 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { } + public function testPurgeDeletedWithoutInterval(){ + $feed1 = new Feed(); + $feed1->setId(3); + $feed2 = new Feed(); + $feed2->setId(5); + $feeds = array($feed1, $feed2); + + $this->feedMapper->expects($this->once()) + ->method('getToDelete') + ->with($this->equalTo(null), $this->equalTo($this->user)) + ->will($this->returnValue($feeds)); + $this->feedMapper->expects($this->at(1)) + ->method('delete') + ->with($this->equalTo($feed1)); + $this->feedMapper->expects($this->at(2)) + ->method('delete') + ->with($this->equalTo($feed2)); + + $this->feedBusinessLayer->purgeDeleted($this->user, false); + } } diff --git a/tests/unit/businesslayer/FolderBusinessLayerTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php index 1e26f0226..35886b626 100644 --- a/tests/unit/businesslayer/FolderBusinessLayerTest.php +++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php @@ -232,4 +232,25 @@ class FolderBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->folderBusinessLayer->purgeDeleted($this->user); } + + public function testPurgeDeletedNoInterval(){ + $folder1 = new Folder(); + $folder1->setId(3); + $folder2 = new Folder(); + $folder2->setId(5); + $feeds = array($folder1, $folder2); + + $this->folderMapper->expects($this->once()) + ->method('getToDelete') + ->with($this->equalTo(null), $this->equalTo($this->user)) + ->will($this->returnValue($feeds)); + $this->folderMapper->expects($this->at(1)) + ->method('delete') + ->with($this->equalTo($folder1)); + $this->folderMapper->expects($this->at(2)) + ->method('delete') + ->with($this->equalTo($folder2)); + + $this->folderBusinessLayer->purgeDeleted($this->user, false); + } } diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index 841ba5ea2..370158822 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -318,7 +318,7 @@ class FeedControllerTest extends ControllerTestUtility { ->will($this->returnValue($result['newestItemId'])); $this->feedBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->feedBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($post['url']), @@ -349,7 +349,7 @@ class FeedControllerTest extends ControllerTestUtility { ->will($this->returnValue($this->user)); $this->feedBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->itemBusinessLayer->expects($this->once()) ->method('getNewestItemId') @@ -377,7 +377,7 @@ class FeedControllerTest extends ControllerTestUtility { ->will($this->returnValue($this->user)); $this->feedBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->feedBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException($ex)); diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index 64df7dc16..ff1a16a13 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -240,7 +240,7 @@ class FolderControllerTest extends ControllerTestUtility { ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->folderBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($post['folderName']), @@ -262,7 +262,7 @@ class FolderControllerTest extends ControllerTestUtility { ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->folderBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException($ex)); diff --git a/tests/unit/db/FeedMapperTest.php b/tests/unit/db/FeedMapperTest.php index 6894e16d0..460156e5c 100644 --- a/tests/unit/db/FeedMapperTest.php +++ b/tests/unit/db/FeedMapperTest.php @@ -289,7 +289,7 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { $deleteOlderThan = 110; $sql = 'SELECT * FROM `*PREFIX*news_feeds` ' . 'WHERE `deleted_at` > 0 ' . - 'AND `deleted_at` < ?'; + 'AND `deleted_at` < ? '; $this->setMapperResult($sql, array($deleteOlderThan), $rows); $result = $this->mapper->getToDelete($deleteOlderThan); @@ -314,4 +314,18 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { } + public function testGetAllPurgeDeletedFromUser(){ + $rows = array( + array('id' => $this->feeds[0]->getId()), + array('id' => $this->feeds[1]->getId()) + ); + $deleteOlderThan = 110; + $sql = 'SELECT * FROM `*PREFIX*news_feeds` ' . + 'WHERE `deleted_at` > 0 ' . + 'AND `user_id` = ?'; + $this->setMapperResult($sql, array($this->user), $rows); + $result = $this->mapper->getToDelete(null, $this->user); + + $this->assertEquals($this->feeds, $result); + } } diff --git a/tests/unit/db/FolderMapperTest.php b/tests/unit/db/FolderMapperTest.php index 87726b893..d31a014a6 100644 --- a/tests/unit/db/FolderMapperTest.php +++ b/tests/unit/db/FolderMapperTest.php @@ -187,7 +187,7 @@ class FolderMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { $deleteOlderThan = 110; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . 'WHERE `deleted_at` > 0 ' . - 'AND `deleted_at` < ?'; + 'AND `deleted_at` < ? '; $this->setMapperResult($sql, array($deleteOlderThan), $rows); $result = $this->folderMapper->getToDelete($deleteOlderThan); @@ -213,4 +213,19 @@ class FolderMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { } + public function testGetAllPurgeDeletedUser(){ + $rows = array( + array('id' => $this->folders[0]->getId()), + array('id' => $this->folders[1]->getId()) + ); + $deleteOlderThan = 110; + $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . + 'WHERE `deleted_at` > 0 ' . + 'AND `user_id` = ?'; + $this->setMapperResult($sql, array($this->user), $rows); + $result = $this->folderMapper->getToDelete(null, $this->user); + + $this->assertEquals($this->folders, $result); + } + } \ No newline at end of file diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php index c6d8247f5..cdc04bf0c 100644 --- a/tests/unit/external/FeedAPITest.php +++ b/tests/unit/external/FeedAPITest.php @@ -211,7 +211,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase { $this->feedBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->feedBusinessLayer->expects($this->once()) ->method('create') ->with( @@ -253,7 +253,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase { $this->feedBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->feedBusinessLayer->expects($this->once()) ->method('create') ->with( @@ -280,7 +280,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase { public function testCreateExists() { $this->feedBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->feedBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException(new BusinessLayerExistsException($this->msg))); diff --git a/tests/unit/external/FolderAPITest.php b/tests/unit/external/FolderAPITest.php index aaae2d084..1ae4bd081 100644 --- a/tests/unit/external/FolderAPITest.php +++ b/tests/unit/external/FolderAPITest.php @@ -114,7 +114,7 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { $this->folderBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->folderBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($folderName), $this->equalTo($this->user)) @@ -132,7 +132,7 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { $msg = 'exists'; $this->folderBusinessLayer->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user)); + ->with($this->equalTo($this->user), $this->equalTo(false)); $this->folderBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException(new BusinessLayerExistsException($msg))); -- cgit v1.2.3