@@ -88,7 +88,10 @@ public function dataAfterException() {
8888 * @param string $message
8989 * @param int $code
9090 */
91- public function testAfterException ($ controller , $ exception , $ forward , $ message = '' , $ code = 0 ) {
91+ public function testAfterExceptionOCSv1 ($ controller , $ exception , $ forward , $ message = '' , $ code = 0 ) {
92+ $ this ->request
93+ ->method ('getScriptName ' )
94+ ->willReturn ('/ocs/v1.php ' );
9295 $ OCSMiddleware = new OCSMiddleware ($ this ->request );
9396
9497 try {
@@ -99,6 +102,37 @@ public function testAfterException($controller, $exception, $forward, $message =
99102
100103 $ this ->assertSame ($ message , $ this ->invokePrivate ($ result , 'message ' ));
101104 $ this ->assertSame ($ code , $ this ->invokePrivate ($ result , 'statuscode ' ));
105+ $ this ->assertSame (200 , $ result ->getStatus ());
106+ } catch (\Exception $ e ) {
107+ $ this ->assertTrue ($ forward );
108+ $ this ->assertEquals ($ exception , $ e );
109+ }
110+ }
111+
112+ /**
113+ * @dataProvider dataAfterException
114+ *
115+ * @param Controller $controller
116+ * @param \Exception $exception
117+ * @param bool $forward
118+ * @param string $message
119+ * @param int $code
120+ */
121+ public function testAfterExceptionOCSv2 ($ controller , $ exception , $ forward , $ message = '' , $ code = 0 ) {
122+ $ this ->request
123+ ->method ('getScriptName ' )
124+ ->willReturn ('/ocs/v2.php ' );
125+ $ OCSMiddleware = new OCSMiddleware ($ this ->request );
126+
127+ try {
128+ $ result = $ OCSMiddleware ->afterException ($ controller , 'method ' , $ exception );
129+ $ this ->assertFalse ($ forward );
130+
131+ $ this ->assertInstanceOf ('OCP\AppFramework\Http\OCSResponse ' , $ result );
132+
133+ $ this ->assertSame ($ message , $ this ->invokePrivate ($ result , 'message ' ));
134+ $ this ->assertSame ($ code , $ this ->invokePrivate ($ result , 'statuscode ' ));
135+ $ this ->assertSame ($ code , $ result ->getStatus ());
102136 } catch (\Exception $ e ) {
103137 $ this ->assertTrue ($ forward );
104138 $ this ->assertEquals ($ exception , $ e );
0 commit comments