summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2013-08-05 03:26:40 -0400
committerDavid Rothstein <drothstein@gmail.com>2013-08-05 03:26:40 -0400
commit768fe8bc2d5e8d664064471fcb4e421a29608a3a (patch)
treeec9bd8a861bc39157ad7a3f4dfed88e14f626eb2 /modules
parent922166f3c910969e8470e1c9fa657b270fe65cd0 (diff)
downloadbrdo-768fe8bc2d5e8d664064471fcb4e421a29608a3a.tar.gz
brdo-768fe8bc2d5e8d664064471fcb4e421a29608a3a.tar.bz2
Issue #1057656 by mondrake, chx | adrinux: Fixed Image styles don't flush for images stored non-default schemes.
Diffstat (limited to 'modules')
-rw-r--r--modules/image/image.module7
-rw-r--r--modules/image/image.test106
2 files changed, 109 insertions, 4 deletions
diff --git a/modules/image/image.module b/modules/image/image.module
index fcbf62cdc..b3ba7c449 100644
--- a/modules/image/image.module
+++ b/modules/image/image.module
@@ -969,9 +969,10 @@ function image_style_transform_dimensions($style_name, array &$dimensions) {
* An image style array.
*/
function image_style_flush($style) {
- $style_directory = drupal_realpath(file_default_scheme() . '://styles/' . $style['name']);
- if (is_dir($style_directory)) {
- file_unmanaged_delete_recursive($style_directory);
+ // Delete the style directory in each registered wrapper.
+ $wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE);
+ foreach ($wrappers as $wrapper => $wrapper_data) {
+ file_unmanaged_delete_recursive($wrapper . '://styles/' . $style['name']);
}
// Let other modules update as necessary on flush.
diff --git a/modules/image/image.test b/modules/image/image.test
index 59fc77d25..7db68e6c3 100644
--- a/modules/image/image.test
+++ b/modules/image/image.test
@@ -17,7 +17,6 @@
* image_style_save()
* image_style_delete()
* image_style_options()
- * image_style_flush()
* image_effect_definition_load()
* image_effect_load()
* image_effect_save()
@@ -1749,3 +1748,108 @@ class ImageThemeFunctionWebTestCase extends DrupalWebTestCase {
}
}
+
+/**
+ * Tests flushing of image styles.
+ */
+class ImageStyleFlushTest extends ImageFieldTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Image style flushing',
+ 'description' => 'Tests flushing of image styles.',
+ 'group' => 'Image',
+ );
+ }
+
+ /**
+ * Given an image style and a wrapper, generate an image.
+ */
+ function createSampleImage($style, $wrapper) {
+ static $file;
+
+ if (!isset($file)) {
+ $files = $this->drupalGetTestFiles('image');
+ $file = reset($files);
+ }
+
+ // Make sure we have an image in our wrapper testing file directory.
+ $source_uri = file_unmanaged_copy($file->uri, $wrapper . '://');
+ // Build the derivative image.
+ $derivative_uri = image_style_path($style['name'], $source_uri);
+ $derivative = image_style_create_derivative($style, $source_uri, $derivative_uri);
+
+ return $derivative ? $derivative_uri : FALSE;
+ }
+
+ /**
+ * Count the number of images currently created for a style in a wrapper.
+ */
+ function getImageCount($style, $wrapper) {
+ return count(file_scan_directory($wrapper . '://styles/' . $style['name'], '/.*/'));
+ }
+
+ /**
+ * General test to flush a style.
+ */
+ function testFlush() {
+
+ // Setup a style to be created and effects to add to it.
+ $style_name = strtolower($this->randomName(10));
+ $style_label = $this->randomString();
+ $style_path = 'admin/config/media/image-styles/edit/' . $style_name;
+ $effect_edits = array(
+ 'image_resize' => array(
+ 'data[width]' => 100,
+ 'data[height]' => 101,
+ ),
+ 'image_scale' => array(
+ 'data[width]' => 110,
+ 'data[height]' => 111,
+ 'data[upscale]' => 1,
+ ),
+ );
+
+ // Add style form.
+ $edit = array(
+ 'name' => $style_name,
+ 'label' => $style_label,
+ );
+ $this->drupalPost('admin/config/media/image-styles/add', $edit, t('Create new style'));
+ // Add each sample effect to the style.
+ foreach ($effect_edits as $effect => $edit) {
+ // Add the effect.
+ $this->drupalPost($style_path, array('new' => $effect), t('Add'));
+ if (!empty($edit)) {
+ $this->drupalPost(NULL, $edit, t('Add effect'));
+ }
+ }
+
+ // Load the saved image style.
+ $style = image_style_load($style_name);
+
+ // Create an image for the 'public' wrapper.
+ $image_path = $this->createSampleImage($style, 'public');
+ // Expecting to find 2 images, one is the sample.png image shown in
+ // image style preview.
+ $this->assertEqual($this->getImageCount($style, 'public'), 2, format_string('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
+
+ // Create an image for the 'private' wrapper.
+ $image_path = $this->createSampleImage($style, 'private');
+ $this->assertEqual($this->getImageCount($style, 'private'), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
+
+ // Remove the 'image_scale' effect and updates the style, which in turn
+ // forces an image style flush.
+ $effect = array_pop($style['effects']);
+ $this->drupalPost($style_path . '/effects/' . $effect['ieid'] . '/delete', array(), t('Delete'));
+ $this->assertResponse(200);
+ $this->drupalPost($style_path, array(), t('Update style'));
+ $this->assertResponse(200);
+
+ // Post flush, expected 1 image in the 'public' wrapper (sample.png).
+ $this->assertEqual($this->getImageCount($style, 'public'), 1, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style['name'], '%wrapper' => 'public')));
+
+ // Post flush, expected no image in the 'private' wrapper.
+ $this->assertEqual($this->getImageCount($style, 'private'), 0, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style['name'], '%wrapper' => 'private')));
+ }
+}