Permalink
Browse files

BUG Cached images stored in wrong folder

If multiple image manipulations are performend the resulting cached image is stored in assets/_resampled because the cached version of the image has no ParentID, which cacheFilename needs to set the correct path.
  • Loading branch information...
1 parent 0ac9eff commit b8495da5d9576ebf5cc1ed4c4e2cf60a64f6f5c8 @johannesx75 johannesx75 committed Aug 26, 2013
Showing with 35 additions and 0 deletions.
  1. +2 −0 model/Image.php
  2. +33 −0 tests/model/ImageTest.php
View
@@ -425,6 +425,8 @@ public function getFormattedImage($format) {
$cached = new Image_Cached($cacheFile);
// Pass through the title so the templates can use it
$cached->Title = $this->Title;
+ // Pass through the parent, to store cached images in correct folder.
+ $cached->ParentID = $this->ParentID;
return $cached;
}
}
View
@@ -181,4 +181,37 @@ public function testGeneratedImageDeletion() {
$image->deleteFormattedImages();
$this->assertFalse(file_exists($p));
}
+
+ /**
+ * Tests that generated images with multiple image manipulations are all deleted
+ */
+ public function testMultipleGenerateManipulationCallsImageDeletion() {
+ $image = $this->objFromFixture('Image', 'imageWithMetacharacters');
+
+ $firstImage = $image->SetWidth(200);
+ $firstImagePath = $firstImage->getFullPath();
+ $this->assertTrue(file_exists($firstImagePath));
+
+ $secondImage = $firstImage->SetHeight(100);
+ $secondImagePath = $secondImage->getFullPath();
+ $this->assertTrue(file_exists($secondImagePath));
+
+ $image->deleteFormattedImages();
+ $this->assertFalse(file_exists($firstImagePath));
+ $this->assertFalse(file_exists($secondImagePath));
+ }
+
+ /**
+ * Tests path properties of cached images with multiple image manipulations
+ */
+ public function testPathPropertiesCachedImage() {
+ $image = $this->objFromFixture('Image', 'imageWithMetacharacters');
+ $firstImage = $image->SetWidth(200);
+ $firstImagePath = $firstImage->getRelativePath();
+ $this->assertEquals($firstImagePath, $firstImage->Filename);
+
+ $secondImage = $firstImage->SetHeight(100);
+ $secondImagePath = $secondImage->getRelativePath();
+ $this->assertEquals($secondImagePath, $secondImage->Filename);
+ }
}

0 comments on commit b8495da

Please sign in to comment.