diff --git a/src/Controller/Component/RequestHandlerComponent.php b/src/Controller/Component/RequestHandlerComponent.php index f0cb4086c6a..a06fa23c688 100644 --- a/src/Controller/Component/RequestHandlerComponent.php +++ b/src/Controller/Component/RequestHandlerComponent.php @@ -331,14 +331,17 @@ public function beforeRender(Event $event) if ($this->ext && $isRecognized) { $this->renderAs($controller, $this->ext); } else { - $controller->response = $response->withCharset(Configure::read('App.encoding')); + $response = $response->withCharset(Configure::read('App.encoding')); } if ($this->_config['checkHttpCache'] && $response->checkNotModified($request) ) { + $controller->response = $response; + return false; } + $controller->response = $response; } /** @@ -675,7 +678,7 @@ public function responseType() { $response = $this->getController()->response; - return $response->mapType($response->type()); + return $response->mapType($response->getType()); } /** diff --git a/src/Http/Response.php b/src/Http/Response.php index 87c174efc23..2a5de0afb90 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -1685,7 +1685,7 @@ public function notModified() 'Last-Modified' ]; foreach ($remove as $header) { - unset($this->headers[$header]); + $this->_clearHeader($header); } } @@ -1991,7 +1991,7 @@ public function checkNotModified(ServerRequest $request) $modifiedSince = $request->getHeaderLine('If-Modified-Since'); if ($modifiedSince && $this->hasHeader('Last-Modified')) { - $timeMatches = strtotime($this->getHeaderLine('Last-Modifed')) === strtotime($modifiedSince); + $timeMatches = strtotime($this->getHeaderLine('Last-Modified')) === strtotime($modifiedSince); } $checks = compact('etagMatches', 'timeMatches'); if (empty($checks)) { diff --git a/src/View/AjaxView.php b/src/View/AjaxView.php index b35dc5cc2ab..b63412ad809 100644 --- a/src/View/AjaxView.php +++ b/src/View/AjaxView.php @@ -46,10 +46,10 @@ public function __construct( EventManager $eventManager = null, array $viewOptions = [] ) { - parent::__construct($request, $response, $eventManager, $viewOptions); - if ($response && $response instanceof Response) { - $response->type('ajax'); + $response = $response->withType('ajax'); } + + parent::__construct($request, $response, $eventManager, $viewOptions); } } diff --git a/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php b/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php index 353aa80004d..88cd67a66ba 100644 --- a/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php +++ b/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php @@ -18,10 +18,12 @@ use Cake\Controller\Component\RequestHandlerComponent; use Cake\Event\Event; use Cake\Http\ServerRequest; +use Cake\Http\Response; use Cake\Routing\DispatcherFactory; use Cake\Routing\Router; use Cake\TestSuite\TestCase; use TestApp\Controller\RequestHandlerTestController; +use Zend\Diactoros\Stream; /** * RequestHandlerComponentTest class @@ -141,7 +143,7 @@ public function testInitializeContentTypeSettingExt() { Router::reload(); Router::$initialized = true; - $this->request->env('HTTP_ACCEPT', 'application/json'); + $this->Controller->request = $this->request->withHeader('Accept', 'application/json'); $this->RequestHandler->ext = null; $this->RequestHandler->startup(new Event('Controller.startup', $this->Controller)); @@ -157,8 +159,9 @@ public function testInitializeContentTypeWithjQueryAccept() { Router::reload(); Router::$initialized = true; - $this->request->env('HTTP_ACCEPT', 'application/json, application/javascript, */*; q=0.01'); - $this->request->env('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest'); + $this->Controller->request = $this->request + ->withHeader('Accept', 'application/json, application/javascript, */*; q=0.01') + ->withHeader('X-Requested-With', 'XMLHttpRequest'); $this->RequestHandler->ext = null; Router::extensions('json', false); @@ -175,7 +178,7 @@ public function testInitializeContentTypeWithjQueryTextPlainAccept() { Router::reload(); Router::$initialized = true; - $this->request->env('HTTP_ACCEPT', 'text/plain, */*; q=0.01'); + $this->Controller->request = $this->request->withHeader('Accept', 'text/plain, */*; q=0.01'); $this->RequestHandler->startup(new Event('Controller.startup', $this->Controller)); $this->assertNull($this->RequestHandler->ext); @@ -191,7 +194,7 @@ public function testInitializeContentTypeWithjQueryAcceptAndMultiplesExtensions( { Router::reload(); Router::$initialized = true; - $this->request->env('HTTP_ACCEPT', 'application/json, application/javascript, */*; q=0.01'); + $this->Controller->request = $this->request->withHeader('Accept', 'application/json, application/javascript, */*; q=0.01'); $this->RequestHandler->ext = null; Router::extensions(['rss', 'json'], false); @@ -225,8 +228,8 @@ public function testInitializeNoContentTypeWithSingleAccept() */ public function testInitializeNoContentTypeWithMultipleAcceptedTypes() { - $this->request->env( - 'HTTP_ACCEPT', + $this->Controller->request = $this->request->withHeader( + 'Accept', 'application/json, application/javascript, application/xml, */*; q=0.01' ); $this->RequestHandler->ext = null; @@ -251,8 +254,8 @@ public function testInitializeContentTypeWithMultipleAcceptedTypes() { Router::reload(); Router::$initialized = true; - $this->request->env( - 'HTTP_ACCEPT', + $this->Controller->request = $this->request->withHeader( + 'Accept', 'text/csv;q=1.0, application/json;q=0.8, application/xml;q=0.7' ); $this->RequestHandler->ext = null; @@ -270,7 +273,7 @@ public function testInitializeAmbiguousAndroidAccepts() { Router::reload(); Router::$initialized = true; - $this->request->env( + $this->request = $this->request->withEnv( 'HTTP_ACCEPT', 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' ); @@ -403,7 +406,7 @@ public function testViewClassMapMethod() */ public function testIsAjaxParams() { - $this->request->env('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest'); + $this->Controller->request = $this->request->withHeader('X-Requested-With', 'XMLHttpRequest'); $event = new Event('Controller.startup', $this->Controller); $this->RequestHandler->initialize([]); $this->Controller->beforeFilter($event); @@ -420,11 +423,12 @@ public function testIsAjaxParams() public function testAutoAjaxLayout() { $event = new Event('Controller.startup', $this->Controller); - $this->request->env('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest'); + $this->Controller->request = $this->request->withHeader('X-Requested-With', 'XMLHttpRequest'); $this->RequestHandler->initialize([]); $this->RequestHandler->startup($event); $event = new Event('Controller.beforeRender', $this->Controller); $this->RequestHandler->beforeRender($event); + $this->assertEquals($this->Controller->viewClass, 'Cake\View\AjaxView'); $view = $this->Controller->createView(); $this->assertEquals('ajax', $view->layout); @@ -532,8 +536,8 @@ public function testStartupCallback() $_SERVER['CONTENT_TYPE'] = 'application/xml'; $this->Controller->request = new ServerRequest(); $this->RequestHandler->beforeRender($event); - $this->assertInternalType('array', $this->Controller->request->data); - $this->assertNotInternalType('object', $this->Controller->request->data); + $this->assertInternalType('array', $this->Controller->request->getData()); + $this->assertNotInternalType('object', $this->Controller->request->getData()); } /** @@ -549,8 +553,8 @@ public function testStartupCallbackCharset() $_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8'; $this->Controller->request = new ServerRequest(); $this->RequestHandler->startup($event); - $this->assertInternalType('array', $this->Controller->request->data); - $this->assertNotInternalType('object', $this->Controller->request->data); + $this->assertInternalType('array', $this->Controller->request->getData()); + $this->assertNotInternalType('object', $this->Controller->request->getData()); } /** @@ -561,21 +565,28 @@ public function testStartupCallbackCharset() */ public function testStartupProcessData() { - $this->Controller->request = new ServerRequest(); - $this->Controller->request->env('REQUEST_METHOD', 'POST'); - $this->Controller->request->env('CONTENT_TYPE', 'application/json'); + $this->Controller->request = new ServerRequest([ + 'environment' => [ + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/json' + ] + ]); $event = new Event('Controller.startup', $this->Controller); $this->RequestHandler->startup($event); - $this->assertEquals([], $this->Controller->request->data); + $this->assertEquals([], $this->Controller->request->getData()); - $this->Controller->request->setInput('"invalid"'); + $stream = new Stream('php://memory', 'w'); + $stream->write('"invalid"'); + $this->Controller->request = $this->Controller->request->withBody($stream); $this->RequestHandler->startup($event); - $this->assertEquals(['invalid'], $this->Controller->request->data); + $this->assertEquals(['invalid'], $this->Controller->request->getData()); - $this->Controller->request->setInput('{"valid":true}'); + $stream = new Stream('php://memory', 'w'); + $stream->write('{"valid":true}'); + $this->Controller->request = $this->Controller->request->withBody($stream); $this->RequestHandler->startup($event); - $this->assertEquals(['valid' => true], $this->Controller->request->data); + $this->assertEquals(['valid' => true], $this->Controller->request->getData()); } /** @@ -586,35 +597,44 @@ public function testStartupProcessData() */ public function testStartupIgnoreFileAsXml() { - $this->Controller->request = new ServerRequest(['input' => '/dev/random']); - $this->Controller->request->env('REQUEST_METHOD', 'POST'); - $this->Controller->request->env('CONTENT_TYPE', 'application/xml'); + $this->Controller->request = new ServerRequest([ + 'input' => '/dev/random', + 'environment' => [ + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/xml' + ] + ]); $event = new Event('Controller.startup', $this->Controller); $this->RequestHandler->startup($event); - $this->assertEquals([], $this->Controller->request->data); + $this->assertEquals([], $this->Controller->request->getData()); } /** * Test mapping a new type and having startup process it. * + * @group deprecated * @return void * @triggers Controller.startup $this->Controller */ public function testStartupCustomTypeProcess() { - $this->Controller->request = new ServerRequest([ - 'input' => '"A","csv","string"' - ]); - $this->RequestHandler->setConfig('inputTypeMap.csv', ['str_getcsv']); - $this->Controller->request->env('REQUEST_METHOD', 'POST'); - $this->Controller->request->env('CONTENT_TYPE', 'text/csv'); - $event = new Event('Controller.startup', $this->Controller); - $this->RequestHandler->startup($event); - $expected = [ - 'A', 'csv', 'string' - ]; - $this->assertEquals($expected, $this->Controller->request->data); + $this->deprecated(function () { + $this->Controller->request = new ServerRequest([ + 'input' => '"A","csv","string"', + 'environment' => [ + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'text/csv' + ] + ]); + $this->RequestHandler->addInputType('csv', ['str_getcsv']); + $event = new Event('Controller.startup', $this->Controller); + $this->RequestHandler->startup($event); + $expected = [ + 'A', 'csv', 'string' + ]; + $this->assertEquals($expected, $this->Controller->request->getData()); + }); } /** @@ -627,7 +647,7 @@ public function testBeforeRedirectDisabled() { static::setAppNamespace(); Router::connect('/:controller/:action'); - $this->Controller->request->env('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest'); + $this->Controller->request = $this->Controller->request->withHeader('X-Requested-With', 'XMLHttpRequest'); $event = new Event('Controller.startup', $this->Controller); $this->RequestHandler->initialize([]); @@ -697,29 +717,13 @@ public function testRenderAs() */ public function testRenderAsWithAttachment() { - $this->RequestHandler->request = $this->getMockBuilder('Cake\Http\ServerRequest') - ->setMethods(['parseAccept']) - ->getMock(); - $this->RequestHandler->request->expects($this->any()) - ->method('parseAccept') - ->will($this->returnValue(['1.0' => ['application/xml']])); - - $this->Controller->response = $this->getMockBuilder('Cake\Http\Response') - ->setMethods(['type', 'download', 'charset']) - ->getMock(); - $this->Controller->response->expects($this->at(0)) - ->method('type') - ->with('application/xml'); - $this->Controller->response->expects($this->at(1)) - ->method('charset') - ->with('UTF-8'); - $this->Controller->response->expects($this->at(2)) - ->method('download') - ->with('myfile.xml'); + $this->Controller->request = $this->request->withHeader('Accept', 'application/xml;q=1.0'); $this->RequestHandler->renderAs($this->Controller, 'xml', ['attachment' => 'myfile.xml']); - $this->assertEquals('Cake\View\XmlView', $this->Controller->viewClass); + $this->assertEquals('application/xml', $this->Controller->response->getType()); + $this->assertEquals('UTF-8', $this->Controller->response->getCharset()); + $this->assertContains('myfile.xml', $this->Controller->response->getHeaderLine('Content-Disposition')); } /** @@ -729,18 +733,13 @@ public function testRenderAsWithAttachment() */ public function testRespondAs() { - $this->Controller->response = $this->getMockBuilder('Cake\Http\Response') - ->setMethods(['type']) - ->getMock(); - $this->Controller->response->expects($this->at(0))->method('type') - ->with('application/json'); - $this->Controller->response->expects($this->at(1))->method('type') - ->with('text/xml'); - $result = $this->RequestHandler->respondAs('json'); $this->assertTrue($result); + $this->assertEquals('application/json', $this->Controller->response->getType()); + $result = $this->RequestHandler->respondAs('text/xml'); $this->assertTrue($result); + $this->assertEquals('text/xml', $this->Controller->response->getType()); } /** @@ -750,28 +749,11 @@ public function testRespondAs() */ public function testRespondAsWithAttachment() { - $this->RequestHandler = $this->getMockBuilder('Cake\Controller\Component\RequestHandlerComponent') - ->setMethods(['_header']) - ->setConstructorArgs([$this->Controller->components()]) - ->getMock(); - $this->Controller->response = $this->getMockBuilder('Cake\Http\Response') - ->setMethods(['type', 'download']) - ->getMock(); - $this->Controller->request = $this->getMockBuilder('Cake\Http\ServerRequest') - ->setMethods(['parseAccept']) - ->getMock(); - - $this->Controller->request->expects($this->once()) - ->method('parseAccept') - ->will($this->returnValue(['1.0' => ['application/xml']])); - - $this->Controller->response->expects($this->once())->method('download') - ->with('myfile.xml'); - $this->Controller->response->expects($this->once())->method('type') - ->with('application/xml'); - $result = $this->RequestHandler->respondAs('xml', ['attachment' => 'myfile.xml']); $this->assertTrue($result); + $response = $this->Controller->response; + $this->assertContains('myfile.xml', $response->getHeaderLine('Content-Disposition')); + $this->assertContains('application/xml', $response->getType()); } /** @@ -803,11 +785,11 @@ public function testRenderAsCalledTwice() */ public function testRequestContentTypes() { - $this->request->env('REQUEST_METHOD', 'GET'); + $this->Controller->request = $this->request->withEnv('REQUEST_METHOD', 'GET'); $this->assertNull($this->RequestHandler->requestedWith()); - $this->request->env('REQUEST_METHOD', 'POST'); - $this->request->env('CONTENT_TYPE', 'application/json'); + $this->Controller->request = $this->request->withEnv('REQUEST_METHOD', 'POST') + ->withEnv('CONTENT_TYPE', 'application/json'); $this->assertEquals('json', $this->RequestHandler->requestedWith()); $result = $this->RequestHandler->requestedWith(['json', 'xml']); @@ -816,36 +798,52 @@ public function testRequestContentTypes() $result = $this->RequestHandler->requestedWith(['rss', 'atom']); $this->assertFalse($result); - $this->request->env('REQUEST_METHOD', 'PATCH'); + $this->Controller->request = $this->request + ->withEnv('REQUEST_METHOD', 'PATCH') + ->withEnv('CONTENT_TYPE', 'application/json'); $this->assertEquals('json', $this->RequestHandler->requestedWith()); - $this->request->env('REQUEST_METHOD', 'DELETE'); + $this->Controller->request = $this->request + ->withEnv('REQUEST_METHOD', 'DELETE') + ->withEnv('CONTENT_TYPE', 'application/json'); $this->assertEquals('json', $this->RequestHandler->requestedWith()); - $this->request->env('REQUEST_METHOD', 'POST'); - $this->request->env('CONTENT_TYPE', 'application/json'); - + $this->Controller->request = $this->request + ->withEnv('REQUEST_METHOD', 'POST') + ->withEnv('CONTENT_TYPE', 'application/json'); $result = $this->RequestHandler->requestedWith(['json', 'xml']); $this->assertEquals('json', $result); $result = $this->RequestHandler->requestedWith(['rss', 'atom']); $this->assertFalse($result); - $this->request->env('HTTP_ACCEPT', 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*'); + $this->Controller->request = $this->request->withHeader( + 'Accept', + 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*' + ); $this->assertTrue($this->RequestHandler->isXml()); $this->assertFalse($this->RequestHandler->isAtom()); $this->assertFalse($this->RequestHandler->isRSS()); - $this->request->env('HTTP_ACCEPT', 'application/atom+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*'); + $this->Controller->request = $this->request->withHeader( + 'Accept', + 'application/atom+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*' + ); $this->assertTrue($this->RequestHandler->isAtom()); $this->assertFalse($this->RequestHandler->isRSS()); - $this->request->env('HTTP_ACCEPT', 'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*'); + $this->Controller->request = $this->request->withHeader( + 'Accept', + 'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*' + ); $this->assertFalse($this->RequestHandler->isAtom()); $this->assertTrue($this->RequestHandler->isRSS()); $this->assertFalse($this->RequestHandler->isWap()); - $this->request->env('HTTP_ACCEPT', 'text/vnd.wap.wml,text/html,text/plain,image/png,*/*'); + $this->Controller->request = $this->request->withHeader( + 'Accept', + 'text/vnd.wap.wml,text/html,text/plain,image/png,*/*' + ); $this->assertTrue($this->RequestHandler->isWap()); } @@ -907,11 +905,14 @@ public function testMapAlias() */ public function testAccepts() { - $this->request->env('HTTP_ACCEPT', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'); + $this->Controller->request = $this->request->withHeader( + 'Accept', + 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' + ); $this->assertTrue($this->RequestHandler->accepts(['js', 'xml', 'html'])); $this->assertFalse($this->RequestHandler->accepts(['gif', 'jpeg', 'foo'])); - $this->request->env('HTTP_ACCEPT', '*/*;q=0.5'); + $this->Controller->request = $this->request->withHeader('Accept', '*/*;q=0.5'); $this->assertFalse($this->RequestHandler->accepts('rss')); } @@ -922,11 +923,12 @@ public function testAccepts() */ public function testPrefers() { - $this->request->env( - 'HTTP_ACCEPT', + $this->Controller->request = $this->request->withHeader( + 'Accept', 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*' ); $this->assertNotEquals('rss', $this->RequestHandler->prefers()); + $this->RequestHandler->ext = 'rss'; $this->assertEquals('rss', $this->RequestHandler->prefers()); $this->assertFalse($this->RequestHandler->prefers('xml')); @@ -937,13 +939,13 @@ public function testPrefers() $this->assertFalse($this->RequestHandler->prefers(['html']), 'No match with ext, return false.'); $this->_init(); - $this->request->env( - 'HTTP_ACCEPT', + $this->Controller->request = $this->request->withHeader( + 'Accept', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' ); $this->assertEquals('xml', $this->RequestHandler->prefers()); - $this->request->env('HTTP_ACCEPT', '*/*;q=0.5'); + $this->Controller->request = $this->request->withHeader('Accept', '*/*;q=0.5'); $this->assertEquals('html', $this->RequestHandler->prefers()); $this->assertFalse($this->RequestHandler->prefers('rss')); } @@ -1190,17 +1192,19 @@ public function testAddInputTypeException() */ public function testCheckNotModifiedByEtagStar() { - $_SERVER['HTTP_IF_NONE_MATCH'] = '*'; - $response = $this->getMockBuilder('Cake\Http\Response') - ->setMethods(['notModified', 'stop']) - ->getMock(); - $response->etag('something'); - $response->expects($this->once())->method('notModified'); + $response = new Response(); + $response = $response->withEtag('something') + ->withHeader('Content-Type', 'text/plain') + ->withStringBody('keeper'); $this->Controller->response = $response; + $this->Controller->request = $this->request->withHeader('If-None-Match', '*'); $event = new Event('Controller.beforeRender', $this->Controller); $requestHandler = new RequestHandlerComponent($this->Controller->components()); $this->assertFalse($requestHandler->beforeRender($event)); + $this->assertEquals(304, $this->Controller->response->getStatusCode()); + $this->assertEquals('', (string)$this->Controller->response->getBody()); + $this->assertFalse($this->Controller->response->hasHeader('Content-Type'), 'header should not be removed.'); } /** @@ -1211,17 +1215,20 @@ public function testCheckNotModifiedByEtagStar() */ public function testCheckNotModifiedByEtagExact() { - $_SERVER['HTTP_IF_NONE_MATCH'] = 'W/"something", "other"'; - $response = $this->getMockBuilder('Cake\Http\Response') - ->setMethods(['notModified', 'stop']) - ->getMock(); - $response->etag('something', true); - $response->expects($this->once())->method('notModified'); + $response = new Response(); + $response = $response->withEtag('something', true) + ->withHeader('Content-Type', 'text/plain') + ->withStringBody('keeper'); $this->Controller->response = $response; + + $this->Controller->request = $this->request->withHeader('If-None-Match', 'W/"something", "other"'); $event = new Event('Controller.beforeRender', $this->Controller); $requestHandler = new RequestHandlerComponent($this->Controller->components()); $this->assertFalse($requestHandler->beforeRender($event)); + $this->assertEquals(304, $this->Controller->response->getStatusCode()); + $this->assertEquals('', (string)$this->Controller->response->getBody()); + $this->assertFalse($this->Controller->response->hasHeader('Content-Type')); } /** @@ -1232,19 +1239,24 @@ public function testCheckNotModifiedByEtagExact() */ public function testCheckNotModifiedByEtagAndTime() { - $_SERVER['HTTP_IF_NONE_MATCH'] = 'W/"something", "other"'; - $_SERVER['HTTP_IF_MODIFIED_SINCE'] = '2012-01-01 00:00:00'; - $response = $this->getMockBuilder('Cake\Http\Response') - ->setMethods(['notModified', 'stop']) - ->getMock(); - $response->etag('something', true); - $response->modified('2012-01-01 00:00:00'); - $response->expects($this->once())->method('notModified'); + $this->Controller->request = $this->request + ->withHeader('If-None-Match', 'W/"something", "other"') + ->withHeader('If-Modified-Since', '2012-01-01 00:00:00'); + + $response = new Response(); + $response = $response->withEtag('something', true) + ->withHeader('Content-type', 'text/plain') + ->withStringBody('should be removed') + ->withModified('2012-01-01 00:00:00'); $this->Controller->response = $response; $event = new Event('Controller.beforeRender', $this->Controller); $requestHandler = new RequestHandlerComponent($this->Controller->components()); $this->assertFalse($requestHandler->beforeRender($event)); + + $this->assertEquals(304, $this->Controller->response->getStatusCode()); + $this->assertEquals('', (string)$this->Controller->response->getBody()); + $this->assertFalse($this->Controller->response->hasHeader('Content-type')); } /** @@ -1322,6 +1334,6 @@ public function testBeforeRender() $this->Controller->set_response_type(); $event = new Event('Controller.beforeRender', $this->Controller); $this->RequestHandler->beforeRender($event); - $this->assertEquals('text/plain', $this->Controller->response->type()); + $this->assertEquals('text/plain', $this->Controller->response->getType()); } } diff --git a/tests/test_app/TestApp/Controller/RequestHandlerTestController.php b/tests/test_app/TestApp/Controller/RequestHandlerTestController.php index a71de209910..aa4456531da 100644 --- a/tests/test_app/TestApp/Controller/RequestHandlerTestController.php +++ b/tests/test_app/TestApp/Controller/RequestHandlerTestController.php @@ -67,6 +67,6 @@ public function ajax2_layout() */ public function set_response_type() { - $this->response->type('txt'); + $this->response = $this->response->withType('txt'); } }