summaryrefslogtreecommitdiffstats
path: root/tests/unit/controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/controller')
-rw-r--r--tests/unit/controller/ExportControllerTest.php61
-rw-r--r--tests/unit/controller/FeedControllerTest.php350
-rw-r--r--tests/unit/controller/FolderControllerTest.php260
-rw-r--r--tests/unit/controller/ItemControllerTest.php299
-rw-r--r--tests/unit/controller/PageControllerTest.php68
-rw-r--r--tests/unit/controller/TwitterFetcherTest.php77
-rw-r--r--tests/unit/controller/UserSettingsControllerTest.php112
7 files changed, 1227 insertions, 0 deletions
diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php
new file mode 100644
index 000000000..913b091c6
--- /dev/null
+++ b/tests/unit/controller/ExportControllerTest.php
@@ -0,0 +1,61 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Controller;
+
+use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Http\JSONResponse;
+use \OCA\AppFramework\Utility\ControllerTestUtility;
+use \OCA\AppFramework\Db\DoesNotExistException;
+use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
+
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class ExportControllerTest extends ControllerTestUtility {
+
+ private $api;
+ private $request;
+ private $controller;
+
+
+ /**
+ * Gets run before each test
+ */
+ public function setUp(){
+ $this->api = $this->getAPIMock();
+ $this->request = new Request();
+ $this->controller = new ExportController($this->api, $this->request);
+ }
+
+
+ public function testOpmlAnnotations(){
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $this->assertAnnotations($this->controller, 'opml', $annotations);
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php
new file mode 100644
index 000000000..e3dc60a28
--- /dev/null
+++ b/tests/unit/controller/FeedControllerTest.php
@@ -0,0 +1,350 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Controller;
+
+use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Http\JSONResponse;
+use \OCA\AppFramework\Utility\ControllerTestUtility;
+use \OCA\AppFramework\Db\DoesNotExistException;
+use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
+
+use \OCA\News\Db\Feed;
+use \OCA\News\Db\FeedType;
+use \OCA\News\Bl\BLException;
+
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class FeedControllerTest extends ControllerTestUtility {
+
+ private $api;
+ private $bl;
+ private $request;
+ private $controller;
+ private $folderBl;
+
+
+ /**
+ * Gets run before each test
+ */
+ public function setUp(){
+ $this->api = $this->getAPIMock();
+ $this->bl = $this->getMockBuilder('\OCA\News\Bl\FeedBl')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->folderBl = $this->getMockBuilder('\OCA\News\Bl\FolderBl')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->request = new Request();
+ $this->controller = new FeedController($this->api, $this->request,
+ $this->bl, $this->folderBl);
+ $this->user = 'jack';
+ }
+
+ private function assertFeedControllerAnnotations($methodName){
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $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->api, $request, $this->bl, $this->folderBl);
+ }
+
+
+ public function testFeedsAnnotations(){
+ $this->assertFeedControllerAnnotations('feeds');
+ }
+
+
+ public function testActiveAnnotations(){
+ $this->assertFeedControllerAnnotations('active');
+ }
+
+
+ public function testCreateAnnotations(){
+ $this->assertFeedControllerAnnotations('create');
+ }
+
+
+ public function testDeleteAnnotations(){
+ $this->assertFeedControllerAnnotations('delete');
+ }
+
+
+ public function testUpdateAnnotations(){
+ $this->assertFeedControllerAnnotations('update');
+ }
+
+
+ public function testMoveAnnotations(){
+ $this->assertFeedControllerAnnotations('move');
+ }
+
+
+ public function testFeeds(){
+ $result = array(
+ 'feeds' => array(
+ array('a feed')
+ )
+ );
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('findAllFromUser')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($result['feeds']));
+
+ $response = $this->controller->feeds();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ private function activeInitMocks($id, $type){
+ $this->api->expects($this->at(0))
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->api->expects($this->at(1))
+ ->method('getUserValue')
+ ->with($this->equalTo('lastViewedFeedId'))
+ ->will($this->returnValue($id));
+ $this->api->expects($this->at(2))
+ ->method('getUserValue')
+ ->with($this->equalTo('lastViewedFeedType'))
+ ->will($this->returnValue($type));
+ }
+
+
+ public function testActive(){
+ $id = 3;
+ $type = FeedType::STARRED;
+ $result = array(
+ 'activeFeed' => array(
+ 'id' => $id,
+ 'type' => $type
+ )
+ );
+
+ $this->activeInitMocks($id, $type);
+
+ $response = $this->controller->active();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testActiveFeedDoesNotExist(){
+ $id = 3;
+ $type = FeedType::FEED;
+ $ex = new BLException('hiu');
+ $result = array(
+ 'activeFeed' => array(
+ 'id' => 0,
+ 'type' => FeedType::SUBSCRIPTIONS
+ )
+ );
+ $this->bl->expects($this->once())
+ ->method('find')
+ ->with($this->equalTo($id), $this->equalTo($this->user))
+ ->will($this->throwException($ex));
+
+ $this->activeInitMocks($id, $type);
+
+ $response = $this->controller->active();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testActiveFolderDoesNotExist(){
+ $id = 3;
+ $type = FeedType::FOLDER;
+ $ex = new BLException('hiu');
+ $result = array(
+ 'activeFeed' => array(
+ 'id' => 0,
+ 'type' => FeedType::SUBSCRIPTIONS
+ )
+ );
+ $this->folderBl->expects($this->once())
+ ->method('find')
+ ->with($this->equalTo($id), $this->equalTo($this->user))
+ ->will($this->throwException($ex));
+
+ $this->activeInitMocks($id, $type);
+
+ $response = $this->controller->active();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testActiveActiveIsNull(){
+ $id = 3;
+ $type = null;
+ $result = array(
+ 'activeFeed' => array(
+ 'id' => 0,
+ 'type' => FeedType::SUBSCRIPTIONS
+ )
+ );
+
+ $this->activeInitMocks($id, $type);
+
+ $response = $this->controller->active();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testCreate(){
+ $result = array(
+ 'feeds' => array(new Feed())
+ );
+
+ $post = array(
+ 'url' => 'hi',
+ 'parentFolderId' => 4
+ );
+ $this->controller = $this->getPostController($post);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+
+ $this->bl->expects($this->once())
+ ->method('create')
+ ->with($this->equalTo($post['url']),
+ $this->equalTo($post['parentFolderId']),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($result['feeds'][0]));
+
+ $response = $this->controller->create();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testCreateReturnsErrorForInvalidCreate(){
+ $msg = 'except';
+ $ex = new BLException($msg);
+ $this->bl->expects($this->once())
+ ->method('create')
+ ->will($this->throwException($ex));
+
+ $response = $this->controller->create();
+ $params = json_decode($response->render(), true);
+
+ $this->assertEquals('error', $params['status']);
+ $this->assertEquals($msg, $params['msg']);
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testDelete(){
+ $url = array(
+ 'feedId' => 4
+ );
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('delete')
+ ->with($this->equalTo($url['feedId']));
+
+ $response = $this->controller->delete();
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testUpdate(){
+ $result = array(
+ 'feeds' => array(
+ new Feed()
+ )
+ );
+
+ $url = array(
+ 'feedId' => 4
+ );
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo($url['feedId']), $this->equalTo($this->user))
+ ->will($this->returnValue($result['feeds'][0]));
+
+ $response = $this->controller->update();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testMove(){
+ $post = array(
+ 'parentFolderId' => 3
+ );
+ $url = array(
+ 'feedId' => 4
+ );
+ $this->controller = $this->getPostController($post, $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('move')
+ ->with($this->equalTo($url['feedId']),
+ $this->equalTo($post['parentFolderId']),
+ $this->equalTo($this->user));
+
+ $response = $this->controller->move();
+
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+} \ No newline at end of file
diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php
new file mode 100644
index 000000000..231cc9187
--- /dev/null
+++ b/tests/unit/controller/FolderControllerTest.php
@@ -0,0 +1,260 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Controller;
+
+use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Http\JSONResponse;
+use \OCA\AppFramework\Utility\ControllerTestUtility;
+use \OCA\AppFramework\Db\DoesNotExistException;
+use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
+
+use \OCA\News\Db\Folder;
+use \OCA\News\Bl\BLException;
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class FolderControllerTest extends ControllerTestUtility {
+
+ private $api;
+ private $bl;
+ private $request;
+ private $controller;
+
+
+ /**
+ * Gets run before each test
+ */
+ public function setUp(){
+ $this->api = $this->getAPIMock();
+ $this->bl = $this->getMockBuilder('\OCA\News\Bl\FolderBl')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->request = new Request();
+ $this->controller = new FolderController($this->api, $this->request,
+ $this->bl);
+ $this->user = 'jack';
+ }
+
+
+ private function assertFolderControllerAnnotations($methodName){
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $this->assertAnnotations($this->controller, $methodName, $annotations);
+ }
+
+
+ private function getPostController($postValue, $url=array()){
+ $post = array(
+ 'post' => $postValue,
+ 'urlParams' => $url
+ );
+
+ $request = $this->getRequest($post);
+ return new FolderController($this->api, $request, $this->bl);
+ }
+
+ public function testFoldersAnnotations(){
+ $this->assertFolderControllerAnnotations('folders');
+ }
+
+
+ public function testOpenAnnotations(){
+ $this->assertFolderControllerAnnotations('open');
+ }
+
+
+ public function testCollapseAnnotations(){
+ $this->assertFolderControllerAnnotations('collapse');
+ }
+
+
+ public function testCreateAnnotations(){
+ $this->assertFolderControllerAnnotations('create');
+ }
+
+
+ public function testDeleteAnnotations(){
+ $this->assertFolderControllerAnnotations('delete');
+ }
+
+
+ public function testRenameAnnotations(){
+ $this->assertFolderControllerAnnotations('rename');
+ }
+
+
+
+ public function testFolders(){
+ $return = array(
+ new Folder(),
+ new Folder(),
+ );
+ $this->bl->expects($this->once())
+ ->method('findAll')
+ ->will($this->returnValue($return));
+
+ $response = $this->controller->folders();
+ $expected = array(
+ 'folders' => $return
+ );
+ $this->assertEquals($expected, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testOpen(){
+ $url = array('folderId' => 5);
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('open')
+ ->with($this->equalTo($url['folderId']),
+ $this->equalTo(true), $this->equalTo($this->user));
+
+ $response = $this->controller->open();
+
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testCollapse(){
+ $url = array('folderId' => 5);
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('open')
+ ->with($this->equalTo($url['folderId']),
+ $this->equalTo(false), $this->equalTo($this->user));
+
+ $response = $this->controller->collapse();
+
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testCreate(){
+ $post = array('folderName' => 'tech');
+ $this->controller = $this->getPostController($post);
+ $result = array(
+ 'folders' => array(new Folder())
+ );
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('create')
+ ->with($this->equalTo($post['folderName']),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($result['folders'][0]));
+
+ $response = $this->controller->create();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testCreateReturnsErrorForInvalidCreate(){
+ $msg = 'except';
+ $ex = new BLException($msg);
+ $this->bl->expects($this->once())
+ ->method('create')
+ ->will($this->throwException($ex));
+
+ $response = $this->controller->create();
+ $params = json_decode($response->render(), true);
+
+ $this->assertEquals('error', $params['status']);
+ $this->assertEquals($msg, $params['msg']);
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testDelete(){
+ $url = array('folderId' => 5);
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('delete')
+ ->with($this->equalTo($url['folderId']),
+ $this->equalTo($this->user));
+
+ $response = $this->controller->delete();
+
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testRename(){
+ $post = array('folderName' => 'tech');
+ $url = array('folderId' => 4);
+ $this->controller = $this->getPostController($post, $url);
+ $result = array(
+ 'folders' => array(new Folder())
+ );
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('rename')
+ ->with($this->equalTo($url['folderId']),
+ $this->equalTo($post['folderName']),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($result['folders'][0]));
+
+ $response = $this->controller->rename();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testRenameReturnsErrorForInvalidCreate(){
+ $msg = 'except';
+ $ex = new BLException($msg);
+ $this->bl->expects($this->once())
+ ->method('rename')
+ ->will($this->throwException($ex));
+
+ $response = $this->controller->rename();
+ $params = json_decode($response->render(), true);
+
+ $this->assertEquals('error', $params['status']);
+ $this->assertEquals($msg, $params['msg']);
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+} \ No newline at end of file
diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php
new file mode 100644
index 000000000..96a28da81
--- /dev/null
+++ b/tests/unit/controller/ItemControllerTest.php
@@ -0,0 +1,299 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Controller;
+
+use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Http\JSONResponse;
+use \OCA\AppFramework\Utility\ControllerTestUtility;
+
+use \OCA\News\Db\Item;
+use \OCA\News\Db\FeedType;
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class ItemControllerTest extends ControllerTestUtility {
+
+ private $api;
+ private $bl;
+ private $request;
+ private $controller;
+
+
+ /**
+ * Gets run before each test
+ */
+ public function setUp(){
+ $this->api = $this->getAPIMock();
+ $this->bl = $this->getMockBuilder('\OCA\News\Bl\ItemBl')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->request = new Request();
+ $this->controller = new ItemController($this->api, $this->request,
+ $this->bl);
+ $this->user = 'jackob';
+ }
+
+ private function getPostController($postValue, $url=array()){
+ $post = array(
+ 'post' => $postValue,
+ 'urlParams' => $url
+ );
+
+ $request = $this->getRequest($post);
+ return new ItemController($this->api, $request, $this->bl);
+ }
+
+
+ private function assertItemControllerAnnotations($methodName){
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $this->assertAnnotations($this->controller, $methodName, $annotations);
+ }
+
+ public function testItemsAnnotations(){
+ $this->assertItemControllerAnnotations('items');
+ }
+
+
+ public function testStarredAnnotations(){
+ $this->assertItemControllerAnnotations('starred');
+ }
+
+
+ public function testStarAnnotations(){
+ $this->assertItemControllerAnnotations('star');
+ }
+
+
+ public function testUnstarAnnotations(){
+ $this->assertItemControllerAnnotations('unstar');
+ }
+
+
+ public function testReadAnnotations(){
+ $this->assertItemControllerAnnotations('read');
+ }
+
+
+ public function testUnreadAnnotations(){
+ $this->assertItemControllerAnnotations('unread');
+ }
+
+
+ public function testReadFeedAnnotations(){
+ $this->assertItemControllerAnnotations('readFeed');
+ }
+
+
+ public function testRead(){
+ $url = array(
+ 'itemId' => 4
+ );
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('read')
+ ->with($url['itemId'], true, $this->user);
+
+
+ $this->controller->read();
+ }
+
+
+ public function testUnread(){
+ $url = array(
+ 'itemId' => 4
+ );
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('read')
+ ->with($url['itemId'], false, $this->user);
+
+ $this->controller->unread();
+ }
+
+
+ public function testStar(){
+ $url = array(
+ 'feedId' => 4,
+ 'guidHash' => md5('test')
+ );
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('star')
+ ->with(
+ $this->equalTo($url['feedId']),
+ $this->equalTo($url['guidHash']),
+ $this->equalTo(true),
+ $this->equalTo($this->user));
+
+ $this->controller->star();
+ }
+
+
+ public function testUnstar(){
+ $url = array(
+ 'feedId' => 4,
+ 'guidHash' => md5('test')
+ );
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('star')
+ ->with(
+ $this->equalTo($url['feedId']),
+ $this->equalTo($url['guidHash']),
+ $this->equalTo(false),
+ $this->equalTo($this->user));
+
+ $this->controller->unstar();
+ }
+
+
+ public function testReadFeed(){
+ $url = array(
+ 'feedId' => 4
+ );
+ $post = array(
+ 'highestItemId' => 5
+ );
+ $this->controller = $this->getPostController($post, $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('readFeed')
+ ->with($url['feedId'], $post['highestItemId'], $this->user);
+
+ $this->controller->readFeed();
+ }
+
+
+ public function testStarred(){
+ $result = array(
+ 'starred' => 3
+ );
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('starredCount')
+ ->with($this->user)
+ ->will($this->returnValue($result['starred']));
+ $response = $this->controller->starred();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+
+ private function itemsApiExpects($id, $type){
+ $this->api->expects($this->once())
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo('showAll'))
+ ->will($this->returnValue('true'));
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->api->expects($this->at(2))
+ ->method('setUserValue')
+ ->with($this->equalTo('lastViewedFeedId'),
+ $this->equalTo($id));
+ $this->api->expects($this->at(3))
+ ->method('setUserValue')
+ ->with($this->equalTo('lastViewedFeedType'),
+ $this->equalTo($type));
+ }
+
+
+ public function testItems(){
+ $result = array(
+ 'items' => array(new Item())
+ );
+ $post = array(
+ 'limit' => 3,
+ 'type' => FeedType::FEED,
+ 'id' => 2,
+ 'offset' => 0
+ );
+ $this->controller = $this->getPostController($post);
+
+ $this->itemsApiExpects($post['id'], $post['type']);
+
+ $this->bl->expects($this->once())
+ ->method('findAll')
+ ->with($post['id'], $post['type'], $post['limit'],
+ $post['offset'], true, $this->user)
+ ->will($this->returnValue($result['items']));
+
+ $response = $this->controller->items();
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testItemsNew(){
+ $result = array(
+ 'items' => array(new Item())
+ );
+ $post = array(
+ 'type' => FeedType::FEED,
+ 'id' => 2,
+ 'updatedSince' => 3333
+ );
+ $this->controller = $this->getPostController($post);
+
+ $this->itemsApiExpects($post['id'], $post['type']);
+
+ $this->bl->expects($this->once())
+ ->method('findAllNew')
+ ->with($post['id'], $post['type'], $post['updatedSince'],
+ true, $this->user)
+ ->will($this->returnValue($result['items']));
+
+ $response = $this->controller->items();
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+} \ No newline at end of file
diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php
new file mode 100644
index 000000000..d4f7e1097
--- /dev/null
+++ b/tests/unit/controller/PageControllerTest.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have rece