diff options
23 files changed, 321 insertions, 1395 deletions
diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index 5489f555c..eb172debb 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.php @@ -213,7 +213,7 @@ class FeedController extends Controller { * @param int $feedId * @param string $feedTitle */ - public function rename() { + public function rename($feedId, $feedTitle) { try { $this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId); } catch(BusinessLayerException $ex) { @@ -265,7 +265,7 @@ class FeedController extends Controller { * * @param int $feedId */ - public function restore(){ + public function restore($feedId){ try { $this->feedBusinessLayer->unmarkDeleted($feedId, $this->userId); } catch(BusinessLayerException $ex) { diff --git a/controller/folderapicontroller.php b/controller/folderapicontroller.php index bf78bdf72..274264ccc 100644 --- a/controller/folderapicontroller.php +++ b/controller/folderapicontroller.php @@ -66,7 +66,7 @@ class FolderApiController extends ApiController { public function create($name) { try { $this->folderBusinessLayer->purgeDeleted($this->userId, false); - $folder = $this->folderBusinessLayer->create($folderName, $this->userId); + $folder = $this->folderBusinessLayer->create($name, $this->userId); $this->registerSerializer(new EntityApiSerializer('folders')); return $folder; @@ -104,7 +104,7 @@ class FolderApiController extends ApiController { */ public function update($folderId, $name) { try { - $this->folderBusinessLayer->rename($folderId, $folderName, $this->userId); + $this->folderBusinessLayer->rename($folderId, $name, $this->userId); } catch(BusinessLayerValidationException $ex) { return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); diff --git a/controller/itemapicontroller.php b/controller/itemapicontroller.php index 5ab728d55..9e4fb672c 100644 --- a/controller/itemapicontroller.php +++ b/controller/itemapicontroller.php @@ -52,7 +52,7 @@ class ItemApiController extends ApiController { $this->registerSerializer(new EntityApiSerializer('items')); return $this->itemBusinessLayer->findAll($id, $type, $batchSize, $offset, - $showAll, $this->userId); + $getRead, $this->userId); } diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php index b621a8ae3..d60a24cea 100644 --- a/controller/pagecontroller.php +++ b/controller/pagecontroller.php @@ -55,7 +55,7 @@ class PageController extends Controller { 'showAll'); $compact = $this->settings->getUserValue($this->userId, $this->appName, 'compact'); - $language = $this->l10n->findLanguage(); + $language = $this->l10n->getLanguageCode(); return array( 'showAll' => $showAll === '1', diff --git a/db/feedmapper.php b/db/feedmapper.php index 6ac21ddac..ed6fd893d 100644 --- a/db/feedmapper.php +++ b/db/feedmapper.php @@ -15,6 +15,7 @@ namespace OCA\News\Db; use \OCP\IDb; use \OCP\AppFramework\Db\Mapper; +use \OCP\AppFramework\Db\Entity; class FeedMapper extends Mapper implements IMapper { diff --git a/db/foldermapper.php b/db/foldermapper.php index 6df2d21d6..bf3fbbc7b 100644 --- a/db/foldermapper.php +++ b/db/foldermapper.php @@ -15,7 +15,7 @@ namespace OCA\News\Db; use \OCP\IDb; use \OCP\AppFramework\Db\Mapper; - +use \OCP\AppFramework\Db\Entity; class FolderMapper extends Mapper implements IMapper { diff --git a/db/item.php b/db/item.php index 4a3fa0d8c..535dd745c 100644 --- a/db/item.php +++ b/db/item.php @@ -163,7 +163,6 @@ class Item extends Entity implements IAPI { $item->setUnstarred(); } - $item->setFeedId(null); return $item; } diff --git a/tests/classloader.php b/tests/classloader.php index bca9c21ea..8fdd9704d 100644 --- a/tests/classloader.php +++ b/tests/classloader.php @@ -12,6 +12,7 @@ */ require_once __DIR__ . '/../3rdparty/simplepie/autoloader.php'; +require_once __DIR__ . '/../../../tests/lib/appframework/db/MapperTestUtility.php'; // to execute without owncloud, we need to create our own classloader spl_autoload_register(function ($className){ diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index 820784d18..f41977241 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -13,11 +13,9 @@ namespace OCA\News\Controller; -use \OCP\IRequest; use \OCP\AppFramework\Http; use \OCA\News\Http\TextDownloadResponse; -use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\Utility\OPMLExporter; use \OCA\News\Db\Item; use \OCA\News\Db\Feed; @@ -25,7 +23,7 @@ use \OCA\News\Db\Feed; require_once(__DIR__ . "/../../classloader.php"); -class ExportControllerTest extends ControllerTestUtility { +class ExportControllerTest extends \PHPUnit_Framework_TestCase { private $appName; private $request; @@ -51,7 +49,9 @@ class ExportControllerTest extends ControllerTestUtility { $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->request = $this->getRequest(); + $this->request = $this->getMockBuilder('\OCP\IRequest') + ->disableOriginalConstructor() + ->getMock(); $this->opmlExporter = new OPMLExporter(); $this->controller = new ExportController($this->appName, $this->request, $this->feedBusinessLayer, $this->folderBusinessLayer, @@ -59,18 +59,6 @@ class ExportControllerTest extends ControllerTestUtility { } - public function testOpmlAnnotations(){ - $annotations = array('NoAdminRequired', 'NoCSRFRequired'); - $this->assertAnnotations($this->controller, 'opml', $annotations); - } - - - public function testArticlesAnnotations(){ - $annotations = array('NoAdminRequired', 'NoCSRFRequired'); - $this->assertAnnotations($this->controller, 'articles', $annotations); - } - - public function testOpmlExportNoFeeds(){ $opml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . 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); } diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index 4238b1faa..ba9d86a8a 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -13,10 +13,8 @@ namespace OCA\News\Controller; -use \OCP\IRequest; use \OCP\AppFramework\Http; -use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedType; use \OCA\News\BusinessLayer\BusinessLayerException; @@ -25,7 +23,7 @@ use \OCA\News\BusinessLayer\BusinessLayerConflictException; require_once(__DIR__ . "/../../classloader.php"); -class FeedControllerTest extends ControllerTestUtility { +class FeedControllerTest extends \PHPUnit_Framework_TestCase { private $appName; private $feedBusinessLayer; @@ -55,7 +53,10 @@ class FeedControllerTest extends ControllerTestUtility { $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->request = $this->getRequest(); + $this->request = $this->getMockBuilder( + '\OCP\IRequest') + ->disableOriginalConstructor() + ->getMock(); $this->controller = new FeedController($this->appName, $this->request, $this->folderBusinessLayer, $this->feedBusinessLayer, @@ -64,70 +65,6 @@ class FeedControllerTest extends ControllerTestUtility { $this->user); } - private function assertFeedControllerAnnotations($methodName){ - $annotations = array('NoAdminRequired'); - $this->assertAnnotations($this->controller, $methodName, $annotations); - } - - - private function getPostController($postValue, $url=array()){ - $post = array( - 'post' => $postValue, - 'urlParams' => $url - ); - - $request = $this->getRequest($post); - return new FeedController($this->appName, $request, - $this->folderBusinessLayer, - $this->feedBusinessLayer, - $this->itemBusinessLayer, - $this->settings, - $this->user); - } - - - public function testFeedsAnnotations(){ - $this->assertFeedControllerAnnotations('index'); - } - - - public function testActiveAnnotations(){ - $this->assertFeedControllerAnnotations('active'); - } - - - public function testCreateAnnotations(){ - $this->assertFeedControllerAnnotations('create'); - } - - - public function testDeleteAnnotations(){ - $this->assertFeedControllerAnnotations('delete'); - } - - - public function testRestoreAnnotations(){ - $this->assertFeedControllerAnnotations('restore'); - } - - - public function testUpdateAnnotations(){ - $this->assertFeedControllerAnnotations('update'); - } - - - public function testMoveAnnotations(){ - $this->assertFeedControllerAnnotations('move'); - } - - - public function testImportArticlesAnnotations(){ - $this->assertFeedControllerAnnotations('import'); - } - - public function testReadAnnotations(){ - $this->assertFeedControllerAnnotations('read'); - } public function testIndex(){ $result = array( @@ -151,7 +88,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->index(); - $this->assertEquals($result, $response->getData()); + $this->assertEquals($result, $response); } @@ -178,7 +115,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->index(); - $this->assertEquals($result, $response->getData()); + $this->assertEquals($result, $response); } @@ -213,7 +150,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->active(); - $this->assertEquals($result, $response->getData()); + $this->assertEquals($result, $response); } @@ -236,7 +173,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->active(); - $this->assertEquals($result, $response->getData()); + $this->assertEquals($result, $response); } @@ -259,7 +196,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->active(); - $this->assertEquals($result, $response->getData()); + $this->assertEquals($result, $response); } @@ -277,7 +214,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->active(); - $this->assertEquals($result, $response->getData()); + $ |