Index: imagecache.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v retrieving revision 1.68.2.2 diff -u -b -u -p -r1.68.2.2 imagecache.module --- imagecache.module 7 May 2008 20:18:55 -0000 1.68.2.2 +++ imagecache.module 11 May 2008 11:22:19 -0000 @@ -185,10 +185,24 @@ function imagecache_action_definition($a /** * Return a URL that points to the location of a derivative of the * original image at @p $path, transformed with the given @p $preset. + * + * Special care is taken to make this work with the possible combinations of + * Clean URLs and public/private downloads. For example, when Clean URLs are not + * available an URL with query should be returned, like + * http://example.com/?q=files/imagecache/foo.jpg, so that imagecache is able + * intercept the request for this file. + * + * This code is very similar to the Drupal core function file_create_url(), but + * handles the case of Clean URLs and public downloads differently however. */ function imagecache_create_url($presetname, $path) { $path = _imagecache_strip_file_directory($path); - return file_create_url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path); + switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) { + case FILE_DOWNLOADS_PUBLIC: + return url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path, NULL, NULL, TRUE); + case FILE_DOWNLOADS_PRIVATE: + return url('system/files/imagecache/'. $presetname .'/'. $path, NULL, NULL, TRUE); + } } /** @@ -927,5 +941,3 @@ function imagecache_action_delete($actio imagecache_preset_flush($preset); imagecache_presets(true); } - - Index: tests/imagecache_create_url.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/tests/Attic/imagecache_create_url.test,v retrieving revision 1.1.2.1 diff -u -b -u -p -r1.1.2.1 imagecache_create_url.test --- tests/imagecache_create_url.test 10 May 2008 15:19:55 -0000 1.1.2.1 +++ tests/imagecache_create_url.test 11 May 2008 11:22:19 -0000 @@ -2,11 +2,14 @@ class ImageCacheUrlTests extends DrupalTestCase { + /** + * Drupal SimpleTest method: return metadata about the test. + */ function get_info() { return array( 'name' => 'ImageCache Create URL Tests', - 'desc' => 'Assure that URLs are properly generated by 'imagecache_create_url'. @see: http://drupal.org/node/241541', - 'group' => 'ImageCache Tests', + 'desc' => 'Assure that URLs are properly generated by imagecache_create_url(), as discussed at http://drupal.org/node/241541', + 'group' => 'ImageCache', ); } @@ -14,18 +17,24 @@ class ImageCacheUrlTests extends DrupalT * No Clean URLs + public downloads : http://example.com/?q=path/to/files/imagecache/preset/foo.jpg */ function testDirtyUrlsPublicDownloads() { - $this->_ImagecacheCreateUrlTest( false, FILE_DOWNLOADS_PUBLIC, 'path/to/files', - 'preset', 'foo.jpg', 'http://example.com/?q=path/to/files/imagecache/preset/foo.jpg', - 'DirtyUrlsPublicDownloads'); + $this->_ImagecacheCreateUrlTest( + false, FILE_DOWNLOADS_PUBLIC, + 'path/to/files', 'preset', 'foo.jpg', + 'http://example.com/?q=path/to/files/imagecache/preset/foo.jpg', + 'DirtyUrlsPublicDownloads' + ); } /** * Clean URLs + public downloads : http://example.com/path/to/files/imagecache/preset/foo.jpg */ function testCleanUrlsPublicDownloads() { - $this->_ImagecacheCreateUrlTest( true, FILE_DOWNLOADS_PUBLIC, 'path/to/files', - 'preset', 'foo.jpg', 'http://example.com/path/to/files/imagecache/preset/foo.jpg', - 'CleanUrlsPublicDownloads'); + $this->_ImagecacheCreateUrlTest( + true, FILE_DOWNLOADS_PUBLIC, + 'path/to/files', 'preset', 'foo.jpg', + 'http://example.com/path/to/files/imagecache/preset/foo.jpg', + 'CleanUrlsPublicDownloads' + ); } @@ -33,9 +42,12 @@ class ImageCacheUrlTests extends DrupalT * No Clean URLs + private downloads : http://example.com/?q=system/files/imagecache/preset/foo.jpg */ function testDirtyUrlsPrivateDownloads() { - $this->_ImagecacheCreateUrlTest( false, FILE_DOWNLOADS_PRIVATE, 'path/to/files', - 'preset', 'foo.jpg', 'http://example.com/?q=system/files/imagecache/preset/foo.jpg', - 'DirtyUrlsPrivateDownloads'); + $this->_ImagecacheCreateUrlTest( + false, FILE_DOWNLOADS_PRIVATE, + 'path/to/files', 'preset', 'foo.jpg', + 'http://example.com/?q=system/files/imagecache/preset/foo.jpg', + 'DirtyUrlsPrivateDownloads' + ); } @@ -43,19 +55,22 @@ class ImageCacheUrlTests extends DrupalT * Clean URLs + private downloads : http://example.com/system/files/imagecache/preset/foo.jpg */ function testCleanUrlsPrivateDownloads() { - $this->_ImagecacheCreateUrlTest( true, FILE_DOWNLOADS_PRIVATE, 'path/to/files', - 'preset', 'foo.jpg', 'http://example.com/system/files/imagecache/preset/foo.jpg', - 'CleanUrlsPrivateDownloads'); + $this->_ImagecacheCreateUrlTest( + true, FILE_DOWNLOADS_PRIVATE, + 'path/to/files', 'preset', 'foo.jpg', + 'http://example.com/system/files/imagecache/preset/foo.jpg', + 'CleanUrlsPrivateDownloads' + ); } /** * function to actually perform URL tests. - * @param $urls + * @param $clean_url * 'clean_url' setting for test. - * @param $files + * @param $file_downloads * 'file_downloads' setting for test. - * @param $filesdir + * @param $file_directory_path * 'file_directory_path' setting for tests. * @param $preset * imagecache preset name to be used for test. @@ -67,30 +82,23 @@ class ImageCacheUrlTests extends DrupalT * error message to be displayed on assertion failure. */ - private function _ImagecacheCreateUrlTest($urls, $files, $filesdir, $preset, $path, $expected, $error = '') { - // save old variables. - $old_baseurl = $GLOBALS['base_url']; - $old_clean = variable_get('clean_url', '0'); - $old_files = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC); - $old_filesdir = variable_get('file_directory_path', conf_path() .'/files'); - - // set test variables - variable_set('clean_url', $urls); - variable_set('file_downloads', $files); - variable_set('file_directory_path', $filesdir); + private function _ImagecacheCreateUrlTest($clean_url, $file_downloads, $file_directory_path, $preset, $path, $expected, $error = '') { + // Drupal settings + $this->drupalVariableSet('clean_url', $clean_url); + $this->drupalVariableSet('file_downloads', $file_downloads); + $this->drupalVariableSet('file_directory_path', $file_directory_path); + // Change base_url (and save original value) + $original_baseurl = $GLOBALS['base_url']; $GLOBALS['base_url'] = 'http://example.com'; - + // Generate URL and check it. $url = imagecache_create_url($preset, $path); - $this->assertTrue($url == $expected, "($error) expected: $expected got: $url"); - - // reset old variable values - variable_set('clean_url', $old_clean); - variable_set('file_downloads', $old_files); - variable_set('file_directory_path', $old_filesdir); + $this->assertTrue($url == $expected, + t('[@type] expected "@expected" and got "@result"', array('@type' => $error, '@expected' => $expected, '@result' => $url)) + ); - $GLOBALS['base_url'] = $old_baseurl; + // Restore base_url. + $GLOBALS['base_url'] = $original_baseurl; } } -