diff options
author | Joas Schilling <coding@schilljs.com> | 2016-08-17 10:23:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-17 10:23:13 +0200 |
commit | 027069cbae9e67a205c77095be09bac9a75bfa2a (patch) | |
tree | 78a2af1e3e7d8f2b9038a3d64a309303f3804610 /tests | |
parent | c1632c3abd0f136b4ecb8d7a5bef5c3c72f9cb95 (diff) | |
parent | 77542817d1bfb260c4bff74f77b9507b699f1d76 (diff) | |
download | nextcloud-server-027069cbae9e67a205c77095be09bac9a75bfa2a.tar.gz nextcloud-server-027069cbae9e67a205c77095be09bac9a75bfa2a.zip |
Merge pull request #846 from nextcloud/provisioning_api_ocs
Move Provisioning API to the AppFramework
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php | 76 |
1 files changed, 70 insertions, 6 deletions
diff --git a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php index 7d8cadc677f..b2295fdc26d 100644 --- a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php @@ -27,14 +27,14 @@ use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSNotFoundException; -use OC\AppFramework\Http\Request; +use OCP\IRequest; use OC\AppFramework\Middleware\OCSMiddleware; class OCSMiddlewareTest extends \Test\TestCase { /** - * @var Request + * @var IRequest */ private $request; @@ -101,8 +101,18 @@ class OCSMiddlewareTest extends \Test\TestCase { $this->assertInstanceOf('OCP\AppFramework\Http\OCSResponse', $result); $this->assertSame($message, $this->invokePrivate($result, 'message')); - $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); - $this->assertSame(200, $result->getStatus()); + + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $this->invokePrivate($result, 'statuscode')); + } else { + $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); + } + + if ($exception instanceof OCSForbiddenException) { + $this->assertSame(Http::STATUS_UNAUTHORIZED, $result->getStatus()); + } else { + $this->assertSame(200, $result->getStatus()); + } } catch (\Exception $e) { $this->assertTrue($forward); $this->assertEquals($exception, $e); @@ -131,7 +141,11 @@ class OCSMiddlewareTest extends \Test\TestCase { $this->assertInstanceOf('OCP\AppFramework\Http\OCSResponse', $result); $this->assertSame($message, $this->invokePrivate($result, 'message')); - $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $this->invokePrivate($result, 'statuscode')); + } else { + $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); + } $this->assertSame($code, $result->getStatus()); } catch (\Exception $e) { $this->assertTrue($forward); @@ -161,7 +175,11 @@ class OCSMiddlewareTest extends \Test\TestCase { $this->assertInstanceOf('OCP\AppFramework\Http\OCSResponse', $result); $this->assertSame($message, $this->invokePrivate($result, 'message')); - $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $this->invokePrivate($result, 'statuscode')); + } else { + $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); + } $this->assertSame($code, $result->getStatus()); } catch (\Exception $e) { $this->assertTrue($forward); @@ -169,4 +187,50 @@ class OCSMiddlewareTest extends \Test\TestCase { } } + public function dataAfterController() { + $OCSController = $this->getMockBuilder('OCP\AppFramework\OCSController') + ->disableOriginalConstructor() + ->getMock(); + $controller = $this->getMockBuilder('OCP\AppFramework\Controller') + ->disableOriginalConstructor() + ->getMock(); + + return [ + [$OCSController, new Http\Response(), false], + [$OCSController, new Http\JSONResponse(), false], + [$OCSController, new Http\JSONResponse(['message' => 'foo']), false], + [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true], + [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), true], + + [$controller, new Http\Response(), false], + [$controller, new Http\JSONResponse(), false], + [$controller, new Http\JSONResponse(['message' => 'foo']), false], + [$controller, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), false], + [$controller, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), false], + + ]; + } + + /** + * @dataProvider dataAfterController + * + * @param Controller $controller + * @param Http\Response $response + * @param bool $converted + */ + public function testAfterController($controller, $response, $converted) { + $OCSMiddleware = new OCSMiddleware($this->request); + $newResponse = $OCSMiddleware->afterController($controller, 'foo', $response); + + if ($converted === false) { + $this->assertSame($response, $newResponse); + } else { + $this->assertInstanceOf('\OCP\AppFramework\Http\OCSResponse', $newResponse); + /** @var Http\OCSResponse $newResponse */ + $this->assertSame($response->getData()['message'], $this->invokePrivate($newResponse, 'message')); + $this->assertSame(\OCP\API::RESPOND_UNAUTHORISED, $this->invokePrivate($newResponse, 'statuscode')); + $this->assertSame(Http::STATUS_UNAUTHORIZED, $newResponse->getStatus()); + } + } + } |