diff --git a/src/View/JsonView.php b/src/View/JsonView.php index 58111b73930..ff2adee344f 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -113,7 +113,7 @@ public function render($view = null, $layout = null) } if ($this->request->getQuery($jsonpParam)) { $return = sprintf('%s(%s)', h($this->request->getQuery($jsonpParam)), $return); - $this->response->type('js'); + $this->response = $this->response->withType('js'); } } diff --git a/src/View/SerializedView.php b/src/View/SerializedView.php index 931c03e4cb1..bed8513a26a 100644 --- a/src/View/SerializedView.php +++ b/src/View/SerializedView.php @@ -46,11 +46,10 @@ public function __construct( EventManager $eventManager = null, array $viewOptions = [] ) { - parent::__construct($request, $response, $eventManager, $viewOptions); - if ($response && $response instanceof Response) { - $response->type($this->_responseType); + $response = $response->withType($this->_responseType); } + parent::__construct($request, $response, $eventManager, $viewOptions); } /** diff --git a/tests/TestCase/View/JsonViewTest.php b/tests/TestCase/View/JsonViewTest.php index 5d5fdc3faa5..b98cdf37c50 100644 --- a/tests/TestCase/View/JsonViewTest.php +++ b/tests/TestCase/View/JsonViewTest.php @@ -293,13 +293,13 @@ public function testJsonpResponse() $output = $View->render(false); $this->assertSame(json_encode($data), $output); - $this->assertSame('application/json', $Response->type()); + $this->assertSame('application/json', $View->response->getType()); $View->request->query = ['callback' => 'jfunc']; $output = $View->render(false); $expected = 'jfunc(' . json_encode($data) . ')'; $this->assertSame($expected, $output); - $this->assertSame('application/javascript', $Response->type()); + $this->assertSame('application/javascript', $View->response->getType()); $View->request->query = ['jsonCallback' => 'jfunc']; $View->viewVars['_jsonp'] = 'jsonCallback'; @@ -337,6 +337,6 @@ public function testRenderWithView() $expected = json_encode(['user' => 'fake', 'list' => ['item1', 'item2'], 'paging' => null]); $this->assertSame($expected, $output); - $this->assertSame('application/json', $Response->type()); + $this->assertSame('application/json', $View->response->getType()); } } diff --git a/tests/TestCase/View/XmlViewTest.php b/tests/TestCase/View/XmlViewTest.php index d49a6414528..84918d2fd05 100644 --- a/tests/TestCase/View/XmlViewTest.php +++ b/tests/TestCase/View/XmlViewTest.php @@ -52,7 +52,7 @@ public function testRenderWithoutView() $output = $View->render(false); $this->assertSame(Xml::build($data)->asXML(), $output); - $this->assertSame('application/xml', $Response->type()); + $this->assertSame('application/xml', $View->response->getType()); $data = [ [ @@ -191,7 +191,7 @@ public function testRenderWithoutViewMultiple() $Controller->set('_serialize', ['no', 'user']); $Controller->viewClass = 'Xml'; $View = $Controller->createView(); - $this->assertSame('application/xml', $Response->type()); + $this->assertSame('application/xml', $View->response->getType()); $output = $View->render(false); $expected = [ 'response' => ['no' => $data['no'], 'user' => $data['user']] @@ -223,7 +223,7 @@ public function testRenderWithoutViewMultipleAndAlias() $Controller->set('_serialize', ['new_name' => 'original_name', 'user']); $Controller->viewClass = 'Xml'; $View = $Controller->createView(); - $this->assertSame('application/xml', $Response->type()); + $this->assertSame('application/xml', $View->response->getType()); $output = $View->render(false); $expected = [ 'response' => ['new_name' => $data['original_name'], 'user' => $data['user']] @@ -257,7 +257,7 @@ public function testRenderWithSerializeTrue() $output = $View->render(); $this->assertSame(Xml::build($data)->asXML(), $output); - $this->assertSame('application/xml', $Response->type()); + $this->assertSame('application/xml', $View->response->getType()); $data = ['no' => 'nope', 'user' => 'fake', 'list' => ['item1', 'item2']]; $Controller->viewVars = []; @@ -306,7 +306,7 @@ public function testRenderWithView() ]; $expected = Xml::build($expected)->asXML(); $this->assertSame($expected, $output); - $this->assertSame('application/xml', $Response->type()); + $this->assertSame('application/xml', $View->response->getType()); $this->assertInstanceOf('Cake\View\HelperRegistry', $View->helpers()); } }