diff options
author | sybio <clement.guillemain@gmail.com> | 2012-05-04 22:01:51 +0200 |
---|---|---|
committer | sybio <clement.guillemain@gmail.com> | 2012-05-04 22:01:51 +0200 |
commit | a511b89b54c720d49622149d80da721d2acea7af (patch) | |
tree | a069b20a35839573694e2b9112d41f7ae4ce4ca0 | |
parent | 286ae1ad6f73b5107755395cd52260264cbd9d50 (diff) | |
download | ImageWorkshop-a511b89b54c720d49622149d80da721d2acea7af.zip ImageWorkshop-a511b89b54c720d49622149d80da721d2acea7af.tar.gz ImageWorkshop-a511b89b54c720d49622149d80da721d2acea7af.tar.bz2 |
Added some tests
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | src/ImageWorkshop.php | 44 | ||||
-rw-r--r-- | tests/ImageWorkshopTest.php | 234 |
3 files changed, 242 insertions, 38 deletions
@@ -4,4 +4,4 @@ ImageWorkshop class Most flexible PHP class to work with images using the GD Library
-! Already under development !
\ No newline at end of file +! Under development !
diff --git a/src/ImageWorkshop.php b/src/ImageWorkshop.php index f554e79..93395cb 100644 --- a/src/ImageWorkshop.php +++ b/src/ImageWorkshop.php @@ -39,28 +39,28 @@ class ImageWorkshop /**
* @var layersLevels
*
- * Levels positions of the layers (or groups) in the document
+ * Levels positions of the sublayers in the stack
*/
protected $layersLevels;
/**
* @var layersPositions
*
- * Positions (x and y) of the layers (or groups) in the document
+ * Positions (x and y) of the sublayers in the stack
*/
protected $layersPositions;
/**
* @var lastLayerId
*
- * Id of the last indexes layer (or group)
+ * Id of the last indexes sublayer
*/
protected $lastLayerId;
/**
* @var highestLayerLevel
*
- * The highest layer (or group) level
+ * The highest sublayer level
*/
protected $highestLayerLevel;
@@ -194,7 +194,7 @@ class ImageWorkshop }
/**
- * TODO: revoir le imagecopy (transparence ?)
+ * @todo revoir le imagecopy (transparence ?)
*
* Paste an image on the layer
* You can specify the position left (in pixels) and the position top (in pixels) of the added image relatives to the layer
@@ -237,8 +237,9 @@ class ImageWorkshop return $this->indexLayer($layerLevel, $layer, $positionX, $positionY, $position);
}
- /* TODO */
/**
+ * @todo
+ *
* Merge a layer with another layer under it on the stack
* Note: the result layer will conserve the given id
* Return true if success or false if layer isn't found or don't has a layer under it
@@ -282,8 +283,9 @@ class ImageWorkshop $this->clearStack();
}
- /* TODO */
/**
+ * @todo
+ *
* Move a sublayer on the top of a group stack
* Return layer level if success or false otherwise
*
@@ -311,8 +313,9 @@ class ImageWorkshop return $this->moveTo($layerId, 1, true);
}
- /* TODO */
/**
+ * @todo
+ *
* Move a sublayer to the level $level of a group stack
* Return layer level if success or false if layer isn't found
*
@@ -475,8 +478,9 @@ class ImageWorkshop return false;
}
- /* TODO */
/**
+ * @todo
+ *
* Delete a layer
*
* @param integer $layerId
@@ -547,7 +551,7 @@ class ImageWorkshop *
* @return boolean
*/
- public function isLayerInIndex($layerId)
+ public function isLayerInIndex($layerId)
{
// if the layer exists in document
if (array_key_exists($layerId, $this->layers)) {
@@ -1872,5 +1876,25 @@ class ImageWorkshop {
return $this->layersPositions;
}
+
+ /**
+ * Getter highestLayerLevel
+ *
+ * @return array
+ */
+ public function getHighestLayerLevel()
+ {
+ return $this->highestLayerLevel;
+ }
+
+ /**
+ * Getter lastLayerId
+ *
+ * @return array
+ */
+ public function getLastLayerId()
+ {
+ return $this->lastLayerId;
+ }
}
?>
\ No newline at end of file diff --git a/tests/ImageWorkshopTest.php b/tests/ImageWorkshopTest.php index 9dbe9d2..6a33a8f 100644 --- a/tests/ImageWorkshopTest.php +++ b/tests/ImageWorkshopTest.php @@ -5,122 +5,302 @@ class ImageWorkshopTest extends PHPUnit_Framework_TestCase {
/**
* @todo
+ *
+ * Test pasteImage
+ *
*/
- public function testPasteImage()
+ /*public function testPasteImage()
{
$this->assertTrue(false);
- }
+ }*/
/**
* @todo
+ *
+ * Test addLayer
+ *
*/
- public function testAddLayer()
+ /*public function testAddLayer()
{
$this->assertTrue(false);
- }
+ }*/
/**
* @todo
+ *
+ * Test mergeDown
+ *
*/
- public function testMergeDown()
+ /*public function testMergeDown()
{
+ $layer = new ImageWorkshop(array(
+ "width" => 300,
+ "height" => 200,
+ ));
+
$this->assertTrue(false);
- }
+ }*/
/**
- * @todo
+ * Test mergeAll
*/
public function testMergeAll()
{
- $this->assertTrue(false);
+ $layer = $this->initializeLayer(2);
+
+ $layer->mergeAll();
+
+ $layerPositions = $layer->getLayersPositions();
+ $layersLevels = $layer->getLayersLevels();
+ $highestLayerLevel = $layer->getHighestLayerLevel();
+ $lastLayerId = $layer->getLastLayerId();
+
+ $array = array();
+
+ $this->assertEquals($layerPositions, $array, 'Expect $layerPositions to be an empty array');
+
+ $this->assertEquals($layerPositions, $array, 'Expect $layersLevels to be an empty array');
+
+ $this->assertTrue($highestLayerLevel === 0, 'Expect $highestLayerLevel to be 0');
+
+ $this->assertTrue($lastLayerId === 0, 'Expect $lastLayerId to be 0');
}
/**
- * @todo
+ * test moveTop
*/
public function testMoveTop()
{
- $this->assertTrue(false);
+ $layer = $this->initializeLayer(2);
+
+ $layer->moveTop(2);
+
+ $layersLevels = $layer->getLayersLevels();
+
+ $array = array(
+ 1 => 1,
+ 2 => 3,
+ 3 => 4,
+ 4 => 2,
+ );
+
+ $this->assertTrue($layersLevels == $array, 'Expect $layersLevels to be the array $array');
}
/**
- * @todo
+ * Test moveBottom
*/
public function testMoveBottom()
{
- $this->assertTrue(false);
+ $layer = $this->initializeLayer(2);
+
+ $layer->moveBottom(3);
+
+ $layersLevels = $layer->getLayersLevels();
+
+ $array = array(
+ 1 => 3,
+ 2 => 1,
+ 3 => 2,
+ 4 => 4,
+ );
+
+ $this->assertTrue($layersLevels == $array, 'Expect $layersLevels to be the array $array');
}
/**
* @todo
+ *
+ * Test moveTo
+ *
*/
- public function testMoveTo()
+ /*public function testMoveTo()
{
$this->assertTrue(false);
- }
+ }*/
/**
* @todo
+ *
+ * Test moveUp
+ *
*/
public function testMoveUp()
{
- $this->assertTrue(false);
+ // Test moveUp on a sublayer not positionned at the highest level
+
+ $layer = $this->initializeLayer(2);
+
+ $layer->moveUp(2);
+
+ $layersLevels = $layer->getLayersLevels();
+
+ $array = array(
+ 1 => 1,
+ 2 => 3,
+ 3 => 2,
+ 4 => 4,
+ );
+
+ $this->assertTrue($layersLevels == $array, 'Expect $layersLevels to be the array $array');
+
+ // Test moveUp on a the sublayer at the highest level
+
+ $layer = $this->initializeLayer(2);
+
+ $layer->moveUp(4);
+
+ $layersLevels = $layer->getLayersLevels();
+
+ $array = array(
+ 1 => 1,
+ 2 => 2,
+ 3 => 3,
+ 4 => 4,
+ );
+
+ $this->assertTrue($layersLevels == $array, 'Expect $layersLevels to be the array $array');
}
/**
* @todo
+ *
+ * Test moveDown
+ *
*/
public function testMoveDown()
{
- $this->assertTrue(false);
+ // Test moveBottom on a sublayer not positionned at the lowest level
+
+ $layer = $this->initializeLayer(2);
+
+ $layer->moveBottom(3);
+
+ $layersLevels = $layer->getLayersLevels();
+
+ $array = array(
+ 1 => 1,
+ 2 => 3,
+ 3 => 2,
+ 4 => 4,
+ );
+
+ $this->assertTrue($layersLevels == $array, 'Expect $layersLevels to be the array $array');
+
+ // Test moveBottom on a sublayer at the lowest level
+
+ $layer = $this->initializeLayer(2);
+
+ $layer->moveBottom(1);
+
+ $layersLevels = $layer->getLayersLevels();
+
+ $array = array(
+ 1 => 1,
+ 2 => 2,
+ 3 => 3,
+ 4 => 4,
+ );
+
+ $this->assertTrue($layersLevels == $array, 'Expect $layersLevels to be the array $array');
}
/**
* @todo
+ *
+ * Test remove
+ *
*/
- public function testRemove()
+ /*public function testRemove()
{
$this->assertTrue(false);
- }
+ }*/
/**
* @todo
+ *
+ * Test getLayerLevel
+ *
*/
- public function testGetLayerLevel()
+ /*public function testGetLayerLevel()
{
$this->assertTrue(false);
- }
+ }*/
/**
- * @todo
+ * Test isLayerInIndex
*/
public function testIsLayerInIndex()
{
- $this->assertTrue(false);
+ $layer = $this->initializeLayer(2);
+
+ $this->assertTrue($layer->isLayerInIndex(3) === true, 'Layer of id 3 must be in the stack');
+
+ $this->assertTrue($layer->isLayerInIndex(5) === false, 'Layer of id 5 would not exist in the stack');
}
/**
* @todo
+ *
+ * Test generateImage
+ *
*/
- public function testGenerateImage()
+ /*public function testGenerateImage()
{
$this->assertTrue(false);
- }
+ }*/
/**
* @todo
+ *
+ * Test resizeByPixel
+ *
*/
- public function testResizeByPixel()
+ /*public function testResizeByPixel()
{
$this->assertTrue(false);
- }
+ }*/
/**
* @todo
+ *
+ * Test resizeByPourcent
+ *
*/
- public function testResizeByPourcent()
+ /*public function testResizeByPourcent()
{
$this->assertTrue(false);
+ }*/
+
+ /**
+ * Initialize a layer
+ *
+ * @param integer $method
+ */
+ protected function initializeLayer($method = 1)
+ {
+ $layer = new ImageWorkshop(array(
+ "width" => 100,
+ "height" => 75,
+ ));
+
+ switch ($method) {
+
+ case 1:
+
+ ;
+
+ case 2: // Add 4 sublayers in $layer stack
+
+ $layer->addLayer(1, $layer);
+ $layer->addLayer(2, $layer);
+ $layer->addLayer(3, $layer);
+ $layer->addLayer(4, $layer);
+
+ ;
+ }
+
+ return $layer;
}
}
?>
\ No newline at end of file |