Browse Source

Merge pull request #8318 from cakephp/response-get-file

Add Response::getFile()
Mark Story 10 years ago
parent
commit
a6f184c120
2 changed files with 27 additions and 0 deletions
  1. 10 0
      src/Network/Response.php
  2. 17 0
      tests/TestCase/Network/ResponseTest.php

+ 10 - 0
src/Network/Response.php

@@ -1458,6 +1458,16 @@ class Response
     }
 
     /**
+     * Get the current file if one exists.
+     *
+     * @return \Cake\Filesystem\File|null The file to use in the response or null
+     */
+    public function getFile()
+    {
+        return $this->_file;
+    }
+
+    /**
      * Apply a file range to a file and set the end offset.
      *
      * If an invalid range is requested a 416 Status code will be used

+ 17 - 0
tests/TestCase/Network/ResponseTest.php

@@ -1537,6 +1537,23 @@ class ResponseTest extends TestCase
     }
 
     /**
+     * test getFile method
+     *
+     * @return void
+     */
+    public function testGetFile()
+    {
+        ob_start();
+        $response = new Response();
+        $this->assertNull($response->getFile(), 'No file to get');
+
+        $response->file(TEST_APP . 'vendor/css/test_asset.css');
+        $file = $response->getFile();
+        $this->assertInstanceOf('Cake\Filesystem\File', $file, 'Should get a file');
+        $this->assertPathEquals(TEST_APP . 'vendor' . DS . 'css' . DS . 'test_asset.css', $file->path);
+    }
+
+    /**
      * testConnectionAbortedOnBuffering method
      *
      * @return void