Browse Source

Revert "Remove test that wasn't reverted properly."

This reverts commit 288a307a42dbc67a93cd2e6e57d01dc67e096714.
mark_story 8 years ago
parent
commit
e4dee68641
1 changed files with 23 additions and 0 deletions
  1. 23 0
      tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php

+ 23 - 0
tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php

@@ -148,6 +148,29 @@ class ErrorHandlerMiddlewareTest extends TestCase
     }
 
     /**
+     * Test rendering an error page holds onto the original request.
+     *
+     * @return void
+     */
+    public function testHandleExceptionPreserveRequest()
+    {
+        $request = ServerRequestFactory::fromGlobals();
+        $request = $request->withHeader('Accept', 'application/json');
+
+        $response = new Response();
+        $middleware = new ErrorHandlerMiddleware();
+        $next = function ($req, $res) {
+            throw new \Cake\Http\Exception\NotFoundException('whoops');
+        };
+        $result = $middleware($request, $response, $next);
+        $this->assertInstanceOf('Cake\Http\Response', $result);
+        $this->assertNotSame($result, $response);
+        $this->assertEquals(404, $result->getStatusCode());
+        $this->assertContains('"message": "whoops"', '' . $result->getBody());
+        $this->assertEquals('application/json; charset=UTF-8', $result->getHeaderLine('Content-type'));
+    }
+
+    /**
      * Test handling PHP 7's Error instance.
      *
      * @return void