2009-05-24 14:16:17 +02:00
|
|
|
<?php
|
2010-12-20 03:19:17 +01:00
|
|
|
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-12-20 03:19:17 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2009-05-24 14:16:17 +02:00
|
|
|
class ImageTest extends SapphireTest {
|
2010-12-20 03:19:17 +01:00
|
|
|
|
2011-03-30 08:49:11 +02:00
|
|
|
static $fixture_file = 'ImageTest.yml';
|
2010-12-20 03:19:17 +01:00
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
if(!file_exists(ASSETS_PATH)) mkdir(ASSETS_PATH);
|
|
|
|
|
|
|
|
// Create a test folders for each of the fixture references
|
|
|
|
$folderIDs = $this->allFixtureIDs('Folder');
|
|
|
|
|
|
|
|
foreach($folderIDs as $folderID) {
|
|
|
|
$folder = DataObject::get_by_id('Folder', $folderID);
|
|
|
|
|
|
|
|
if(!file_exists(BASE_PATH."/$folder->Filename")) mkdir(BASE_PATH."/$folder->Filename");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
$image = imagecreatetruecolor(300,300);
|
|
|
|
|
|
|
|
imagepng($image, BASE_PATH."/$file->Filename");
|
|
|
|
imagedestroy($image);
|
|
|
|
|
|
|
|
$file->write();
|
|
|
|
}
|
|
|
|
}
|
2009-05-24 14:16:17 +02:00
|
|
|
|
|
|
|
function testGetTagWithTitle() {
|
2009-07-08 02:06:16 +02:00
|
|
|
$image = $this->objFromFixture('Image', 'imageWithTitle');
|
2010-10-15 05:17:14 +02:00
|
|
|
$expected = '<img src="' . Director::baseUrl() . 'assets/ImageTest/test_image.png" alt="This is a image Title" />';
|
2009-05-24 14:16:17 +02:00
|
|
|
$actual = $image->getTag();
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetTagWithoutTitle() {
|
2009-07-08 02:06:16 +02:00
|
|
|
$image = $this->objFromFixture('Image', 'imageWithoutTitle');
|
2010-10-15 05:17:14 +02:00
|
|
|
$expected = '<img src="' . Director::baseUrl() . 'assets/ImageTest/test_image.png" alt="test_image" />';
|
2009-05-24 14:16:17 +02:00
|
|
|
$actual = $image->getTag();
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetTagWithoutTitleContainingDots() {
|
2009-07-08 02:06:16 +02:00
|
|
|
$image = $this->objFromFixture('Image', 'imageWithoutTitleContainingDots');
|
2010-10-15 05:17:14 +02:00
|
|
|
$expected = '<img src="' . Director::baseUrl() . 'assets/ImageTest/test.image.with.dots.png" alt="test.image.with.dots" />';
|
2009-05-24 14:16:17 +02:00
|
|
|
$actual = $image->getTag();
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
2010-10-15 05:17:14 +02:00
|
|
|
|
|
|
|
function tearDown() {
|
|
|
|
/* Remove the test files that we've created */
|
|
|
|
$fileIDs = $this->allFixtureIDs('Image');
|
|
|
|
foreach($fileIDs as $fileID) {
|
|
|
|
$file = DataObject::get_by_id('Image', $fileID);
|
|
|
|
if($file && file_exists(BASE_PATH."/$file->Filename")) unlink(BASE_PATH."/$file->Filename");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the test folders that we've crated */
|
|
|
|
$folderIDs = $this->allFixtureIDs('Folder');
|
|
|
|
foreach($folderIDs as $folderID) {
|
|
|
|
$folder = DataObject::get_by_id('Folder', $folderID);
|
|
|
|
if($folder && file_exists(BASE_PATH."/$folder->Filename")) Filesystem::removeFolder(BASE_PATH."/$folder->Filename");
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2010-12-20 03:19:17 +01:00
|
|
|
|
|
|
|
function testMultipleGenerateManipulationCalls() {
|
|
|
|
$image = $this->objFromFixture('Image', 'imageWithoutTitle');
|
|
|
|
|
|
|
|
$imageFirst = $image->SetWidth(200);
|
|
|
|
$this->assertNotNull($imageFirst);
|
|
|
|
$expected = 200;
|
|
|
|
$actual = $imageFirst->getWidth();
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
|
|
|
|
$imageSecond = $imageFirst->setHeight(100);
|
|
|
|
$this->assertNotNull($imageSecond);
|
|
|
|
$expected = 100;
|
|
|
|
$actual = $imageSecond->getHeight();
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
2011-10-31 18:16:03 +01:00
|
|
|
|
|
|
|
function testGeneratedImageDeletion() {
|
|
|
|
$image = $this->objFromFixture('Image', 'imageWithMetacharacters');
|
|
|
|
$image_generated = $image->SetWidth(200);
|
|
|
|
$p = $image_generated->getFullPath();
|
|
|
|
$this->assertTrue(file_exists($p));
|
|
|
|
$image->deleteFormattedImages();
|
|
|
|
$this->assertFalse(file_exists($p));
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|