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.php191
1 files changed, 14 insertions, 177 deletions
diff --git a/tests/unit/controller/FolderApiControllerTest.php b/tests/unit/controller/FolderApiControllerTest.php
index aa134f58e..cf23984ce 100644
--- a/tests/unit/controller/FolderApiControllerTest.php
+++ b/tests/unit/controller/FolderApiControllerTest.php
@@ -13,11 +13,9 @@
namespace OCA\News\Controller;
-use \OCP\IRequest;
use \OCP\AppFramework\Http;
use \OCP\AppFramework\Http\JSONResponse;
-use \OCA\News\Utility\ControllerTestUtility;
use \OCA\News\BusinessLayer\BusinessLayerException;
use \OCA\News\BusinessLayer\BusinessLayerConflictException;
use \OCA\News\BusinessLayer\BusinessLayerValidationException;
@@ -29,7 +27,7 @@ use \OCA\News\Db\Item;
require_once(__DIR__ . "/../../classloader.php");
-class FolderApiControllerTest extends ControllerTestUtility {
+class FolderApiControllerTest extends \PHPUnit_Framework_TestCase {
private $folderBusinessLayer;
private $itemBusinessLayer;
@@ -65,37 +63,6 @@ class FolderApiControllerTest extends ControllerTestUtility {
}
- private function assertDefaultAnnotations($methodName){
- $annotations = array('NoAdminRequired', 'NoCSRFRequired', 'API');
- $this->assertAnnotations($this->folderAPI, $methodName, $annotations);
- }
-
-
- public function testIndexAnnotations(){
- $this->assertDefaultAnnotations('index');
- }
-
-
- public function testCreateAnnotations(){
- $this->assertDefaultAnnotations('create');
- }
-
-
- public function testDeleteAnnotations(){
- $this->assertDefaultAnnotations('delete');
- }
-
-
- public function testUpdateAnnotations(){
- $this->assertDefaultAnnotations('update');
- }
-
-
- public function testReadAnnotations(){
- $this->assertDefaultAnnotations('read');
- }
-
-
public function testIndex() {
$folders = array(
new Folder()
@@ -108,9 +75,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
$response = $this->folderAPI->index();
- $this->assertEquals(array(
- 'folders' => array($folders[0]->toAPI())
- ), $response->getData());
+ $this->assertEquals($folders, $response);
}
@@ -121,16 +86,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
$folders = array(
$folder
);
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $this->getRequest(array('params' => array(
- 'name' => $folderName
- ))),
- $this->folderBusinessLayer,
- $this->itemBusinessLayer,
- $this->user
- );
-
+
$this->folderBusinessLayer->expects($this->once())
->method('purgeDeleted')
->with($this->equalTo($this->user), $this->equalTo(false));
@@ -139,11 +95,9 @@ class FolderApiControllerTest extends ControllerTestUtility {
->with($this->equalTo($folderName), $this->equalTo($this->user))
->will($this->returnValue($folder));
- $response = $this->folderAPI->create();
+ $response = $this->folderAPI->create($folderName);
- $this->assertEquals(array(
- 'folders' => array($folders[0]->toAPI())
- ), $response->getData());
+ $this->assertEquals($folder, $response);
}
@@ -157,7 +111,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
->method('create')
->will($this->throwException(new BusinessLayerConflictException($msg)));
- $response = $this->folderAPI->create();
+ $response = $this->folderAPI->create('hi');
$data = $response->getData();
$this->assertEquals($msg, $data['message']);
@@ -175,7 +129,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
->method('create')
->will($this->throwException(new BusinessLayerValidationException($msg)));
- $response = $this->folderAPI->create();
+ $response = $this->folderAPI->create('hi');
$data = $response->getData();
$this->assertEquals($msg, $data['message']);
@@ -185,45 +139,22 @@ class FolderApiControllerTest extends ControllerTestUtility {
public function testDelete() {
$folderId = 23;
-
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $this->getRequest(array('urlParams' => array(
- 'folderId' => $folderId
- ))),
- $this->folderBusinessLayer,
- $this->itemBusinessLayer,
- $this->user
- );
-
$this->folderBusinessLayer->expects($this->once())
->method('delete')
->with($this->equalTo($folderId), $this->equalTo($this->user));
- $response = $this->folderAPI->delete();
-
- $this->assertEmpty($response->getData());
+ $response = $this->folderAPI->delete(23);
}
public function testDeleteDoesNotExist() {
$folderId = 23;
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $this->getRequest(array('urlParams' => array(
- 'folderId' => $folderId
- ))),
- $this->folderBusinessLayer,
- $this->itemBusinessLayer,
- $this->user
- );
-
$this->folderBusinessLayer->expects($this->once())
->method('delete')
->will($this->throwException(new BusinessLayerException($this->msg)));
- $response = $this->folderAPI->delete();
+ $response = $this->folderAPI->delete($folderId);
$data = $response->getData();
$this->assertEquals($this->msg, $data['message']);
@@ -235,63 +166,24 @@ class FolderApiControllerTest extends ControllerTestUtility {
$folderId = 23;
$folderName = 'test';
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $this->getRequest(
- array(
- 'urlParams' => array(
- 'folderId' => $folderId
- ),
-
- 'params' => array(
- 'name' => $folderName
- )
- )
- ),
- $this->folderBusinessLayer,
- $this->itemBusinessLayer,
- $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->assertEmpty($response->getData());
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ $this->folderAPI->update($folderId, $folderName);
}
public function testUpdateDoesNotExist() {
$folderId = 23;
$folderName = 'test';
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $this->getRequest(
- array(
- 'urlParams' => array(
- 'folderId' => $folderId
- ),
-
- 'params' => array(
- 'name' => $folderName
- )
- )
- ),
- $this->folderBusinessLayer,
- $this->itemBusinessLayer,
- $this->user
- );
-
$this->folderBusinessLayer->expects($this->once())
->method('rename')
->will($this->throwException(new BusinessLayerException($this->msg)));
- $response = $this->folderAPI->update();
+ $response = $this->folderAPI->update($folderId, $folderName);
$data = $response->getData();
$this->assertEquals($this->msg, $data['message']);
@@ -303,29 +195,11 @@ class FolderApiControllerTest extends ControllerTestUtility {
$folderId = 23;
$folderName = 'test';
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $this->getRequest(
- array(
- 'urlParams' => array(
- 'folderId' => $folderId
- ),
-
- 'params' => array(
- 'name' => $folderName
- )
- )
- ),
- $this->folderBusinessLayer,
- $this->itemBusinessLayer,
- $this->user
- );
-
$this->folderBusinessLayer->expects($this->once())
->method('rename')
->will($this->throwException(new BusinessLayerConflictException($this->msg)));
- $response = $this->folderAPI->update();
+ $response = $this->folderAPI->update($folderId, $folderName);
$data = $response->getData();
$this->assertEquals($this->msg, $data['message']);
@@ -337,29 +211,11 @@ class FolderApiControllerTest extends ControllerTestUtility {
$folderId = 23;
$folderName = '';
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $this->getRequest(
- array(
- 'urlParams' => array(
- 'folderId' => $folderId
- ),
-
- 'params' => array(
- 'name' => $folderName
- )
- )
- ),
- $this->folderBusinessLayer,
- $this->itemBusinessLayer,
- $this->user
- );
-
$this->folderBusinessLayer->expects($this->once())
->method('rename')
->will($this->throwException(new BusinessLayerValidationException($this->msg)));
- $response = $this->folderAPI->update();
+ $response = $this->folderAPI->update($folderId, $folderName);
$data = $response->getData();
$this->assertEquals($this->msg, $data['message']);
@@ -368,22 +224,6 @@ class FolderApiControllerTest extends ControllerTestUtility {
public function testRead() {
- $request = $this->getRequest(array(
- 'urlParams' => array(
- 'folderId' => 3
- ),
- 'params' => array(
- 'newestItemId' => 30,
- )
- ));
- $this->folderAPI = new FolderApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->itemBusinessLayer,
- $this->user
- );
-
$this->itemBusinessLayer->expects($this->once())
->method('readFolder')
->with(
@@ -391,10 +231,7 @@ class FolderApiControllerTest extends ControllerTestUtility {
$this->equalTo(30),
$this->equalTo($this->user));
- $response = $this->folderAPI->read();
-
- $this->assertEmpty($response->getData());
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ $this->folderAPI->read(3, 30);
}