summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/file_test.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-05-11 10:56:04 +0000
committerDries Buytaert <dries@buytaert.net>2010-05-11 10:56:04 +0000
commita4954415212b9c4a74db46bf6f55df5f0f3077c2 (patch)
tree1278968261898dace08e74e91edb7bfd90440137 /modules/simpletest/tests/file_test.module
parent8b0871244950bd389e82fc38809af09124ba60c3 (diff)
downloadbrdo-a4954415212b9c4a74db46bf6f55df5f0f3077c2.tar.gz
brdo-a4954415212b9c4a74db46bf6f55df5f0f3077c2.tar.bz2
- Patch #777830 by Wim Leers: file_create_url() does not support protocol-relative nor root-relative file URLs.
Diffstat (limited to 'modules/simpletest/tests/file_test.module')
-rw-r--r--modules/simpletest/tests/file_test.module111
1 files changed, 80 insertions, 31 deletions
diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module
index b14dd6ef4..6d4d1f8c5 100644
--- a/modules/simpletest/tests/file_test.module
+++ b/modules/simpletest/tests/file_test.module
@@ -286,41 +286,90 @@ function file_test_file_delete($file) {
function file_test_file_url_alter(&$uri) {
// Only run this hook when this variable is set. Otherwise, we'd have to add
// another hidden test module just for this hook.
- if (!variable_get('file_test_hook_file_url_alter', FALSE)) {
+ $alter_mode = variable_get('file_test_hook_file_url_alter', FALSE);
+ if (!$alter_mode) {
return;
}
-
- $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png');
-
- // Most CDNs don't support private file transfers without a lot of hassle,
- // so don't support this in the common case.
- $schemes = array('public');
-
- $scheme = file_uri_scheme($uri);
-
- // Only serve shipped files and public created files from the CDN.
- if (!$scheme || in_array($scheme, $schemes)) {
- // Shipped files.
- if (!$scheme) {
- $path = $uri;
- }
- // Public created files.
- else {
- $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
- $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
+ // Test alteration of file URLs to use a CDN.
+ elseif ($alter_mode == 'cdn') {
+ $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png');
+
+ // Most CDNs don't support private file transfers without a lot of hassle,
+ // so don't support this in the common case.
+ $schemes = array('public');
+
+ $scheme = file_uri_scheme($uri);
+
+ // Only serve shipped files and public created files from the CDN.
+ if (!$scheme || in_array($scheme, $schemes)) {
+ // Shipped files.
+ if (!$scheme) {
+ $path = $uri;
+ }
+ // Public created files.
+ else {
+ $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
+ $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
+ }
+
+ // Clean up Windows paths.
+ $path = str_replace('\\', '/', $path);
+
+ // Serve files with one of the CDN extensions from CDN 1, all others from
+ // CDN 2.
+ $pathinfo = pathinfo($path);
+ if (array_key_exists('extension', $pathinfo) && in_array($pathinfo['extension'], $cdn_extensions)) {
+ $uri = FILE_URL_TEST_CDN_1 . '/' . $path;
+ }
+ else {
+ $uri = FILE_URL_TEST_CDN_2 . '/' . $path;
+ }
}
-
- // Clean up Windows paths.
- $path = str_replace('\\', '/', $path);
-
- // Serve files with one of the CDN extensions from CDN 1, all others from
- // CDN 2.
- $pathinfo = pathinfo($path);
- if (array_key_exists('extension', $pathinfo) && in_array($pathinfo['extension'], $cdn_extensions)) {
- $uri = FILE_URL_TEST_CDN_1 . '/' . $path;
+ }
+ // Test alteration of file URLs to use root-relative URLs.
+ elseif ($alter_mode == 'root-relative') {
+ // Only serve shipped files and public created files with root-relative
+ // URLs.
+ $scheme = file_uri_scheme($uri);
+ if (!$scheme || $scheme == 'public') {
+ // Shipped files.
+ if (!$scheme) {
+ $path = $uri;
+ }
+ // Public created files.
+ else {
+ $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
+ $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
+ }
+
+ // Clean up Windows paths.
+ $path = str_replace('\\', '/', $path);
+
+ // Generate a root-relative URL.
+ $uri = base_path() . '/' . $path;
}
- else {
- $uri = FILE_URL_TEST_CDN_2 . '/' . $path;
+ }
+ // Test alteration of file URLs to use protocol-relative URLs.
+ elseif ($alter_mode == 'protocol-relative') {
+ // Only serve shipped files and public created files with protocol-relative
+ // URLs.
+ $scheme = file_uri_scheme($uri);
+ if (!$scheme || $scheme == 'public') {
+ // Shipped files.
+ if (!$scheme) {
+ $path = $uri;
+ }
+ // Public created files.
+ else {
+ $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
+ $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
+ }
+
+ // Clean up Windows paths.
+ $path = str_replace('\\', '/', $path);
+
+ // Generate a protocol-relative URL.
+ $uri = '/' . base_path() . '/' . $path;
}
}
}