summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controller/itemcontroller.php38
-rw-r--r--tests/controller/ItemControllerTest.php116
2 files changed, 148 insertions, 6 deletions
diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php
index d4cf44de9..62a65a86e 100644
--- a/controller/itemcontroller.php
+++ b/controller/itemcontroller.php
@@ -58,17 +58,31 @@ class ItemController extends Controller {
* @Ajax
*/
public function starred(){
-
+ $userId = $this->api->getUserId();
+ $starredCount = $this->itemBl->starredCount($userId);
+
+ $params = array(
+ 'starred' => $starredCount
+ );
+
+ return $this->renderJSON($params);
}
+ private function setStarred($isStarred){
+ $userId = $this->api->getUserId();
+ $itemId = $this->params('itemId');
+
+ $this->itemBl->star($itemId, $isStarred, $userId);
+ }
+
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
public function star(){
-
+ $this->setStarred(true);
}
@@ -78,17 +92,24 @@ class ItemController extends Controller {
* @Ajax
*/
public function unstar(){
-
+ $this->setStarred(false);
}
+ private function setRead($isRead){
+ $userId = $this->api->getUserId();
+ $itemId = $this->params('itemId');
+
+ $this->itemBl->read($itemId, $isRead, $userId);
+ }
+
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
public function read(){
-
+ $this->setRead(true);
}
@@ -98,7 +119,7 @@ class ItemController extends Controller {
* @Ajax
*/
public function unread(){
-
+ $this->setRead(false);
}
@@ -108,6 +129,11 @@ class ItemController extends Controller {
* @Ajax
*/
public function readFeed(){
-
+ $userId = $this->api->getUserId();
+ $feedId = $this->params('feedId');
+
+ $this->itemBl->readFeed($feedId, $userId);
}
+
+
} \ No newline at end of file
diff --git a/tests/controller/ItemControllerTest.php b/tests/controller/ItemControllerTest.php
index 8e816e125..4f7fe564a 100644
--- a/tests/controller/ItemControllerTest.php
+++ b/tests/controller/ItemControllerTest.php
@@ -56,8 +56,20 @@ class ItemControllerTest extends ControllerTestUtility {
$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);
@@ -97,4 +109,108 @@ class ItemControllerTest extends ControllerTestUtility {
$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(
+ '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('star')
+ ->with($url['itemId'], true, $this->user);
+
+ $this->controller->star();
+ }
+
+
+ public function testUnstar(){
+ $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('star')
+ ->with($url['itemId'], false, $this->user);
+
+ $this->controller->unstar();
+ }
+
+
+ public function testReadFeed(){
+ $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('readFeed')
+ ->with($url['feedId'], $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);
+ }
+
} \ No newline at end of file