summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-22 23:04:44 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-22 23:04:44 +0100
commit46cbbb1a1e89f5302e1a33f81b8526e039894c60 (patch)
tree48401178b23912438e39ca64e3973078676d192e
parent80644c69e096e272184b729071d8a41a3d31b79c (diff)
finished usersettingscontroller
-rw-r--r--controller/itemcontroller.php2
-rw-r--r--controller/usersettingscontroller.php15
-rw-r--r--dependencyinjection/dicontainer.php3
-rw-r--r--tests/controller/UserSettingsControllerTest.php46
4 files changed, 61 insertions, 5 deletions
diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php
index 62a65a86e..1dbf7c43e 100644
--- a/controller/itemcontroller.php
+++ b/controller/itemcontroller.php
@@ -48,7 +48,7 @@ class ItemController extends Controller {
* @Ajax
*/
public function items(){
-
+ // TBD
}
diff --git a/controller/usersettingscontroller.php b/controller/usersettingscontroller.php
index 7bdcda51d..9900d98d8 100644
--- a/controller/usersettingscontroller.php
+++ b/controller/usersettingscontroller.php
@@ -44,7 +44,14 @@ class UserSettingsController extends Controller {
* @Ajax
*/
public function read(){
-
+ $userId = $this->api->getUserId();
+ $showAll = $this->api->getUserValue($userId, 'showAll');
+
+ $params = array(
+ 'showAll' => $showAll === 'true'
+ );
+
+ return $this->renderJSON($params);
}
@@ -54,7 +61,8 @@ class UserSettingsController extends Controller {
* @Ajax
*/
public function show(){
-
+ $userId = $this->api->getUserId();
+ $this->api->setUserValue($userId, 'showAll', true);
}
@@ -64,7 +72,8 @@ class UserSettingsController extends Controller {
* @Ajax
*/
public function hide(){
-
+ $userId = $this->api->getUserId();
+ $this->api->setUserValue($userId, 'showAll', false);
}
diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php
index a199bfc4a..1a4535920 100644
--- a/dependencyinjection/dicontainer.php
+++ b/dependencyinjection/dicontainer.php
@@ -82,7 +82,8 @@ class DIContainer extends BaseContainer {
});
$this['UserSettingsController'] = $this->share(function($c){
- return new UserSettingsController($c['API'], $c['Request']);
+ return new UserSettingsController($c['API'], $c['Request'],
+ $c['ItemBl']);
});
/**
diff --git a/tests/controller/UserSettingsControllerTest.php b/tests/controller/UserSettingsControllerTest.php
index b434c5ffa..4b561a3e4 100644
--- a/tests/controller/UserSettingsControllerTest.php
+++ b/tests/controller/UserSettingsControllerTest.php
@@ -49,6 +49,7 @@ class UserSettingsControllerTest extends ControllerTestUtility {
$this->api = $this->getAPIMock();
$this->request = new Request();
$this->controller = new UserSettingsController($this->api, $this->request);
+ $this->user = 'becka';
}
@@ -73,6 +74,51 @@ class UserSettingsControllerTest extends ControllerTestUtility {
}
+ public function testShow(){
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->api->expects($this->once())
+ ->method('setUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo('showAll'),
+ $this->equalTo(true));
+ $result = $this->controller->show();
+ }
+
+
+ public function testHide(){
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->api->expects($this->once())
+ ->method('setUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo('showAll'),
+ $this->equalTo(false));
+ $result = $this->controller->hide();
+ }
+
+
+ public function testRead(){
+ $result = array(
+ 'showAll' => true
+ );
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->api->expects($this->once())
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo('showAll'))
+ ->will($this->returnValue('true'));
+
+ $response = $this->controller->read();
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
} \ No newline at end of file