Merge pull request #2366 from johannesx75/Cached-Images-Path2

BUG Cached images stored in wrong folder
This commit is contained in:
Ingo Schommer 2013-08-28 06:48:49 -07:00
commit eaa78b98b8
2 changed files with 35 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}