From 347000cc2d5597c1971942ebdbe97461c9fa5802 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 10 May 2013 13:30:00 +0200 Subject: use a deleted flag for deleted feeds to handle undo --- tests/unit/controller/FeedControllerTest.php | 63 ++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'tests/unit/controller/FeedControllerTest.php') diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index c89d432d6..841ba5ea2 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -111,6 +111,11 @@ class FeedControllerTest extends ControllerTestUtility { } + public function testRestoreAnnotations(){ + $this->assertFeedControllerAnnotations('restore'); + } + + public function testUpdateAnnotations(){ $this->assertFeedControllerAnnotations('update'); } @@ -311,7 +316,9 @@ class FeedControllerTest extends ControllerTestUtility { $this->itemBusinessLayer->expects($this->once()) ->method('getNewestItemId') ->will($this->returnValue($result['newestItemId'])); - + $this->feedBusinessLayer->expects($this->once()) + ->method('purgeDeleted') + ->with($this->equalTo($this->user)); $this->feedBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($post['url']), @@ -340,6 +347,9 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('purgeDeleted') + ->with($this->equalTo($this->user)); $this->itemBusinessLayer->expects($this->once()) ->method('getNewestItemId') @@ -362,6 +372,12 @@ class FeedControllerTest extends ControllerTestUtility { public function testCreateReturnsErrorForInvalidCreate(){ $msg = 'except'; $ex = new BusinessLayerException($msg); + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('purgeDeleted') + ->with($this->equalTo($this->user)); $this->feedBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -385,7 +401,7 @@ class FeedControllerTest extends ControllerTestUtility { ->method('getUserId') ->will($this->returnValue($this->user)); $this->feedBusinessLayer->expects($this->once()) - ->method('delete') + ->method('markDeleted') ->with($this->equalTo($url['feedId'])); $response = $this->controller->delete(); @@ -404,7 +420,7 @@ class FeedControllerTest extends ControllerTestUtility { ->method('getUserId') ->will($this->returnValue($this->user)); $this->feedBusinessLayer->expects($this->once()) - ->method('delete') + ->method('markDeleted') ->will($this->throwException(new BusinessLayerException($msg))); $response = $this->controller->delete(); @@ -583,4 +599,45 @@ class FeedControllerTest extends ControllerTestUtility { $this->assertEquals($expected, $response->getParams()); } + + public function testRestore() { + $url = array( + 'feedId' => 4 + ); + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('unmarkDeleted') + ->with($this->equalTo($url['feedId'])); + + $response = $this->controller->restore(); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testRestoreDoesNotExist(){ + $url = array( + 'feedId' => 4 + ); + $msg = 'hehe'; + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('unmarkDeleted') + ->will($this->throwException(new BusinessLayerException($msg))); + + $response = $this->controller->restore(); + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + } \ No newline at end of file -- cgit v1.2.3