diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-09-14 04:03:04 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-09-14 04:03:04 +0400 |
commit | df470ed7170e4b323b4623fd55453abc2d7810ad (patch) | |
tree | d2e234b0562e8b85f9aa847fe0a6de468e554808 /tests | |
parent | 6ea0fe5c49de11a0693e0f588ae06484cf3f6503 (diff) |
Refactoring ProxyStaticFile class:
Small static file server proxy, with compression, caching.
Used to server piwik.js and the merged+minified CSS and JS files
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Core/ServeStaticFileTest.php | 23 | ||||
-rw-r--r-- | tests/resources/staticFileServer.php | 26 |
2 files changed, 25 insertions, 24 deletions
diff --git a/tests/PHPUnit/Core/ServeStaticFileTest.php b/tests/PHPUnit/Core/ServeStaticFileTest.php index 116edab40a..a5cbaa1d39 100644 --- a/tests/PHPUnit/Core/ServeStaticFileTest.php +++ b/tests/PHPUnit/Core/ServeStaticFileTest.php @@ -1,19 +1,20 @@ <?php /** - * This php file is used to unit test Piwik::serveStaticFile() + * This php file is used to unit test Piwik::serveFile() * Unit tests for this method should normally be located in /tests/core/Piwik.test.php - * To make a comprehensive test suit for Piwik::serveStaticFile() (ie. being able to test combinations of request + * To make a comprehensive test suit for Piwik::serveFile() (ie. being able to test combinations of request * headers, being able to test response headers and so on) we need to simulate static file requests in a controlled * environment - * The php code which simulates requests using Piwik::serveStaticFile() is provided in the same file (ie. this one) - * as the unit testing code for Piwik::serveStaticFile() + * The php code which simulates requests using Piwik::serveFile() is provided in the same file (ie. this one) + * as the unit testing code for Piwik::serveFile() * This decision has a structural impact on the usual unit test file structure - * serveStaticFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php + * serveFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php */ // This is Piwik logo, the static file used in this test suit -use Piwik\Piwik; use Piwik\Common; +use Piwik\Piwik; +use Piwik\ProxyStaticFile; define("TEST_FILE_LOCATION", realpath(dirname(__FILE__) . "/../../resources/lipsum.txt")); define("TEST_FILE_CONTENT_TYPE", "text/plain"); @@ -25,7 +26,7 @@ define("ZLIB_OUTPUT_REQUEST_VAR", "zlibOutput"); /** * These constants define the mode in which this php file is used : - * - for unit testing Piwik::serveStaticFile() or + * - for unit testing Piwik::serveFile() or * - as a static file server */ define("STATIC_SERVER_MODE", "staticServerMode"); @@ -52,11 +53,11 @@ class Test_Piwik_ServeStaticFile extends PHPUnit_Framework_TestCase */ public function test_phpOutputCompression() { - $this->assertFalse(Piwik::isPhpOutputCompressed()); + $this->assertFalse(ProxyStaticFile::isPhpOutputCompressed()); } /** - * Checks that "HTTP/1.0 404 Not Found" is returned when Piwik::serveStaticFile is called with a null file + * Checks that "HTTP/1.0 404 Not Found" is returned when Piwik::serveFile is called with a null file * * @group ServeStaticFile */ @@ -73,7 +74,7 @@ class Test_Piwik_ServeStaticFile extends PHPUnit_Framework_TestCase } /** - * Checks that "HTTP/1.0 404 Not Found" is returned when Piwik::serveStaticFile is called with a non existing file + * Checks that "HTTP/1.0 404 Not Found" is returned when Piwik::serveFile is called with a non existing file * * @group ServeStaticFile */ @@ -90,7 +91,7 @@ class Test_Piwik_ServeStaticFile extends PHPUnit_Framework_TestCase } /** - * Checks that "HTTP/1.0 505 Internal server error" is returned when Piwik::serveStaticFile is called with a + * Checks that "HTTP/1.0 505 Internal server error" is returned when Piwik::serveFile is called with a * non-readable file * * @group ServeStaticFile diff --git a/tests/resources/staticFileServer.php b/tests/resources/staticFileServer.php index 3860cf1910..0646b6b3cc 100644 --- a/tests/resources/staticFileServer.php +++ b/tests/resources/staticFileServer.php @@ -1,16 +1,16 @@ <?php /** - * This php file is used to unit test Piwik::serveStaticFile() - * To make a comprehensive test suit for Piwik::serveStaticFile() (ie. being able to test combinations of request + * This php file is used to unit test Piwik::serveFile() + * To make a comprehensive test suit for Piwik::serveFile() (ie. being able to test combinations of request * headers, being able to test response headers and so on) we need to simulate static file requests in a controlled * environment - * The php code which simulates requests using Piwik::serveStaticFile() is provided in the same file (ie. this one) - * as the unit testing code for Piwik::serveStaticFile() + * The php code which simulates requests using Piwik::serveFile() is provided in the same file (ie. this one) + * as the unit testing code for Piwik::serveFile() * This decision has a structural impact on the usual unit test file structure - * serveStaticFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php + * serveFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php */ -use Piwik\Piwik; use Piwik\Common; +use Piwik\ProxyStaticFile; define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__).'/../../'); if(file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php')) @@ -58,7 +58,7 @@ define("TEST_FILE_SRV_MODE", "testFile"); /** * If the static file server has been requested, the response sent back to the browser will be the content produced by - * the execution of Piwik:serveStaticFile(). In this case, unit tests won't be executed + * the execution of Piwik:serveFile(). In this case, unit tests won't be executed */ // Getting the server mode $staticFileServerMode = Common::getRequestVar(SRV_MODE_REQUEST_VAR, ""); @@ -72,21 +72,21 @@ if ($staticFileServerMode === "") { } switch ($staticFileServerMode) { - // The static file server calls Piwik::serveStaticFile with a null file + // The static file server calls Piwik::serveFile with a null file case NULL_FILE_SRV_MODE: - Piwik::serveStaticFile(null, TEST_FILE_CONTENT_TYPE); + ProxyStaticFile::serveFile(null, TEST_FILE_CONTENT_TYPE); break; - // The static file server calls Piwik::serveStaticFile with a non-existing file + // The static file server calls Piwik::serveFile with a non-existing file case GHOST_FILE_SRV_MODE: - Piwik::serveStaticFile(TEST_FILE_LOCATION . ".ghost", TEST_FILE_CONTENT_TYPE); + ProxyStaticFile::serveFile(TEST_FILE_LOCATION . ".ghost", TEST_FILE_CONTENT_TYPE); break; - // The static file server calls Piwik::serveStaticFile with the test file + // The static file server calls Piwik::serveFile with the test file case TEST_FILE_SRV_MODE: - Piwik::serveStaticFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE); + ProxyStaticFile::serveFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE); break; }
\ No newline at end of file |