summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/image/image.module2
-rw-r--r--modules/simpletest/tests/image.test41
2 files changed, 42 insertions, 1 deletions
diff --git a/modules/image/image.module b/modules/image/image.module
index 066bd34..35f1068 100644
--- a/modules/image/image.module
+++ b/modules/image/image.module
@@ -326,7 +326,7 @@ function image_file_download($uri) {
*/
function image_file_move($file, $source) {
// Delete any image derivatives at the original image path.
- image_path_flush($file->uri);
+ image_path_flush($source->uri);
}
/**
diff --git a/modules/simpletest/tests/image.test b/modules/simpletest/tests/image.test
index 60599be..962aa66 100644
--- a/modules/simpletest/tests/image.test
+++ b/modules/simpletest/tests/image.test
@@ -458,3 +458,44 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
}
}
+
+/**
+ * Tests the file move function for managed files.
+ */
+class ImageFileMoveTest extends ImageToolkitTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Image moving',
+ 'description' => 'Tests the file move function for managed files.',
+ 'group' => 'Image',
+ );
+ }
+
+ /**
+ * Tests moving a randomly generated image.
+ */
+ function testNormal() {
+ // Pick a file for testing.
+ $file = current($this->drupalGetTestFiles('image'));
+
+ // Create derivative image.
+ $style = image_style_load(key(image_styles()));
+ $derivative_uri = image_style_path($style['name'], $file->uri);
+ image_style_create_derivative($style, $file->uri, $derivative_uri);
+
+ // Check if derivative image exists.
+ $this->assertTrue(file_exists($derivative_uri), 'Make sure derivative image is generated successfully.');
+
+ // Clone the object so we don't have to worry about the function changing
+ // our reference copy.
+ $desired_filepath = 'public://' . $this->randomName();
+ $result = file_move(clone $file, $desired_filepath, FILE_EXISTS_ERROR);
+
+ // Check if image has been moved.
+ $this->assertTrue(file_exists($result->uri), 'Make sure image is moved successfully.');
+
+ // Check if derivative image has been flushed.
+ $this->assertFalse(file_exists($derivative_uri), 'Make sure derivative image has been flushed.');
+ }
+}
+