diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 20:42:39 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 20:42:39 +0200 |
commit | 20d4c2911fa39454b5c0cc9811b15a45d1fdfd2a (patch) | |
tree | 83854dfa7940d7f4ed5022cbb61a119e84e656ff /tests/unit | |
parent | 61299d72050db23b62b96e0ea22cf54a515631f4 (diff) |
implemented folder api methods
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/external/FolderAPITest.php | 170 | ||||
-rw-r--r-- | tests/unit/external/NewsAPIResultTest.php | 13 |
2 files changed, 181 insertions, 2 deletions
diff --git a/tests/unit/external/FolderAPITest.php b/tests/unit/external/FolderAPITest.php index 1ab8bbc1c..ef78d3dd8 100644 --- a/tests/unit/external/FolderAPITest.php +++ b/tests/unit/external/FolderAPITest.php @@ -25,7 +25,10 @@ namespace OCA\News\External; +use \OCA\AppFramework\Http\Request; + use \OCA\News\BusinessLayer\BusinessLayerException; +use \OCA\News\BusinessLayer\BusinessLayerExistsException; use \OCA\News\Db\Folder; use \OCA\News\Db\Feed; @@ -41,6 +44,7 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { private $api; private $user; private $request; + private $msg; protected function setUp() { $this->api = $this->getMockBuilder( @@ -61,6 +65,7 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { $this->folderBusinessLayer ); $this->user = 'tom'; + $this->msg = 'test'; } @@ -85,5 +90,170 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { } + public function testCreate() { + $folderName = 'test'; + $folder = new Folder(); + $folder->setName($folderName); + $folders = array( + $folder + ); + $this->folderAPI = new FolderAPI( + $this->api, + new Request(array('params' => array( + 'name' => $folderName + ))), + $this->folderBusinessLayer + ); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('create') + ->with($this->equalTo($folderName), $this->equalTo($this->user)) + ->will($this->returnValue($folder)); + + $response = $this->folderAPI->create(); + + $this->assertEquals(array( + 'folders' => array($folders[0]->toAPI()) + ), $response->getData()); + } + + + public function testCreateAlreadyExists() { + $msg = 'exists'; + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('create') + ->will($this->throwException(new BusinessLayerExistsException($msg))); + + $response = $this->folderAPI->create(); + + $this->assertNull($response->getData()); + $this->assertEquals(NewsAPIResult::EXISTS_ERROR, $response->getStatusCode()); + $this->assertEquals($msg, $response->getMessage()); + } + + + public function testDelete() { + $folderId = 23; + + $this->folderAPI = new FolderAPI( + $this->api, + new Request(array('urlParams' => array( + 'folderId' => $folderId + ))), + $this->folderBusinessLayer + ); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('delete') + ->with($this->equalTo($folderId), $this->equalTo($this->user)); + + $response = $this->folderAPI->delete(); + + $this->assertNull($response->getData()); + } + + + public function testDeleteDoesNotExist() { + $folderId = 23; + + $this->folderAPI = new FolderAPI( + $this->api, + new Request(array('urlParams' => array( + 'folderId' => $folderId + ))), + $this->folderBusinessLayer + ); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('delete') + ->will($this->throwException(new BusinessLayerException($this->msg))); + + $response = $this->folderAPI->delete(); + + $this->assertNull($response->getData()); + $this->assertEquals($this->msg, $response->getMessage()); + $this->assertEquals(NewsAPIResult::NOT_FOUND, $response->getStatusCode()); + } + + + public function testUpdate() { + $folderId = 23; + $folderName = 'test'; + + $this->folderAPI = new FolderAPI( + $this->api, + new Request( + array( + 'urlParams' => array( + 'folderId' => $folderId + ), + + 'params' => array( + 'name' => $folderName + ) + ) + ), + $this->folderBusinessLayer + ); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('rename') + ->with($this->equalTo($folderId), + $this->equalTo($folderName), + $this->equalTo($this->user)); + + $response = $this->folderAPI->update(); + + $this->assertNull($response->getData()); + $this->assertNull($response->getMessage()); + $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode()); + } + + + public function testUpdateDoesNotExist() { + $folderId = 23; + $folderName = 'test'; + + $this->folderAPI = new FolderAPI( + $this->api, + new Request( + array('urlParams' => array( + 'folderId' => $folderId + ), + array('params' => array( + 'name' => $folderName + )) + )), + $this->folderBusinessLayer + ); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('rename') + ->will($this->throwException(new BusinessLayerException($this->msg))); + + $response = $this->folderAPI->update(); + + $this->assertNull($response->getData()); + $this->assertEquals($this->msg, $response->getMessage()); + $this->assertEquals(NewsAPIResult::NOT_FOUND, $response->getStatusCode()); + } }
\ No newline at end of file diff --git a/tests/unit/external/NewsAPIResultTest.php b/tests/unit/external/NewsAPIResultTest.php index 426198183..6d0e41669 100644 --- a/tests/unit/external/NewsAPIResultTest.php +++ b/tests/unit/external/NewsAPIResultTest.php @@ -32,9 +32,18 @@ class NewsAPIResultTest extends \PHPUnit_Framework_TestCase { public function testExistsError(){ - $result = new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR); + $result = new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR, 'hi'); $this->assertEquals(409, $result->getStatusCode()); + $this->assertEquals('hi', $result->getMessage()); } -}
\ No newline at end of file + public function testNoInput(){ + $result = new NewsAPIResult(); + $this->assertNull($result->getData()); + $this->assertEquals(100, $result->getStatusCode()); + $this->assertNull($result->getMessage()); + } + + +} |