From b8495da5d9576ebf5cc1ed4c4e2cf60a64f6f5c8 Mon Sep 17 00:00:00 2001 From: "Johannes Hammersen, x75" Date: Mon, 26 Aug 2013 10:16:42 +0200 Subject: [PATCH] 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. --- model/Image.php | 2 ++ tests/model/ImageTest.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/model/Image.php b/model/Image.php index 006135bdb..07214b736 100644 --- a/model/Image.php +++ b/model/Image.php @@ -425,6 +425,8 @@ class Image extends File { $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; } } diff --git a/tests/model/ImageTest.php b/tests/model/ImageTest.php index d29cd1984..8ec1e28ee 100644 --- a/tests/model/ImageTest.php +++ b/tests/model/ImageTest.php @@ -181,4 +181,37 @@ class ImageTest extends SapphireTest { $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); + } }