summaryrefslogtreecommitdiffstats
path: root/tests/unit/controller/ItemControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/controller/ItemControllerTest.php')
-rw-r--r--tests/unit/controller/ItemControllerTest.php234
1 files changed, 51 insertions, 183 deletions
diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php
index 15701bd6d..7017d52e4 100644
--- a/tests/unit/controller/ItemControllerTest.php
+++ b/tests/unit/controller/ItemControllerTest.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\Item;
use \OCA\News\Db\Feed;
use \OCA\News\Db\FeedType;
@@ -25,7 +23,7 @@ use \OCA\News\BusinessLayer\BusinessLayerException;
require_once(__DIR__ . "/../../classloader.php");
-class ItemControllerTest extends ControllerTestUtility {
+class ItemControllerTest extends \PHPUnit_Framework_TestCase {
private $appName;
private $settings;
@@ -54,233 +52,141 @@ class ItemControllerTest extends ControllerTestUtility {
$this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer')
->disableOriginalConstructor()
->getMock();
- $this->request = $this->getRequest();
+ $this->request = $this->getMockBuilder(
+ '\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->controller = new ItemController($this->appName, $this->request,
$this->feedBusinessLayer, $this->itemBusinessLayer, $this->settings,
$this->user);
$this->newestItemId = 12312;
}
- private function getPostController($postValue, $url=array()){
- $post = array(
- 'post' => $postValue,
- 'urlParams' => $url
- );
-
- $request = $this->getRequest($post);
- return new ItemController($this->appName, $request,
- $this->feedBusinessLayer, $this->itemBusinessLayer, $this->settings,
- $this->user);
- }
-
-
- private function assertItemControllerAnnotations($methodName){
- $annotations = array('NoAdminRequired');
- $this->assertAnnotations($this->controller, $methodName, $annotations);
- }
-
-
- public function testItemsAnnotations(){
- $this->assertItemControllerAnnotations('index');
- }
-
-
- public function testNewItemsAnnotations(){
- $this->assertItemControllerAnnotations('newItems');
- }
-
- 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 testReadAllAnnotations(){
- $this->assertItemControllerAnnotations('readAll');
- }
-
public function testRead(){
- $url = array(
- 'itemId' => 4
- );
- $this->controller = $this->getPostController(array(), $url);
-
$this->itemBusinessLayer->expects($this->once())
->method('read')
- ->with($url['itemId'], true, $this->user);
+ ->with(4, true, $this->user);
- $this->controller->read();
+ $this->controller->read(4);
}
public function testReadDoesNotExist(){
- $url = array(
- 'itemId' => 4
- );
$msg = 'hi';
- $this->controller = $this->getPostController(array(), $url);
$this->itemBusinessLayer->expects($this->once())
->method('read')
->will($this->throwException(new BusinessLayerException($msg)));
-
- $response = $this->controller->read();
+ $response = $this->controller->read(4);
$params = json_decode($response->render(), true);
$this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND);
- $this->assertEquals($msg, $params['msg']);
+ $this->assertEquals($msg, $params['message']);
}
public function testUnread(){
- $url = array(
- 'itemId' => 4
- );
- $this->controller = $this->getPostController(array(), $url);
-
$this->itemBusinessLayer->expects($this->once())
->method('read')
- ->with($url['itemId'], false, $this->user);
+ ->with(4, false, $this->user);
- $this->controller->unread();
+ $this->controller->unread(4);
}
public function testUnreadDoesNotExist(){
- $url = array(
- 'itemId' => 4
- );
$msg = 'hi';
- $this->controller = $this->getPostController(array(), $url);
$this->itemBusinessLayer->expects($this->once())
->method('read')
->will($this->throwException(new BusinessLayerException($msg)));
- $response = $this->controller->unread();
+ $response = $this->controller->unread(4);
$params = json_decode($response->render(), true);
$this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND);
- $this->assertEquals($msg, $params['msg']);
+ $this->assertEquals($msg, $params['message']);
}
public function testStar(){
- $url = array(
- 'feedId' => 4,
- 'guidHash' => md5('test')
- );
- $this->controller = $this->getPostController(array(), $url);
-
$this->itemBusinessLayer->expects($this->once())
->method('star')
->with(
- $this->equalTo($url['feedId']),
- $this->equalTo($url['guidHash']),
+ $this->equalTo(4),
+ $this->equalTo('test'),
$this->equalTo(true),
$this->equalTo($this->user));
- $this->controller->star();
+ $this->controller->star(4, 'test');
}
public function testStarDoesNotExist(){
- $url = array(
- 'feedId' => 4,
- 'guidHash' => md5('test')
- );
$msg = 'ho';
- $this->controller = $this->getPostController(array(), $url);
$this->itemBusinessLayer->expects($this->once())
->method('star')
->will($this->throwException(new BusinessLayerException($msg)));;
- $response = $this->controller->star();
+ $response = $this->controller->star(4, 'test');
$params = json_decode($response->render(), true);
$this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND);
- $this->assertEquals($msg, $params['msg']);
+ $this->assertEquals($msg, $params['message']);
}
public function testUnstar(){
- $url = array(
- 'feedId' => 4,
- 'guidHash' => md5('test')
- );
- $this->controller = $this->getPostController(array(), $url);
-
$this->itemBusinessLayer->expects($this->once())
->method('star')
->with(
- $this->equalTo($url['feedId']),
- $this->equalTo($url['guidHash']),
+ $this->equalTo(4),
+ $this->equalTo('test'),
$this->equalTo(false),
$this->equalTo($this->user));
- $this->controller->unstar();
+ $this->controller->unstar(4, 'test');
}
public function testUnstarDoesNotExist(){
- $url = array(
- 'feedId' => 4,
- 'guidHash' => md5('test')
- );
$msg = 'ho';
- $this->controller = $this->getPostController(array(), $url);
$this->itemBusinessLayer->expects($this->once())
->method('star')
->will($this->throwException(new BusinessLayerException($msg)));;
- $response = $this->controller->unstar();
+ $response = $this->controller->unstar(4, 'test');
$params = json_decode($response->render(), true);
$this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND);
- $this->assertEquals($msg, $params['msg']);
+ $this->assertEquals($msg, $params['message']);
}
public function testReadAll(){
$feed = new Feed();
- $post = array(
- 'highestItemId' => 5
- );
- $this->controller = $this->getPostController($post);
+
$expected = array(
'feeds' => array($feed)
);
$this->itemBusinessLayer->expects($this->once())
->method('readAll')
- ->with($this->equalTo($post['highestItemId']),
+ ->with($this->equalTo(5),
$this->equalTo($this->user));
$this->feedBusinessLayer->expects($this->once())
->method('findAll')
->with($this->equalTo($this->user))
->will($this->returnValue(array($feed)));
- $response = $this->controller->readAll();
- $this->assertEquals($expected, $response->getData());
+ $response = $this->controller->readAll(5);
+ $this->assertEquals($expected, $response);
}
@@ -314,15 +220,8 @@ class ItemControllerTest extends ControllerTestUtility {
'newestItemId' => $this->newestItemId,
'starred' => 3111
);
- $post = array(
- 'limit' => 3,
- 'type' => FeedType::FEED,
- 'id' => 2,
- 'offset' => 0,
- );
- $this->controller = $this->getPostController($post);
- $this->itemsApiExpects($post['id'], $post['type']);
+ $this->itemsApiExpects(2, FeedType::FEED);
$this->feedBusinessLayer->expects($this->once())
->method('findAll')
@@ -342,16 +241,16 @@ class ItemControllerTest extends ControllerTestUtility {
$this->itemBusinessLayer->expects($this->once())
->method('findAll')
->with(
- $this->equalTo($post['id']),
- $this->equalTo($post['type']),
- $this->equalTo($post['limit']),
- $this->equalTo($post['offset']),
+ $this->equalTo(2),
+ $this->equalTo(FeedType::FEED),
+ $this->equalTo(3),
+ $this->equalTo(0),
$this->equalTo(true),
$this->equalTo($this->user))
->will($this->returnValue($result['items']));
- $response = $this->controller->index();
- $this->assertEquals($result, $response->getData());
+ $response = $this->controller->index(FeedType::FEED, 2, 3);
+ $this->assertEquals($result, $response);
}
@@ -359,22 +258,15 @@ class ItemControllerTest extends ControllerTestUtility {
$result = array(
'items' => array(new Item())
);
- $post = array(
- 'limit' => 3,
- 'type' => FeedType::FEED,
- 'id' => 2,
- 'offset' => 10,
- );
- $this->controller = $this->getPostController($post);
- $this->itemsApiExpects($post['id'], $post['type']);
+ $this->itemsApiExpects(2, FeedType::FEED);
$this->itemBusinessLayer->expects($this->once())
->method('findAll')
- ->with($this->equalTo($post['id']),
- $this->equalTo($post['type']),
- $this->equalTo($post['limit']),
- $this->equalTo($post['offset']),
+ ->with($this->equalTo(2),
+ $this->equalTo(FeedType::FEED),
+ $this->equalTo(3),
+ $this->equalTo(10),
$this->equalTo(true),
$this->equalTo($this->user))
->will($this->returnValue($result['items']));
@@ -382,31 +274,21 @@ class ItemControllerTest extends ControllerTestUtility {
$this->feedBusinessLayer->expects($this->never())
->method('findAll');
- $response = $this->controller->index();
- $this->assertEquals($result, $response->getData());
+ $response = $this->controller->index(FeedType::FEED, 2, 3, 10);
+ $this->assertEquals($result, $response);
}
public function testGetItemsNoNewestItemsId(){
- $result = array();
- $post = array(
- 'limit' => 3,
- 'type' => FeedType::FEED,
- 'id' => 2,
- 'offset' => 0,
- 'newestItemId' => 3
- );
- $this->controller = $this->getPostController($post);
-
- $this->itemsApiExpects($post['id'], $post['type']);
+ $this->itemsApiExpects(2, FeedType::FEED);
$this->itemBusinessLayer->expects($this->once())
->method('getNewestItemId')
->with($this->equalTo($this->user))
->will($this->throwException(new BusinessLayerException('')));
- $response = $this->controller->index();
- $this->assertEquals($result, $response->getData());
+ $response = $this->controller->index(FeedType::FEED, 2, 3);
+ $this->assertEquals(array(), $response);
}
@@ -418,12 +300,6 @@ class ItemControllerTest extends ControllerTestUtility {
'newestItemId' => $this->newestItemId,
'starred' => 3111
);
- $post = array(
- 'lastModified' => 3,
- 'type' => FeedType::FEED,
- 'id' => 2
- );
- $this->controller = $this->getPostController($post);
$this->settings->expects($this->once())
->method('getUserValue')
@@ -450,27 +326,19 @@ class ItemControllerTest extends ControllerTestUtility {
$this->itemBusinessLayer->expects($this->once())
->method('findAllNew')
->with(
- $this->equalTo($post['id']),
- $this->equalTo($post['type']),
- $this->equalTo($post['lastModified']),
+ $this->equalTo(2),
+ $this->equalTo(FeedType::FEED),
+ $this->equalTo(3),
$this->equalTo(true),
$this->equalTo($this->user))
->will($this->returnValue($result['items']));
- $response = $this->controller->newItems();
- $this->assertEquals($result, $response->getData());
+ $response = $this->controller->newItems(FeedType::FEED, 2, 3);
+ $this->assertEquals($result, $response);
}
public function testGetNewItemsNoNewestItemsId(){
- $result = array();
- $post = array(
- 'lastModified' => 3,
- 'type' => FeedType::FEED,
- 'id' => 2
- );
- $this->controller = $this->getPostController($post);
-
$this->settings->expects($this->once())
->method('getUserValue')
->with($this->equalTo($this->user),
@@ -483,8 +351,8 @@ class ItemControllerTest extends ControllerTestUtility {
->with($this->equalTo($this->user))
->will($this->throwException(new BusinessLayerException('')));
- $response = $this->controller->newItems();
- $this->assertEquals($result, $response->getData());
+ $response = $this->controller->newItems(FeedType::FEED, 2, 3);
+ $this->assertEquals(array(), $response);
}