2012-10-25 00:28:39 +02:00
|
|
|
<?php
|
2014-01-02 16:59:34 +01:00
|
|
|
|
2012-10-25 00:28:39 +02:00
|
|
|
class GDImageTest extends ImageTest {
|
2014-01-02 16:59:34 +01:00
|
|
|
|
2012-10-25 00:28:39 +02:00
|
|
|
public function setUp() {
|
|
|
|
if(!extension_loaded("gd")) {
|
|
|
|
$this->markTestSkipped("The GD extension is required");
|
|
|
|
$this->skipTest = true;
|
|
|
|
parent::setUp();
|
|
|
|
return;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-25 00:28:39 +02:00
|
|
|
parent::setUp();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-25 00:28:39 +02:00
|
|
|
Image::set_backend("GDBackend");
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-25 00:28:39 +02:00
|
|
|
// Create a test files for each of the fixture references
|
|
|
|
$fileIDs = $this->allFixtureIDs('Image');
|
|
|
|
foreach($fileIDs as $fileID) {
|
|
|
|
$file = DataObject::get_by_id('Image', $fileID);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-25 00:28:39 +02:00
|
|
|
$image = imagecreatetruecolor(300,300);
|
|
|
|
|
|
|
|
imagepng($image, BASE_PATH."/{$file->Filename}");
|
|
|
|
imagedestroy($image);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-25 00:28:39 +02:00
|
|
|
$file->write();
|
|
|
|
}
|
|
|
|
}
|
2014-01-02 16:59:34 +01:00
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
$cache = SS_Cache::factory('GDBackend_Manipulations');
|
|
|
|
$cache->clean(Zend_Cache::CLEANING_MODE_ALL);
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the cache of manipulation failures is cleared when deleting
|
|
|
|
* the image object
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCacheCleaningOnDelete() {
|
|
|
|
$image = $this->objFromFixture('Image', 'imageWithTitle');
|
|
|
|
$cache = SS_Cache::factory('GDBackend_Manipulations');
|
|
|
|
$fullPath = $image->getFullPath();
|
|
|
|
$key = md5(implode('_', array($fullPath, filemtime($fullPath))));
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Simluate a failed manipulation
|
|
|
|
$gdFailure = new GDBackend_Failure($fullPath, array('SetWidth', 123));
|
|
|
|
$this->fail('GDBackend_Failure should throw an exception when setting image resource');
|
|
|
|
} catch (GDBackend_Failure_Exception $e) {
|
|
|
|
// Check that the cache has stored the manipulation failure
|
|
|
|
$data = unserialize($cache->load($key));
|
|
|
|
$this->assertArrayHasKey('SetWidth|123', $data);
|
|
|
|
$this->assertTrue($data['SetWidth|123']);
|
|
|
|
|
|
|
|
// Delete the image object
|
|
|
|
$image->delete();
|
|
|
|
|
|
|
|
// Check that the cache has been removed
|
|
|
|
$data = unserialize($cache->load($key));
|
|
|
|
$this->assertFalse($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 00:28:39 +02:00
|
|
|
}
|