diff options
author | sgiehl <stefangiehl@gmail.com> | 2012-11-27 02:00:05 +0400 |
---|---|---|
committer | sgiehl <stefangiehl@gmail.com> | 2012-11-27 02:00:05 +0400 |
commit | 4caab2461a50d6d4f81435cf52816a43525780ff (patch) | |
tree | a868f178deba86c0d4af80977ac623426e32e613 /tests/resources/staticFileServer.php | |
parent | 641d319d05162e2c9841d4395a7b133eec8c230b (diff) |
refs #3227 migrated last remaining test
git-svn-id: http://dev.piwik.org/svn/trunk@7549 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'tests/resources/staticFileServer.php')
-rw-r--r-- | tests/resources/staticFileServer.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/resources/staticFileServer.php b/tests/resources/staticFileServer.php new file mode 100644 index 0000000000..fc647f26af --- /dev/null +++ b/tests/resources/staticFileServer.php @@ -0,0 +1,89 @@ +<?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 + * 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() + * 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 + */ +define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__).'/../../'); +if(file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php')) +{ + require_once PIWIK_DOCUMENT_ROOT . '/bootstrap.php'; +} + +error_reporting(E_ALL|E_NOTICE); +@ini_set('display_errors', defined('PIWIK_DISPLAY_ERRORS') ? PIWIK_DISPLAY_ERRORS : @ini_get('display_errors')); +@ini_set('xdebug.show_exception_trace', 0); +@ini_set('magic_quotes_runtime', 0); + +if(!defined('PIWIK_USER_PATH')) +{ + define('PIWIK_USER_PATH', PIWIK_DOCUMENT_ROOT); +} +if(!defined('PIWIK_INCLUDE_PATH')) +{ + define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT); +} + +require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; +require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php'; + +// NOTE: the code above this comment must be PHP4 compatible + +session_cache_limiter('nocache'); +@date_default_timezone_set('UTC'); +require_once PIWIK_INCLUDE_PATH .'/core/Loader.php'; + +// This is Piwik logo, the static file used in this test suit +define("TEST_FILE_LOCATION", dirname(__FILE__) . "/lipsum.txt"); +define("TEST_FILE_CONTENT_TYPE", "text/plain"); + +// Defines http request parameters +define("FILE_MODE_REQUEST_VAR", "fileMode"); +define("SRV_MODE_REQUEST_VAR", "serverMode"); +define("ZLIB_OUTPUT_REQUEST_VAR", "zlibOutput"); + +// These constants define which action will be performed by the static server. +define("NULL_FILE_SRV_MODE", "nullFile"); +define("GHOST_FILE_SRV_MODE", "ghostFile"); +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 + */ +// Getting the server mode +$staticFileServerMode = Piwik_Common::getRequestVar(SRV_MODE_REQUEST_VAR, ""); + +// Setting zlib output compression as requested +ini_set('zlib.output_compression', Piwik_Common::getRequestVar(ZLIB_OUTPUT_REQUEST_VAR, '0')); + +if ($staticFileServerMode === "") { + throw new Exception("When this testing file is used as a static file server, the request parameter " . + SRV_MODE_REQUEST_VAR . " must be provided."); +} + +switch ($staticFileServerMode) { + // The static file server calls Piwik::serveStaticFile with a null file + case NULL_FILE_SRV_MODE: + + Piwik::serveStaticFile(null, TEST_FILE_CONTENT_TYPE); + break; + + // The static file server calls Piwik::serveStaticFile with a non-existing file + case GHOST_FILE_SRV_MODE: + + Piwik::serveStaticFile(TEST_FILE_LOCATION . ".ghost", TEST_FILE_CONTENT_TYPE); + break; + + // The static file server calls Piwik::serveStaticFile with the test file + case TEST_FILE_SRV_MODE: + + Piwik::serveStaticFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE); + break; +}
\ No newline at end of file |