summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--external/feedapi.php39
-rw-r--r--external/folderapi.php37
-rw-r--r--external/itemapi.php56
-rw-r--r--external/newsapi.php5
-rw-r--r--tests/unit/controller/FeedControllerTest.php18
-rw-r--r--tests/unit/external/FeedAPITest.php91
-rw-r--r--tests/unit/external/FolderAPITest.php77
-rw-r--r--tests/unit/external/ItemAPITest.php121
-rw-r--r--tests/unit/external/NewsAPITest.php15
9 files changed, 404 insertions, 55 deletions
diff --git a/external/feedapi.php b/external/feedapi.php
index 9ebfbc012..dc7e1781b 100644
--- a/external/feedapi.php
+++ b/external/feedapi.php
@@ -54,6 +54,11 @@ class FeedAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function getAll() {
$userId = $this->api->getUserId();
@@ -68,7 +73,7 @@ class FeedAPI extends Controller {
// check case when there are no items
try {
- $result['newestItemId'] =
+ $result['newestItemId'] =
$this->itemBusinessLayer->getNewestItemId($userId);
} catch(BusinessLayerException $ex) {}
@@ -76,6 +81,11 @@ class FeedAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function create() {
$userId = $this->api->getUserId();
$feedUrl = $this->params('url');
@@ -83,29 +93,34 @@ class FeedAPI extends Controller {
try {
$this->feedBusinessLayer->purgeDeleted($userId, false);
-
+
$feed = $this->feedBusinessLayer->create($feedUrl, $folderId, $userId);
$result = array(
'feeds' => array($feed->toAPI())
);
try {
- $result['newestItemId'] =
+ $result['newestItemId'] =
$this->itemBusinessLayer->getNewestItemId($userId);
} catch(BusinessLayerException $ex) {}
return new NewsAPIResult($result);
} catch(BusinessLayerExistsException $ex) {
- return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR,
+ return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR,
$ex->getMessage());
} catch(BusinessLayerException $ex) {
- return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
+ return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
$ex->getMessage());
}
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function delete() {
$userId = $this->api->getUserId();
$feedId = (int) $this->params('feedId');
@@ -114,12 +129,17 @@ class FeedAPI extends Controller {
$this->feedBusinessLayer->delete($feedId, $userId);
return new NewsAPIResult();
} catch(BusinessLayerException $ex) {
- return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
+ return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
$ex->getMessage());
}
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function read() {
$userId = $this->api->getUserId();
$feedId = (int) $this->params('feedId');
@@ -130,6 +150,11 @@ class FeedAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function move() {
$userId = $this->api->getUserId();
$feedId = (int) $this->params('feedId');
@@ -139,7 +164,7 @@ class FeedAPI extends Controller {
$this->feedBusinessLayer->move($feedId, $folderId, $userId);
return new NewsAPIResult();
} catch(BusinessLayerException $ex) {
- return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
+ return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
$ex->getMessage());
}
}
diff --git a/external/folderapi.php b/external/folderapi.php
index bbe32ab24..5b90eff9e 100644
--- a/external/folderapi.php
+++ b/external/folderapi.php
@@ -40,7 +40,7 @@ class FolderAPI extends Controller {
private $folderBusinessLayer;
private $itemBusinessLayer;
- public function __construct(API $api,
+ public function __construct(API $api,
Request $request,
FolderBusinessLayer $folderBusinessLayer,
ItemBusinessLayer $itemBusinessLayer){
@@ -50,6 +50,11 @@ class FolderAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function getAll() {
$userId = $this->api->getUserId();
$result = array(
@@ -64,7 +69,12 @@ class FolderAPI extends Controller {
}
- public function create() {
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
+ public function create() {
$userId = $this->api->getUserId();
$folderName = $this->params('name');
$result = array(
@@ -78,12 +88,17 @@ class FolderAPI extends Controller {
return new NewsAPIResult($result);
} catch(BusinessLayerExistsException $ex) {
- return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR,
+ return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR,
$ex->getMessage());
}
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function delete() {
$userId = $this->api->getUserId();
$folderId = (int) $this->params('folderId');
@@ -92,12 +107,17 @@ class FolderAPI extends Controller {
$this->folderBusinessLayer->delete($folderId, $userId);
return new NewsAPIResult();
} catch(BusinessLayerException $ex) {
- return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
+ return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
$ex->getMessage());
}
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function update() {
$userId = $this->api->getUserId();
$folderId = (int) $this->params('folderId');
@@ -108,16 +128,21 @@ class FolderAPI extends Controller {
return new NewsAPIResult();
} catch(BusinessLayerExistsException $ex) {
- return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR,
+ return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR,
$ex->getMessage());
} catch(BusinessLayerException $ex) {
- return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
+ return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
$ex->getMessage());
}
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function read() {
$userId = $this->api->getUserId();
$folderId = (int) $this->params('folderId');
diff --git a/external/itemapi.php b/external/itemapi.php
index adca0a3d8..fae0b3593 100644
--- a/external/itemapi.php
+++ b/external/itemapi.php
@@ -45,6 +45,11 @@ class ItemAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function getAll() {
$result = array(
'items' => array()
@@ -80,6 +85,11 @@ class ItemAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function getUpdated() {
$result = array(
'items' => array()
@@ -133,26 +143,51 @@ class ItemAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function read() {
return $this->setRead(true);
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function unread() {
return $this->setRead(false);
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function star() {
return $this->setStarred(true);
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function unstar() {
return $this->setStarred(false);
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function readAll() {
$userId = $this->api->getUserId();
$newestItemId = (int) $this->params('newestItemId');
@@ -178,11 +213,21 @@ class ItemAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function readMultiple() {
return $this->setMultipleRead(true);
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function unreadMultiple() {
return $this->setMultipleRead(false);
}
@@ -205,13 +250,24 @@ class ItemAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function starMultiple() {
return $this->setMultipleStarred(true);
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function unstarMultiple() {
return $this->setMultipleStarred(false);
}
+
}
diff --git a/external/newsapi.php b/external/newsapi.php
index 747f818ec..bb3e3bc28 100644
--- a/external/newsapi.php
+++ b/external/newsapi.php
@@ -38,6 +38,11 @@ class NewsAPI extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ */
public function version() {
$version = $this->api->getAppValue('installed_version');
return new NewsAPIResult(array('version' => $version));
diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php
index 370158822..064fdeeb4 100644
--- a/tests/unit/controller/FeedControllerTest.php
+++ b/tests/unit/controller/FeedControllerTest.php
@@ -84,9 +84,9 @@ class FeedControllerTest extends ControllerTestUtility {
);
$request = $this->getRequest($post);
- return new FeedController($this->api, $request,
+ return new FeedController($this->api, $request,
$this->folderBusinessLayer,
- $this->feedBusinessLayer,
+ $this->feedBusinessLayer,
$this->itemBusinessLayer);
}
@@ -293,7 +293,7 @@ class FeedControllerTest extends ControllerTestUtility {
$response = $this->controller->active();
$this->assertEquals($result, $response->getParams());
- $this->assertTrue($response instanceof JSONResponse);
+ $this->assertTrue($response instanceof JSONResponse);
}
@@ -330,7 +330,7 @@ class FeedControllerTest extends ControllerTestUtility {
$this->assertEquals($result, $response->getParams());
$this->assertTrue($response instanceof JSONResponse);
- }
+ }
public function testCreateNoItems(){
@@ -366,7 +366,7 @@ class FeedControllerTest extends ControllerTestUtility {
$this->assertEquals($result, $response->getParams());
$this->assertTrue($response instanceof JSONResponse);
- }
+ }
public function testCreateReturnsErrorForInvalidCreate(){
@@ -507,7 +507,7 @@ class FeedControllerTest extends ControllerTestUtility {
->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('move')
- ->with($this->equalTo($url['feedId']),
+ ->with($this->equalTo($url['feedId']),
$this->equalTo($post['parentFolderId']),
$this->equalTo($this->user));
@@ -559,7 +559,7 @@ class FeedControllerTest extends ControllerTestUtility {
->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('importGoogleReaderJSON')
- ->with($this->equalTo($post['json']),
+ ->with($this->equalTo($post['json']),
$this->equalTo($this->user))
->will($this->returnValue($feed));
@@ -614,7 +614,7 @@ class FeedControllerTest extends ControllerTestUtility {
->with($this->equalTo($url['feedId']));
$response = $this->controller->restore();
- $this->assertTrue($response instanceof JSONResponse);
+ $this->assertTrue($response instanceof JSONResponse);
}
@@ -640,4 +640,4 @@ class FeedControllerTest extends ControllerTestUtility {
$this->assertTrue($response instanceof JSONResponse);
}
-} \ No newline at end of file
+}
diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php
index cdc04bf0c..fd65d742c 100644
--- a/tests/unit/external/FeedAPITest.php
+++ b/tests/unit/external/FeedAPITest.php
@@ -26,6 +26,8 @@
namespace OCA\News\External;
use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Http\JSONResponse;
+use \OCA\AppFramework\Utility\ControllerTestUtility;
use \OCA\News\BusinessLayer\BusinessLayerException;
use \OCA\News\BusinessLayer\BusinessLayerExistsException;
@@ -36,7 +38,7 @@ use \OCA\News\Db\Item;
require_once(__DIR__ . "/../../classloader.php");
-class FeedAPITest extends \PHPUnit_Framework_TestCase {
+class FeedAPITest extends ControllerTestUtility {
private $folderBusinessLayer;
private $feedBusinessLayer;
@@ -76,13 +78,41 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
$this->user = 'tom';
- $this->api->expects($this->once())
- ->method('getUserId')
- ->will($this->returnValue($this->user));
$this->msg = 'hohoho';
}
+ private function assertDefaultAnnotations($methodName){
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $this->assertAnnotations($this->feedAPI, $methodName, $annotations);
+ }
+
+
+ public function testGetAllAnnotations(){
+ $this->assertDefaultAnnotations('getAll');
+ }
+
+
+ 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 testGetAll() {
$feeds = array(
new Feed()
@@ -90,6 +120,9 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$starredCount = 3;
$newestItemId = 2;
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('starredCount')
->with($this->equalTo($this->user))
@@ -119,6 +152,9 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
);
$starredCount = 3;
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('starredCount')
->with($this->equalTo($this->user))
@@ -151,9 +187,11 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->folderBusinessLayer,
$this->feedBusinessLayer,
$this->itemBusinessLayer
- );
+ );
-
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('delete')
->with(
@@ -178,9 +216,11 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->folderBusinessLayer,
$this->feedBusinessLayer,
$this->itemBusinessLayer
- );
+ );
-
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('delete')
->will($this->throwException(new BusinessLayerException($this->msg)));
@@ -207,8 +247,11 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->folderBusinessLayer,
$this->feedBusinessLayer,
$this->itemBusinessLayer
- );
+ );
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('purgeDeleted')
->with($this->equalTo($this->user), $this->equalTo(false));
@@ -249,8 +292,11 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->folderBusinessLayer,
$this->feedBusinessLayer,
$this->itemBusinessLayer
- );
+ );
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('purgeDeleted')
->with($this->equalTo($this->user), $this->equalTo(false));
@@ -278,6 +324,9 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
public function testCreateExists() {
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('purgeDeleted')
->with($this->equalTo($this->user), $this->equalTo(false));
@@ -294,6 +343,9 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
public function testCreateError() {
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('create')
->will($this->throwException(new BusinessLayerException($this->msg)));
@@ -321,9 +373,11 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->folderBusinessLayer,
$this->feedBusinessLayer,
$this->itemBusinessLayer
- );
+ );
-
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('readFeed')
->with(
@@ -354,9 +408,11 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->folderBusinessLayer,
$this->feedBusinessLayer,
$this->itemBusinessLayer
- );
+ );
-
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('move')
->with(
@@ -372,7 +428,10 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
}
- public function testMoveDoesNotExist() {
+ public function testMoveDoesNotExist() {
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('move')
->will($this->throwException(new BusinessLayerException($this->msg)));
@@ -383,4 +442,4 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($this->msg, $response->getMessage());
$this->assertEquals(NewsAPIResult::NOT_FOUND_ERROR, $response->getStatusCode());
}
-} \ No newline at end of file
+}
diff --git a/tests/unit/external/FolderAPITest.php b/tests/unit/external/FolderAPITest.php
index 1ae4bd081..f9e5490a3 100644
--- a/tests/unit/external/FolderAPITest.php
+++ b/tests/unit/external/FolderAPITest.php
@@ -26,6 +26,8 @@
namespace OCA\News\External;
use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Http\JSONResponse;
+use \OCA\AppFramework\Utility\ControllerTestUtility;
use \OCA\News\BusinessLayer\BusinessLayerException;
use \OCA\News\BusinessLayer\BusinessLayerExistsException;
@@ -37,7 +39,7 @@ use \OCA\News\Db\Item;
require_once(__DIR__ . "/../../classloader.php");
-class FolderAPITest extends \PHPUnit_Framework_TestCase {
+class FolderAPITest extends ControllerTestUtility {
private $folderBusinessLayer;
private $itemBusinessLayer;
@@ -72,9 +74,37 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
);
$this->user = 'tom';
$this->msg = 'test';
- $this->api->expects($this->once())
- ->method('getUserId')
- ->will($this->returnValue($this->user));
+ }
+
+
+ private function assertDefaultAnnotations($methodName){
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $this->assertAnnotations($this->folderAPI, $methodName, $annotations);
+ }
+
+
+ public function testGetAllAnnotations(){
+ $this->assertDefaultAnnotations('getAll');
+ }
+
+
+ public function testCreateAnnotations(){
+ $this->assertDefaultAnnotations('create');
+ }
+
+
+ public function testDeleteAnnotations(){
+ $this->assertDefaultAnnotations('delete');
+ }
+
+
+ public function testUpdateAnnotations(){
+ $this->assertDefaultAnnotations('update');
+ }
+
+
+ public function testReadAnnotations(){
+ $this->assertDefaultAnnotations('read');
}
@@ -83,6 +113,9 @@ 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))
@@ -112,6 +145,9 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->folderBusinessLayer->expects($this->once())
->method('purgeDeleted')
->with($this->equalTo($this->user), $this->equalTo(false));
@@ -130,6 +166,10 @@ 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('purgeDeleted')
->with($this->equalTo($this->user), $this->equalTo(false));
@@ -157,6 +197,9 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
$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));
@@ -179,6 +222,9 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
$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)));
@@ -202,7 +248,7 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
'urlParams' => array(
'folderId' => $folderId
),
-
+
'params' => array(
'name' => $folderName
)
@@ -212,6 +258,9 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
$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),
@@ -236,7 +285,7 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
'urlParams' => array(
'folderId' => $folderId
),
-
+
'params' => array(
'name' => $folderName
)
@@ -246,6 +295,9 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
$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)));
@@ -269,7 +321,7 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
'urlParams' => array(
'folderId' => $folderId
),
-
+
'params' => array(
'name' => $folderName
)
@@ -279,6 +331,9 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
$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)));
@@ -305,9 +360,11 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
$request,
$this->folderBusinessLayer,
$this->itemBusinessLayer
- );
+ );
-
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('readFolder')
->with(
@@ -323,4 +380,4 @@ class FolderAPITest extends \PHPUnit_Framework_TestCase {
}
-} \ No newline at end of file
+}
diff --git a/tests/unit/external/ItemAPITest.php b/tests/unit/external/ItemAPITest.php
index 56e518da8..cc66d562d 100644
--- a/tests/unit/external/ItemAPITest.php
+++ b/tests/unit/external/ItemAPITest.php
@@ -26,6 +26,8 @@
namespace OCA\News\External;
use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Http\JSONResponse;
+use \OCA\AppFramework\Utility\ControllerTestUtility;
use \OCA\News\BusinessLayer\BusinessLayerException;
use \OCA\News\Db\Item;
@@ -33,7 +35,7 @@ use \OCA\News\Db\Item;
require_once(__DIR__ . "/../../classloader.php");
-class ItemAPITest extends \PHPUnit_Framework_TestCase {
+class ItemAPITest extends ControllerTestUtility {
private $itemBusinessLayer;
private $itemAPI;
@@ -56,9 +58,6 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()
->getMock();
$this->user = 'tom';
- $this->api->expects($this->once())
- ->method('getUserId')
- ->will($this->returnValue($this->user));
$this->itemAPI = new ItemAPI(
$this->api,
$this->request,
@@ -68,6 +67,67 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
}
+ private function assertDefaultAnnotations($methodName){
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $this->assertAnnotations($this->itemAPI, $methodName, $annotations);
+ }
+
+
+ public function testGetAllAnnotations(){
+ $this->assertDefaultAnnotations('getAll');
+ }
+
+
+ public function testGetUpdatedAnnotations(){
+ $this->assertDefaultAnnotations('getUpdated');
+ }
+
+
+ public function testReadAllAnnotations(){
+ $this->assertDefaultAnnotations('readAll');
+ }
+
+
+ public function testReadAnnotations(){
+ $this->assertDefaultAnnotations('read');
+ }
+
+
+ public function testStarAnnotations(){
+ $this->assertDefaultAnnotations('star');
+ }
+
+
+ public function testUnreadAnnotations(){
+ $this->assertDefaultAnnotations('unread');
+ }
+
+
+ public function testUnstarAnnotations(){
+ $this->assertDefaultAnnotations('unstar');
+ }
+
+
+ public function testReadMultipleAnnotations(){
+ $this->assertDefaultAnnotations('readMultiple');
+ }
+
+
+ public function testStarMultipleAnnotations(){
+ $this->assertDefaultAnnotations('starMultiple');
+ }
+
+
+ public function testUnreadMultipleAnnotations(){
+ $this->assertDefaultAnnotations('unreadMultiple');
+ }
+
+
+ public function testUnstarMultipleAnnotations(){
+ $this->assertDefaultAnnotations('unstarMultiple');
+ }
+
+
public function testGetAll() {
$items = array(
new Item()
@@ -85,6 +145,9 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('findAll')
->with(
@@ -120,6 +183,9 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('findAllNew')
->with(
@@ -149,6 +215,9 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('read')
->with(
@@ -175,6 +244,9 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('read')
->will($this->throwException(new BusinessLayerException($this->msg)));
@@ -197,6 +269,9 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('read')
->with(
@@ -223,6 +298,9 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('read')
->will($this->throwException(new BusinessLayerException($this->msg)));
@@ -246,6 +324,9 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('star')
-&g