summaryrefslogtreecommitdiffstats
path: root/tests/unit/controller/FeedApiControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/controller/FeedApiControllerTest.php')
-rw-r--r--tests/unit/controller/FeedApiControllerTest.php256
1 files changed, 41 insertions, 215 deletions
diff --git a/tests/unit/controller/FeedApiControllerTest.php b/tests/unit/controller/FeedApiControllerTest.php
index 220e89ea9..1444fa563 100644
--- a/tests/unit/controller/FeedApiControllerTest.php
+++ b/tests/unit/controller/FeedApiControllerTest.php
@@ -13,10 +13,8 @@
namespace OCA\News\Controller;
-use \OCP\IRequest;
use \OCP\AppFramework\Http;
-use \OCA\News\Utility\ControllerTestUtility;
use \OCA\News\BusinessLayer\BusinessLayerException;
use \OCA\News\BusinessLayer\BusinessLayerConflictException;
use \OCA\News\Db\Folder;
@@ -26,7 +24,7 @@ use \OCA\News\Db\Item;
require_once(__DIR__ . "/../../classloader.php");
-class FeedApiControllerTest extends ControllerTestUtility {
+class FeedApiControllerTest extends \PHPUnit_Framework_TestCase {
private $folderBusinessLayer;
private $feedBusinessLayer;
@@ -37,11 +35,13 @@ class FeedApiControllerTest extends ControllerTestUtility {
private $request;
private $msg;
private $logger;
+ private $loggerParams;
protected function setUp() {
$this->user = 'tom';
+ $this->loggerParams = array('hi');
$this->logger = $this->getMockBuilder(
- '\OCA\News\Core\Logger')
+ '\OCP\ILogger')
->disableOriginalConstructor()
->getMock();
$this->appName = 'news';
@@ -68,55 +68,13 @@ class FeedApiControllerTest extends ControllerTestUtility {
$this->feedBusinessLayer,
$this->itemBusinessLayer,
$this->logger,
- $this->user
+ $this->user,
+ $this->loggerParams
);
$this->msg = 'hohoho';
}
- private function assertDefaultAnnotations($methodName){
- $annotations = array('NoAdminRequired', 'NoCSRFRequired', 'API');
- $this->assertAnnotations($this->feedAPI, $methodName, $annotations);
- }
-
-
- public function testGetAllAnnotations(){
- $this->assertDefaultAnnotations('index');
- }
-
-
- public function testCreateAnnotations(){
- $this->assertDefaultAnnotations('create');
- }
-
-
- public function testDeleteAnnotations(){
- $this->assertDefaultAnnotations('delete');
- }
-
-
- public function testMoveAnnotations(){
- $this->assertDefaultAnnotations('move');
- }
-
-
- public function testReadAnnotations(){
- $this->assertDefaultAnnotations('read');
- }
-
-
- public function testFromUsersAnnotations(){
- $annotations = array('NoCSRFRequired', 'API');
- $this->assertAnnotations($this->feedAPI, 'fromAllUsers', $annotations);
- }
-
-
- public function testUpdateAnnotations(){
- $annotations = array('NoCSRFRequired');
- $this->assertAnnotations($this->feedAPI, 'update', $annotations);
- }
-
-
public function testIndex() {
$feeds = array(
new Feed()
@@ -143,7 +101,7 @@ class FeedApiControllerTest extends ControllerTestUtility {
'feeds' => array($feeds[0]->toAPI()),
'starredCount' => $starredCount,
'newestItemId' => $newestItemId
- ), $response->getData());
+ ), $response);
}
@@ -171,56 +129,27 @@ class FeedApiControllerTest extends ControllerTestUtility {
$this->assertEquals(array(
'feeds' => array($feeds[0]->toAPI()),
'starredCount' => $starredCount,
- ), $response->getData());
+ ), $response);
}
public function testDelete() {
- $request = $this->getRequest(array('urlParams' => array(
- 'feedId' => 2
- )));
- $this->feedAPI = new FeedApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->feedBusinessLayer,
- $this->itemBusinessLayer,
- $this->logger,
- $this->user
- );
-
$this->feedBusinessLayer->expects($this->once())
->method('delete')
->with(
$this->equalTo(2),
$this->equalTo($this->user));
- $response = $this->feedAPI->delete();
-
- $this->assertEmpty($response->getData());
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ $this->feedAPI->delete(2);
}
public function testDeleteDoesNotExist() {
- $request = $this->getRequest(array('urlParams' => array(
- 'feedId' => 2
- )));
- $this->feedAPI = new FeedApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->feedBusinessLayer,
- $this->itemBusinessLayer,
- $this->logger,
- $this->user
- );
-
$this->feedBusinessLayer->expects($this->once())
->method('delete')
->will($this->throwException(new BusinessLayerException($this->msg)));
- $response = $this->feedAPI->delete();
+ $response = $this->feedAPI->delete(2);
$data = $response->getData();
$this->assertEquals($this->msg, $data['message']);
@@ -232,19 +161,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
$feeds = array(
new Feed()
);
- $request = $this->getRequest(array('params' => array(
- 'url' => 'ho',
- 'folderId' => 3
- )));
- $this->feedAPI = new FeedApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->feedBusinessLayer,
- $this->itemBusinessLayer,
- $this->logger,
- $this->user
- );
$this->feedBusinessLayer->expects($this->once())
->method('purgeDeleted')
@@ -252,7 +168,7 @@ class FeedApiControllerTest extends ControllerTestUtility {
$this->feedBusinessLayer->expects($this->once())
->method('create')
->with(
- $this->equalTo('ho'),
+ $this->equalTo('url'),
$this->equalTo(3),
$this->equalTo($this->user))
->will($this->returnValue($feeds[0]));
@@ -260,14 +176,12 @@ class FeedApiControllerTest extends ControllerTestUtility {
->method('getNewestItemId')
->will($this->returnValue(3));
- $response = $this->feedAPI->create();
+ $response = $this->feedAPI->create('url', 3);
$this->assertEquals(array(
'feeds' => array($feeds[0]->toAPI()),
'newestItemId' => 3
- ), $response->getData());
-
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ ), $response);
}
@@ -275,19 +189,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
$feeds = array(
new Feed()
);
- $request = $this->getRequest(array('params' => array(
- 'url' => 'ho',
- 'folderId' => 3
- )));
- $this->feedAPI = new FeedApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->feedBusinessLayer,
- $this->itemBusinessLayer,
- $this->logger,
- $this->user
- );
$this->feedBusinessLayer->expects($this->once())
->method('purgeDeleted')
@@ -303,13 +204,11 @@ class FeedApiControllerTest extends ControllerTestUtility {
->method('getNewestItemId')
->will($this->throwException(new BusinessLayerException('')));
- $response = $this->feedAPI->create();
+ $response = $this->feedAPI->create('ho', 3);
$this->assertEquals(array(
'feeds' => array($feeds[0]->toAPI())
- ), $response->getData());
-
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ ), $response);
}
@@ -322,7 +221,7 @@ class FeedApiControllerTest extends ControllerTestUtility {
->method('create')
->will($this->throwException(new BusinessLayerConflictException($this->msg)));
- $response = $this->feedAPI->create();
+ $response = $this->feedAPI->create('ho', 3);
$data = $response->getData();
$this->assertEquals($this->msg, $data['message']);
@@ -335,7 +234,7 @@ class FeedApiControllerTest extends ControllerTestUtility {
->method('create')
->will($this->throwException(new BusinessLayerException($this->msg)));
- $response = $this->feedAPI->create();
+ $response = $this->feedAPI->create('ho', 3);
$data = $response->getData();
$this->assertEquals($this->msg, $data['message']);
@@ -344,24 +243,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
public function testRead() {
- $request = $this->getRequest(array(
- 'urlParams' => array(
- 'feedId' => 3
- ),
- 'params' => array(
- 'newestItemId' => 30,
- )
- ));
- $this->feedAPI = new FeedApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->feedBusinessLayer,
- $this->itemBusinessLayer,
- $this->logger,
- $this->user
- );
-
$this->itemBusinessLayer->expects($this->once())
->method('readFeed')
->with(
@@ -369,32 +250,11 @@ class FeedApiControllerTest extends ControllerTestUtility {
$this->equalTo(30),
$this->equalTo($this->user));
- $response = $this->feedAPI->read();
-
- $this->assertEmpty($response->getData());
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ $this->feedAPI->read(3, 30);
}
public function testMove() {
- $request = $this->getRequest(array(
- 'urlParams' => array(
- 'feedId' => 3
- ),
- 'params' => array(
- 'folderId' => 30,
- )
- ));
- $this->feedAPI = new FeedApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->feedBusinessLayer,
- $this->itemBusinessLayer,
- $this->logger,
- $this->user
- );
-
$this->feedBusinessLayer->expects($this->once())
->method('move')
->with(
@@ -402,10 +262,20 @@ class FeedApiControllerTest extends ControllerTestUtility {
$this->equalTo(30),
$this->equalTo($this->user));
- $response = $this->feedAPI->move();
+ $this->feedAPI->move(3, 30);
+ }
+
+
+ public function testMoveDoesNotExist() {
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('move')
+ ->will($this->throwException(new BusinessLayerException($this->msg)));
+
+ $response = $this->feedAPI->move(3, 4);
- $this->assertEmpty($response->getData());
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ $data = $response->getData();
+ $this->assertEquals($this->msg, $data['message']);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
}
@@ -413,24 +283,6 @@ class FeedApiControllerTest extends ControllerTestUtility {
$feedId = 3;
$feedTitle = 'test';
- $request = $this->getRequest(array(
- 'urlParams' => array(
- 'feedId' => $feedId
- ),
- 'params' => array(
- 'feedTitle' => $feedTitle
- )
- ));
- $this->feedAPI = new FeedApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->feedBusinessLayer,
- $this->itemBusinessLayer,
- $this->logger,
- $this->user
- );
-
$this->feedBusinessLayer->expects($this->once())
->method('rename')
->with(
@@ -438,23 +290,7 @@ class FeedApiControllerTest extends ControllerTestUtility {
$this->equalTo($feedTitle),
$this->equalTo($this->user));
- $response = $this->feedAPI->rename();
-
- $this->assertEmpty($response->getData());
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
- }
-
-
- public function testMoveDoesNotExist() {
- $this->feedBusinessLayer->expects($this->once())
- ->method('move')
- ->will($this->throwException(new BusinessLayerException($this->msg)));
-
- $response = $this->feedAPI->move();
-
- $data = $response->getData();
- $this->assertEquals($this->msg, $data['message']);
- $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+ $this->feedAPI->rename($feedId, $feedTitle);
}
@@ -467,45 +303,35 @@ class FeedApiControllerTest extends ControllerTestUtility {
$this->feedBusinessLayer->expects($this->once())
->method('findAllFromAllUsers')
->will($this->returnValue($feeds));
- $response = $this->feedAPI->fromAllUsers();
- $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response->render());
+ $response = json_encode($this->feedAPI->fromAllUsers());
+ $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response);
}
public function testUpdate() {
$feedId = 3;
$userId = 'hi';
- $request = $this->getRequest(array('params' => array(
- 'feedId' => $feedId,
- 'userId' => $userId
- )));
- $this->feedAPI = new FeedApiController(
- $this->appName,
- $request,
- $this->folderBusinessLayer,
- $this->feedBusinessLayer,
- $this->itemBusinessLayer,
- $this->logger,
- $this->user
- );
+
$this->feedBusinessLayer->expects($this->once())
->method('update')
->with($this->equalTo($feedId), $this->equalTo($userId));
- $this->feedAPI->update();
+ $this->feedAPI->update($userId, $feedId);
}
public function testUpdateError() {
+ $feedId = 3;
+ $userId = 'hi';
$this->feedBusinessLayer->expects($this->once())
->method('update')
->will($this->throwException(new \Exception($this->msg)));
$this->logger->expects($this->once())
- ->method('log')
+ ->method('debug')
->with($this->equalTo('Could not update feed ' . $this->msg),
- $this->equalTo('debug'));
+ $this->equalTo($this->loggerParams));
- $this->feedAPI->update();
+ $this->feedAPI->update($userId, $feedId);
}