Browse Source

Merge pull request #6361 from cakephp/issue-6340

Make content type header available in integration tests
José Lorenzo Rodríguez 11 years ago
parent
commit
3946fd7917

+ 4 - 0
src/TestSuite/Stub/Response.php

@@ -28,5 +28,9 @@ class Response extends Base
      */
     public function send()
     {
+        if (isset($this->_headers['Location']) && $this->_status === 200) {
+            $this->statusCode(302);
+        }
+        $this->_setContentType();
     }
 }

+ 13 - 0
tests/TestCase/TestSuite/IntegrationTestCaseTest.php

@@ -289,6 +289,19 @@ class IntegrationTestCaseTest extends IntegrationTestCase
     }
 
     /**
+     * Test that type() in an action sets the content-type header.
+     *
+     * @return void
+     */
+    public function testContentTypeInAction()
+    {
+        $this->get('/tests_apps/set_type');
+        $this->assertHeader('Content-Type', 'application/json; charset=UTF-8');
+        $this->assertContentType('json');
+        $this->assertContentType('application/json');
+    }
+
+    /**
      * Test the content assertion.
      *
      * @return void

+ 6 - 0
tests/test_app/TestApp/Controller/TestsAppsController.php

@@ -55,4 +55,10 @@ class TestsAppsController extends AppController
     {
         return $this->redirect('http://cakephp.org', 301);
     }
+
+    public function set_type()
+    {
+        $this->response->type('json');
+        return $this->response;
+    }
 }