aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/appframework/controller
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2016-05-20 15:38:20 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-05-20 15:38:20 +0200
commit94ad54ec9b96d41a614fbbad4a97b34c41a6901f (patch)
treef3eb7cdda2704aaf0cd59d58efe66bcbd34cb67d /tests/lib/appframework/controller
parent2ef751b1ec28f7b5c7113af60ec8c9fa0ae1cf87 (diff)
downloadnextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.tar.gz
nextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.zip
Move tests/ to PSR-4 (#24731)
* Move a-b to PSR-4 * Move c-d to PSR-4 * Move e+g to PSR-4 * Move h-l to PSR-4 * Move m-r to PSR-4 * Move s-u to PSR-4 * Move files/ to PSR-4 * Move remaining tests to PSR-4 * Remove Test\ from old autoloader
Diffstat (limited to 'tests/lib/appframework/controller')
-rw-r--r--tests/lib/appframework/controller/ApiControllerTest.php58
-rw-r--r--tests/lib/appframework/controller/ControllerTest.php226
-rw-r--r--tests/lib/appframework/controller/OCSControllerTest.php148
3 files changed, 0 insertions, 432 deletions
diff --git a/tests/lib/appframework/controller/ApiControllerTest.php b/tests/lib/appframework/controller/ApiControllerTest.php
deleted file mode 100644
index 783eecf93e5..00000000000
--- a/tests/lib/appframework/controller/ApiControllerTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-/**
- * ownCloud - App Framework
- *
- * @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-namespace Test\AppFramework\Controller;
-
-use OC\AppFramework\Http\Request;
-use OCP\AppFramework\ApiController;
-
-
-class ChildApiController extends ApiController {};
-
-
-class ApiControllerTest extends \Test\TestCase {
- /** @var ChildApiController */
- protected $controller;
-
- public function testCors() {
- $request = new Request(
- ['server' => ['HTTP_ORIGIN' => 'test']],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
- );
- $this->controller = new ChildApiController('app', $request, 'verbs',
- 'headers', 100);
-
- $response = $this->controller->preflightedCors();
-
- $headers = $response->getHeaders();
-
- $this->assertEquals('test', $headers['Access-Control-Allow-Origin']);
- $this->assertEquals('verbs', $headers['Access-Control-Allow-Methods']);
- $this->assertEquals('headers', $headers['Access-Control-Allow-Headers']);
- $this->assertEquals('false', $headers['Access-Control-Allow-Credentials']);
- $this->assertEquals(100, $headers['Access-Control-Max-Age']);
- }
-
-}
diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php
deleted file mode 100644
index 521799a46ce..00000000000
--- a/tests/lib/appframework/controller/ControllerTest.php
+++ /dev/null
@@ -1,226 +0,0 @@
-<?php
-
-/**
- * ownCloud - App Framework
- *
- * @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-namespace Test\AppFramework\Controller;
-
-use OC\AppFramework\Http\Request;
-use OCP\AppFramework\Controller;
-use OCP\AppFramework\Http\TemplateResponse;
-use OCP\AppFramework\Http\JSONResponse;
-use OCP\AppFramework\Http\DataResponse;
-
-
-class ChildController extends Controller {
-
- public function __construct($appName, $request) {
- parent::__construct($appName, $request);
- $this->registerResponder('tom', function ($respone) {
- return 'hi';
- });
- }
-
- public function custom($in) {
- $this->registerResponder('json', function ($response) {
- return new JSONResponse(array(strlen($response)));
- });
-
- return $in;
- }
-
- public function customDataResponse($in) {
- $response = new DataResponse($in, 300);
- $response->addHeader('test', 'something');
- return $response;
- }
-};
-
-class ControllerTest extends \Test\TestCase {
-
- /**
- * @var Controller
- */
- private $controller;
- private $app;
-
- protected function setUp(){
- parent::setUp();
-
- $request = new Request(
- [
- 'get' => ['name' => 'John Q. Public', 'nickname' => 'Joey'],
- 'post' => ['name' => 'Jane Doe', 'nickname' => 'Janey'],
- 'urlParams' => ['name' => 'Johnny Weissmüller'],
- 'files' => ['file' => 'filevalue'],
- 'env' => ['PATH' => 'daheim'],
- 'session' => ['sezession' => 'kein'],
- 'method' => 'hi',
- ],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
- );
-
- $this->app = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer',
- array('getAppName'), array('test'));
- $this->app->expects($this->any())
- ->method('getAppName')
- ->will($this->returnValue('apptemplate_advanced'));
-
- $this->controller = new ChildController($this->app, $request);
- }
-
-
- public function testParamsGet(){
- $this->assertEquals('Johnny Weissmüller', $this->controller->params('name', 'Tarzan'));
- }
-
-
- public function testParamsGetDefault(){
- $this->assertEquals('Tarzan', $this->controller->params('Ape Man', 'Tarzan'));
- }
-
-
- public function testParamsFile(){
- $this->assertEquals('filevalue', $this->controller->params('file', 'filevalue'));
- }
-
-
- public function testGetUploadedFile(){
- $this->assertEquals('filevalue', $this->controller->getUploadedFile('file'));
- }
-
-
-
- public function testGetUploadedFileDefault(){
- $this->assertEquals('default', $this->controller->params('files', 'default'));
- }
-
-
- public function testGetParams(){
- $params = array(
- 'name' => 'Johnny Weissmüller',
- 'nickname' => 'Janey',
- );
-
- $this->assertEquals($params, $this->controller->getParams());
- }
-
-
- public function testRender(){
- $this->assertTrue($this->controller->render('') instanceof TemplateResponse);
- }
-
-
- public function testSetParams(){
- $params = array('john' => 'foo');
- $response = $this->controller->render('home', $params);
-
- $this->assertEquals($params, $response->getParams());
- }
-
-
- public function testRenderHeaders(){
- $headers = array('one', 'two');
- $response = $this->controller->render('', array(), '', $headers);
-
- $this->assertTrue(in_array($headers[0], $response->getHeaders()));
- $this->assertTrue(in_array($headers[1], $response->getHeaders()));
- }
-
-
- public function testGetRequestMethod(){
- $this->assertEquals('hi', $this->controller->method());
- }
-
-
- public function testGetEnvVariable(){
- $this->assertEquals('daheim', $this->controller->env('PATH'));
- }
-
-
- /**
- * @expectedException \DomainException
- */
- public function testFormatResonseInvalidFormat() {
- $this->controller->buildResponse(null, 'test');
- }
-
-
- public function testFormat() {
- $response = $this->controller->buildResponse(array('hi'), 'json');
-
- $this->assertEquals(array('hi'), $response->getData());
- }
-
-
- public function testFormatDataResponseJSON() {
- $expectedHeaders = [
- 'test' => 'something',
- 'Cache-Control' => 'no-cache, must-revalidate',
- 'Content-Type' => 'application/json; charset=utf-8',
- 'Content-Security-Policy' => "default-src 'none';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self';connect-src 'self';media-src 'self'",
- ];
-
- $response = $this->controller->customDataResponse(array('hi'));
- $response = $this->controller->buildResponse($response, 'json');
-
- $this->assertEquals(array('hi'), $response->getData());
- $this->assertEquals(300, $response->getStatus());
- $this->assertEquals($expectedHeaders, $response->getHeaders());
- }
-
-
- public function testCustomFormatter() {
- $response = $this->controller->custom('hi');
- $response = $this->controller->buildResponse($response, 'json');
-
- $this->assertEquals(array(2), $response->getData());
- }
-
-
- public function testDefaultResponderToJSON() {
- $responder = $this->controller->getResponderByHTTPHeader('*/*');
-
- $this->assertEquals('json', $responder);
- }
-
-
- public function testResponderAcceptHeaderParsed() {
- $responder = $this->controller->getResponderByHTTPHeader(
- '*/*, application/tom, application/json'
- );
-
- $this->assertEquals('tom', $responder);
- }
-
-
- public function testResponderAcceptHeaderParsedUpperCase() {
- $responder = $this->controller->getResponderByHTTPHeader(
- '*/*, apPlication/ToM, application/json'
- );
-
- $this->assertEquals('tom', $responder);
- }
-
-
-}
diff --git a/tests/lib/appframework/controller/OCSControllerTest.php b/tests/lib/appframework/controller/OCSControllerTest.php
deleted file mode 100644
index f69740d4496..00000000000
--- a/tests/lib/appframework/controller/OCSControllerTest.php
+++ /dev/null
@@ -1,148 +0,0 @@
-<?php
-
-/**
- * ownCloud - App Framework
- *
- * @author Bernhard Posselt
- * @copyright 2015 Bernhard Posselt <dev@bernhard-posselt.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-namespace Test\AppFramework\Controller;
-
-use OC\AppFramework\Http\Request;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\OCSController;
-
-
-class ChildOCSController extends OCSController {}
-
-
-class OCSControllerTest extends \Test\TestCase {
-
- private $controller;
-
- public function testCors() {
- $request = new Request(
- [
- 'server' => [
- 'HTTP_ORIGIN' => 'test',
- ],
- ],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
- );
- $controller = new ChildOCSController('app', $request, 'verbs',
- 'headers', 100);
-
- $response = $controller->preflightedCors();
-
- $headers = $response->getHeaders();
-
- $this->assertEquals('test', $headers['Access-Control-Allow-Origin']);
- $this->assertEquals('verbs', $headers['Access-Control-Allow-Methods']);
- $this->assertEquals('headers', $headers['Access-Control-Allow-Headers']);
- $this->assertEquals('false', $headers['Access-Control-Allow-Credentials']);
- $this->assertEquals(100, $headers['Access-Control-Max-Age']);
- }
-
-
- public function testXML() {
- $controller = new ChildOCSController('app', new Request(
- [],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
- ));
- $expected = "<?xml version=\"1.0\"?>\n" .
- "<ocs>\n" .
- " <meta>\n" .
- " <status>failure</status>\n" .
- " <statuscode>400</statuscode>\n" .
- " <message>OK</message>\n" .
- " <totalitems></totalitems>\n" .
- " <itemsperpage></itemsperpage>\n" .
- " </meta>\n" .
- " <data>\n" .
- " <test>hi</test>\n" .
- " </data>\n" .
- "</ocs>\n";
-
- $params = [
- 'data' => [
- 'test' => 'hi'
- ],
- 'statuscode' => 400
- ];
-
- $out = $controller->buildResponse($params, 'xml')->render();
- $this->assertEquals($expected, $out);
- }
-
-
- public function testXMLDataResponse() {
- $controller = new ChildOCSController('app', new Request(
- [],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
- ));
- $expected = "<?xml version=\"1.0\"?>\n" .
- "<ocs>\n" .
- " <meta>\n" .
- " <status>failure</status>\n" .
- " <statuscode>400</statuscode>\n" .
- " <message>OK</message>\n" .
- " <totalitems></totalitems>\n" .
- " <itemsperpage></itemsperpage>\n" .
- " </meta>\n" .
- " <data>\n" .
- " <test>hi</test>\n" .
- " </data>\n" .
- "</ocs>\n";
-
- $params = new DataResponse([
- 'data' => [
- 'test' => 'hi'
- ],
- 'statuscode' => 400
- ]);
-
- $out = $controller->buildResponse($params, 'xml')->render();
- $this->assertEquals($expected, $out);
- }
-
-
- public function testJSON() {
- $controller = new ChildOCSController('app', new Request(
- [],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
- ));
- $expected = '{"ocs":{"meta":{"status":"failure","statuscode":400,"message":"OK",' .
- '"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}';
- $params = [
- 'data' => [
- 'test' => 'hi'
- ],
- 'statuscode' => 400
- ];
-
- $out = $controller->buildResponse($params, 'json')->render();
- $this->assertEquals($expected, $out);
- }
-
-
-}