. * */ 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 UserSettingsControllerTest 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 UserSettingsController($this->api, $this->request); $this->user = 'becka'; } private function assertUserSettingsControllerAnnotations($methodName){ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax'); $this->assertAnnotations($this->controller, $methodName, $annotations); } public function testFoldersAnnotations(){ $this->assertUserSettingsControllerAnnotations('read'); } public function testOpenAnnotations(){ $this->assertUserSettingsControllerAnnotations('show'); } public function testCollapseAnnotations(){ $this->assertUserSettingsControllerAnnotations('hide'); } 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('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('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('showAll')) ->will($this->returnValue('1')); $response = $this->controller->read(); $this->assertEquals($result, $response->getParams()); $this->assertTrue($response instanceof JSONResponse); } }