Browse Source

Implement response::getType()

saeid 8 years ago
parent
commit
2b668581aa
2 changed files with 25 additions and 2 deletions
  1. 12 2
      src/Http/Response.php
  2. 13 0
      tests/TestCase/Http/ResponseTest.php

+ 12 - 2
src/Http/Response.php

@@ -1046,14 +1046,14 @@ class Response implements ResponseInterface
     public function type($contentType = null)
     {
         if ($contentType === null) {
-            return $this->_contentType;
+            return $this->getType();
         }
         if (is_array($contentType)) {
             foreach ($contentType as $type => $definition) {
                 $this->_mimeTypes[$type] = $definition;
             }
 
-            return $this->_contentType;
+            return $this->getType();
         }
         if (isset($this->_mimeTypes[$contentType])) {
             $contentType = $this->_mimeTypes[$contentType];
@@ -1069,6 +1069,16 @@ class Response implements ResponseInterface
     }
 
     /**
+     * Retruns the current content type.
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return $this->_contentType;
+    }
+
+    /**
      * Get an updated response with the content type set.
      *
      * If you attempt to set the type on a 304 or 204 status code response, the

+ 13 - 0
tests/TestCase/Http/ResponseTest.php

@@ -214,6 +214,19 @@ class ResponseTest extends TestCase
     }
 
     /**
+     * Tests the getType method
+     *
+     * @return void
+     */
+    public function testGetType()
+    {
+        $response = new Response();
+        $this->assertEquals('text/html', $response->getType());
+        $response->type('pdf');
+        $this->assertEquals('application/pdf', $response->getType());
+    }
+
+    /**
      * Tests the withType method
      *
      * @return void