. * */ namespace OCA\News\External; use \OCA\AppFramework\Http\JSONResponse; use \OCA\AppFramework\Utility\ControllerTestUtility; require_once(__DIR__ . "/../../classloader.php"); class NewsAPITest extends ControllerTestUtility { private $api; private $request; private $newsAPI; private $updater; protected function setUp() { $this->api = $this->getMockBuilder( '\OCA\AppFramework\Core\API') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( '\OCA\AppFramework\Http\Request') ->disableOriginalConstructor() ->getMock(); $this->updater = $this->getMockBuilder( '\OCA\News\Utility\Updater') ->disableOriginalConstructor() ->getMock(); $this->newsAPI = new NewsAPI($this->api, $this->request, $this->updater); } private function assertDefaultAnnotations($methodName){ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax', 'CSRFExemption', 'API'); $this->assertAnnotations($this->newsAPI, $methodName, $annotations); } public function testVersionAnnotations(){ $this->assertDefaultAnnotations('version'); } public function testCleanUpAnnotations(){ $annotations = array('Ajax', 'CSRFExemption', 'API'); $this->assertAnnotations($this->newsAPI, 'cleanUp', $annotations); } public function testGetVersion(){ $this->api->expects($this->once()) ->method('getAppValue') ->with($this->equalTo('installed_version')) ->will($this->returnValue('1.0')); $response = $this->newsAPI->version(); $data = $response->getData(); $version = $data['version']; $this->assertEquals('1.0', $version); } public function testCleanUp(){ $this->updater->expects($this->once()) ->method('cleanUp'); $this->newsAPI->cleanUp(); } public function testCorsAnnotations(){ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax', 'CSRFExemption', 'IsLoggedInExemption'); $this->assertAnnotations($this->newsAPI, 'cors', $annotations); } public function testCors() { $response = $this->newsAPI->cors(); $headers = $response->getHeaders(); $this->assertEquals('*', $headers['Access-Control-Allow-Origin']); $this->assertEquals('PUT, POST, GET, DELETE', $headers['Access-Control-Allow-Methods']); $this->assertEquals('true', $headers['Access-Control-Allow-Credentials']); } }