summaryrefslogtreecommitdiffstats
path: root/tests/unit/controller/FolderApiControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/controller/FolderApiControllerTest.php')
-rw-r--r--tests/unit/controller/FolderApiControllerTest.php332
1 files changed, 166 insertions, 166 deletions
diff --git a/tests/unit/controller/FolderApiControllerTest.php b/tests/unit/controller/FolderApiControllerTest.php
index 22e038e16..c0371661a 100644
--- a/tests/unit/controller/FolderApiControllerTest.php
+++ b/tests/unit/controller/FolderApiControllerTest.php
@@ -27,209 +27,209 @@ use \OCA\News\Db\Item;
class FolderApiControllerTest extends \PHPUnit_Framework_TestCase {
- private $folderService;
- private $itemService;
- private $folderAPI;
- private $appName;
- private $user;
- private $request;
- private $msg;
-
- protected function setUp() {
- $this->appName = 'news';
- $this->user = 'tom';
- $this->request = $this->getMockBuilder(
- '\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->folderService = $this->getMockBuilder(
- '\OCA\News\Service\FolderService')
- ->disableOriginalConstructor()
- ->getMock();
- $this->itemService = $this->getMockBuilder(
- '\OCA\News\Service\ItemService')
- ->disableOriginalConstructor()
- ->getMock();
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $this->request,
- $this->folderService,
- $this->itemService,
- $this->user
- );
- $this->msg = 'test';
- }
-
-
- public function testIndex() {
- $folders = [new Folder()];
-
- $this->folderService->expects($this->once())
- ->method('findAll')
- ->with($this->equalTo($this->user))
- ->will($this->returnValue($folders));
-
- $response = $this->folderAPI->index();
-
- $this->assertEquals([
- 'folders' => [$folders[0]->toAPI()]
- ], $response);
- }
-
-
- public function testCreate() {
- $folderName = 'test';
- $folder = new Folder();
- $folder->setName($folderName);
-
- $this->folderService->expects($this->once())
- ->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
- $this->folderService->expects($this->once())
- ->method('create')
- ->with($this->equalTo($folderName), $this->equalTo($this->user))
- ->will($this->returnValue($folder));
-
- $response = $this->folderAPI->create($folderName);
-
- $this->assertEquals([
- 'folders' => [$folder->toAPI()]
- ], $response);
- }
-
+ private $folderService;
+ private $itemService;
+ private $folderAPI;
+ private $appName;
+ private $user;
+ private $request;
+ private $msg;
+
+ protected function setUp() {
+ $this->appName = 'news';
+ $this->user = 'tom';
+ $this->request = $this->getMockBuilder(
+ '\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->folderService = $this->getMockBuilder(
+ '\OCA\News\Service\FolderService')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->itemService = $this->getMockBuilder(
+ '\OCA\News\Service\ItemService')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->folderAPI = new FolderApiController(
+ $this->appName,
+ $this->request,
+ $this->folderService,
+ $this->itemService,
+ $this->user
+ );
+ $this->msg = 'test';
+ }
+
+
+ public function testIndex() {
+ $folders = [new Folder()];
+
+ $this->folderService->expects($this->once())
+ ->method('findAll')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($folders));
+
+ $response = $this->folderAPI->index();
+
+ $this->assertEquals([
+ 'folders' => [$folders[0]->toAPI()]
+ ], $response);
+ }
+
+
+ public function testCreate() {
+ $folderName = 'test';
+ $folder = new Folder();
+ $folder->setName($folderName);
+
+ $this->folderService->expects($this->once())
+ ->method('purgeDeleted')
+ ->with($this->equalTo($this->user), $this->equalTo(false));
+ $this->folderService->expects($this->once())
+ ->method('create')
+ ->with($this->equalTo($folderName), $this->equalTo($this->user))
+ ->will($this->returnValue($folder));
+
+ $response = $this->folderAPI->create($folderName);
+
+ $this->assertEquals([
+ 'folders' => [$folder->toAPI()]
+ ], $response);
+ }
+
- public function testCreateAlreadyExists() {
- $msg = 'exists';
-
- $this->folderService->expects($this->once())
- ->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
- $this->folderService->expects($this->once())
- ->method('create')
- ->will($this->throwException(new ServiceConflictException($msg)));
+ public function testCreateAlreadyExists() {
+ $msg = 'exists';
+
+ $this->folderService->expects($this->once())
+ ->method('purgeDeleted')
+ ->with($this->equalTo($this->user), $this->equalTo(false));
+ $this->folderService->expects($this->once())
+ ->method('create')
+ ->will($this->throwException(new ServiceConflictException($msg)));
- $response = $this->folderAPI->create('hi');
+ $response = $this->folderAPI->create('hi');
- $data = $response->getData();
- $this->assertEquals($msg, $data['message']);
- $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
- }
+ $data = $response->getData();
+ $this->assertEquals($msg, $data['message']);
+ $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
+ }
- public function testCreateInvalidFolderName() {
- $msg = 'exists';
+ public function testCreateInvalidFolderName() {
+ $msg = 'exists';
- $this->folderService->expects($this->once())
- ->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
- $this->folderService->expects($this->once())
- ->method('create')
- ->will($this->throwException(new ServiceValidationException($msg)));
+ $this->folderService->expects($this->once())
+ ->method('purgeDeleted')
+ ->with($this->equalTo($this->user), $this->equalTo(false));
+ $this->folderService->expects($this->once())
+ ->method('create')
+ ->will($this->throwException(new ServiceValidationException($msg)));
- $response = $this->folderAPI->create('hi');
+ $response = $this->folderAPI->create('hi');
- $data = $response->getData();
- $this->assertEquals($msg, $data['message']);
- $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
- }
+ $data = $response->getData();
+ $this->assertEquals($msg, $data['message']);
+ $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
+ }
- public function testDelete() {
- $folderId = 23;
- $this->folderService->expects($this->once())
- ->method('delete')
- ->with($this->equalTo($folderId), $this->equalTo($this->user));
+ public function testDelete() {
+ $folderId = 23;
+ $this->folderService->expects($this->once())
+ ->method('delete')
+ ->with($this->equalTo($folderId), $this->equalTo($this->user));
- $this->folderAPI->delete(23);
- }
+ $this->folderAPI->delete(23);
+ }
- public function testDeleteDoesNotExist() {
- $folderId = 23;
+ public function testDeleteDoesNotExist() {
+ $folderId = 23;
- $this->folderService->expects($this->once())
- ->method('delete')
- ->will($this->throwException(new ServiceNotFoundException($this->msg)));
+ $this->folderService->expects($this->once())
+ ->method('delete')
+ ->will($this->throwException(new ServiceNotFoundException($this->msg)));
- $response = $this->folderAPI->delete($folderId);
+ $response = $this->folderAPI->delete($folderId);
- $data = $response->getData();
- $this->assertEquals($this->msg, $data['message']);
- $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
- }
+ $data = $response->getData();
+ $this->assertEquals($this->msg, $data['message']);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+ }
- public function testUpdate() {
- $folderId = 23;
- $folderName = 'test';
+ public function testUpdate() {
+ $folderId = 23;
+ $folderName = 'test';
- $this->folderService->expects($this->once())
- ->method('rename')
- ->with($this->equalTo($folderId),
- $this->equalTo($folderName),
- $this->equalTo($this->user));
+ $this->folderService->expects($this->once())
+ ->method('rename')
+ ->with($this->equalTo($folderId),
+ $this->equalTo($folderName),
+ $this->equalTo($this->user));
- $this->folderAPI->update($folderId, $folderName);
- }
+ $this->folderAPI->update($folderId, $folderName);
+ }
- public function testUpdateDoesNotExist() {
- $folderId = 23;
- $folderName = 'test';
+ public function testUpdateDoesNotExist() {
+ $folderId = 23;
+ $folderName = 'test';
- $this->folderService->expects($this->once())
- ->method('rename')
- ->will($this->throwException(new ServiceNotFoundException($this->msg)));
+ $this->folderService->expects($this->once())
+ ->method('rename')
+ ->will($this->throwException(new ServiceNotFoundException($this->msg)));
- $response = $this->folderAPI->update($folderId, $folderName);
+ $response = $this->folderAPI->update($folderId, $folderName);
- $data = $response->getData();
- $this->assertEquals($this->msg, $data['message']);
- $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
- }
+ $data = $response->getData();
+ $this->assertEquals($this->msg, $data['message']);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+ }
- public function testUpdateExists() {
- $folderId = 23;
- $folderName = 'test';
+ public function testUpdateExists() {
+ $folderId = 23;
+ $folderName = 'test';
- $this->folderService->expects($this->once())
- ->method('rename')
- ->will($this->throwException(new ServiceConflictException($this->msg)));
+ $this->folderService->expects($this->once())
+ ->method('rename')
+ ->will($this->throwException(new ServiceConflictException($this->msg)));
- $response = $this->folderAPI->update($folderId, $folderName);
+ $response = $this->folderAPI->update($folderId, $folderName);
- $data = $response->getData();
- $this->assertEquals($this->msg, $data['message']);
- $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
- }
+ $data = $response->getData();
+ $this->assertEquals($this->msg, $data['message']);
+ $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
+ }
- public function testUpdateInvalidFolderName() {
- $folderId = 23;
- $folderName = '';
+ public function testUpdateInvalidFolderName() {
+ $folderId = 23;
+ $folderName = '';
- $this->folderService->expects($this->once())
- ->method('rename')
- ->will($this->throwException(new ServiceValidationException($this->msg)));
+ $this->folderService->expects($this->once())
+ ->method('rename')
+ ->will($this->throwException(new ServiceValidationException($this->msg)));
- $response = $this->folderAPI->update($folderId, $folderName);
+ $response = $this->folderAPI->update($folderId, $folderName);
- $data = $response->getData();
- $this->assertEquals($this->msg, $data['message']);
- $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
- }
+ $data = $response->getData();
+ $this->assertEquals($this->msg, $data['message']);
+ $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
+ }
- public function testRead() {
- $this->itemService->expects($this->once())
- ->method('readFolder')
- ->with(
- $this->equalTo(3),
- $this->equalTo(30),
- $this->equalTo($this->user));
+ public function testRead() {
+ $this->itemService->expects($this->once())
+ ->method('readFolder')
+ ->with(
+ $this->equalTo(3),
+ $this->equalTo(30),
+ $this->equalTo($this->user));
- $this->folderAPI->read(3, 30);
- }
+ $this->folderAPI->read(3, 30);
+ }
}