From 78340f5fa64faae2a69f54dd061fbc43b73aa245 Mon Sep 17 00:00:00 2001 From: mscherer Date: Sun, 23 Sep 2018 16:43:24 +0200 Subject: [PATCH] Add tests --- src/Http/Response.php | 8 ++++---- tests/TestCase/Http/ResponseTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Http/Response.php b/src/Http/Response.php index b3aece13bc8..857a449d836 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -1111,7 +1111,7 @@ public function type($contentType = null) { deprecationWarning( 'Response::type() is deprecated. ' . - 'Use getType(), setType() or withType() instead.' + 'Use setTypeMap(), getType() or withType() instead.' ); if ($contentType === null) { @@ -1138,9 +1138,9 @@ public function type($contentType = null) } /** - * Sets a content type into the map. + * Sets a content type definition into the map. * - * E.g.: setType('xhtml' => ['application/xhtml+xml', 'application/xhtml', 'text/xhtml']) + * E.g.: setType('xhtml' => ['application/xhtml+xml', 'application/xhtml']) * * This is needed for RequestHandlerComponent and recognition of types. * @@ -1148,7 +1148,7 @@ public function type($contentType = null) * @param string|array $mimeType Definition of the mime type. * @return void */ - public function setType($type, $mimeType) + public function setTypeMap($type, $mimeType) { $this->_mimeTypes[$type] = $mimeType; } diff --git a/tests/TestCase/Http/ResponseTest.php b/tests/TestCase/Http/ResponseTest.php index 2c36667e8f9..06e6f55ec79 100644 --- a/tests/TestCase/Http/ResponseTest.php +++ b/tests/TestCase/Http/ResponseTest.php @@ -265,6 +265,30 @@ public function testGetType() ); } + /** + * @return void + */ + public function testSetTypeMap() + { + $response = new Response(); + $response->setTypeMap('ical', 'text/calendar'); + + $response = $response->withType('ical')->getType(); + $this->assertEquals('text/calendar', $response); + } + + /** + * @return void + */ + public function testSetTypeMapAsArray() + { + $response = new Response(); + $response->setTypeMap('ical', ['text/calendar']); + + $response = $response->withType('ical')->getType(); + $this->assertEquals('text/calendar', $response); + } + /** * Tests the withType method *