This commit is contained in:
Bernhard Posselt 2013-03-22 22:29:58 +01:00
Родитель 452d91ee39
Коммит 80644c69e0
2 изменённых файлов: 148 добавлений и 6 удалений

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}