. * */ 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 testGetLanguageAnnotations(){ $this->assertUserSettingsControllerAnnotations('getLanguage'); } 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('setUserValue') ->with($this->equalTo('showAll'), $this->equalTo(true)); $response = $this->controller->show(); $this->assertTrue($response instanceof JSONResponse); } public function testHide(){ $this->api->expects($this->once()) ->method('setUserValue') ->with($this->equalTo('showAll'), $this->equalTo(false)); $response = $this->controller->hide(); $this->assertTrue($response instanceof JSONResponse); } public function testRead(){ $result = array( 'showAll' => true ); $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); } public function testGetLanguage(){ $language = 'de'; $lang = $this->getMock('Lang', array('findLanguage')); $lang->expects($this->once()) ->method('findLanguage') ->will($this->returnValue($language)); $this->api->expects($this->once()) ->method('getTrans') ->will($this->returnValue($lang)); $response = $this->controller->getLanguage(); $params = $response->getParams(); $this->assertEquals($language, $params['language']); $this->assertTrue($response instanceof JSONResponse); } }