diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-09 12:57:35 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-09 12:57:35 +0200 |
commit | b8b4dfb4969e1baf84a14fb65a5dc153b0f5fae4 (patch) | |
tree | 27e211e26f442efd72a7f34903953ad57b1a9b76 /tests/unit/external | |
parent | fe0de2ab84a88cb4c742f4f10fd43716934b7282 (diff) |
only make one request for mark all read and mark folder read, fix #171, fix a bug that prevented readding of feeds when its folder was deleted, fix a bug that would not allow mark read for feeds when the app was started for the first time
Diffstat (limited to 'tests/unit/external')
-rw-r--r-- | tests/unit/external/FolderAPITest.php | 86 | ||||
-rw-r--r-- | tests/unit/external/ItemAPITest.php | 28 |
2 files changed, 83 insertions, 31 deletions
diff --git a/tests/unit/external/FolderAPITest.php b/tests/unit/external/FolderAPITest.php index 8b7a7b797..654a4fbae 100644 --- a/tests/unit/external/FolderAPITest.php +++ b/tests/unit/external/FolderAPITest.php @@ -40,6 +40,7 @@ require_once(__DIR__ . "/../../classloader.php"); class FolderAPITest extends \PHPUnit_Framework_TestCase { private $folderBusinessLayer; + private $itemBusinessLayer; private $folderAPI; private $api; private $user; @@ -59,13 +60,21 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { '\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); + $this->itemBusinessLayer = $this->getMockBuilder( + '\OCA\News\BusinessLayer\ItemBusinessLayer') + ->disableOriginalConstructor() + ->getMock(); $this->folderAPI = new FolderAPI( $this->api, $this->request, - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); $this->user = 'tom'; $this->msg = 'test'; + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); } @@ -74,9 +83,6 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { new Folder() ); - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) @@ -102,12 +108,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { new Request(array('params' => array( 'name' => $folderName ))), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $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)) @@ -123,9 +127,6 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { 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))); @@ -146,12 +147,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { new Request(array('urlParams' => array( 'folderId' => $folderId ))), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $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)); @@ -170,12 +169,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { new Request(array('urlParams' => array( 'folderId' => $folderId ))), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $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))); @@ -205,12 +202,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { ) ) ), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('rename') ->with($this->equalTo($folderId), @@ -241,12 +236,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { ) ) ), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $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))); @@ -276,12 +269,10 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { ) ) ), - $this->folderBusinessLayer + $this->folderBusinessLayer, + $this->itemBusinessLayer ); - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('rename') ->will($this->throwException(new BusinessLayerExistsException($this->msg))); @@ -293,4 +284,37 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase { $this->assertEquals(NewsAPIResult::EXISTS_ERROR, $response->getStatusCode()); } + + public function testRead() { + $request = new Request(array( + 'urlParams' => array( + 'folderId' => 3 + ), + 'params' => array( + 'newestItemId' => 30, + ) + )); + $this->folderAPI = new FolderAPI( + $this->api, + $request, + $this->folderBusinessLayer, + $this->itemBusinessLayer + ); + + + $this->itemBusinessLayer->expects($this->once()) + ->method('readFolder') + ->with( + $this->equalTo(3), + $this->equalTo(30), + $this->equalTo($this->user)); + + $response = $this->folderAPI->read(); + + $this->assertNull($response->getData()); + $this->assertNull($response->getMessage()); + $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode()); + } + + }
\ No newline at end of file diff --git a/tests/unit/external/ItemAPITest.php b/tests/unit/external/ItemAPITest.php index a6cd96018..94c91eea0 100644 --- a/tests/unit/external/ItemAPITest.php +++ b/tests/unit/external/ItemAPITest.php @@ -336,4 +336,32 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase { $this->assertEquals(NewsAPIResult::NOT_FOUND_ERROR, $response->getStatusCode()); } + + public function testReadAll() { + $request = new Request(array( + 'params' => array( + 'newestItemId' => 30, + ) + )); + $this->itemAPI = new ItemAPI( + $this->api, + $request, + $this->itemBusinessLayer + ); + + + $this->itemBusinessLayer->expects($this->once()) + ->method('readAll') + ->with( + $this->equalTo(30), + $this->equalTo($this->user)); + + $response = $this->itemAPI->readAll(); + + $this->assertNull($response->getData()); + $this->assertNull($response->getMessage()); + $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode()); + } + + }
\ No newline at end of file |