[limb-svn] r6812 - in 3.x/trunk/limb/imagekit/tests/cases: . im im/filters
svn at limb-project.com
svn at limb-project.com
Sat Mar 1 10:52:45 MSK 2008
Author: svk
Date: 2008-03-01 10:52:44 +0300 (Sat, 01 Mar 2008)
New Revision: 6812
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6812
Added:
3.x/trunk/limb/imagekit/tests/cases/im/
3.x/trunk/limb/imagekit/tests/cases/im/.skipif.php
3.x/trunk/limb/imagekit/tests/cases/im/filters/
3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImOutputImageFilterTest.class.php
3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImResizeImageFilterTest.class.php
3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImRotateImageFilterTest.class.php
3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImWaterMarkImageFilterTest.class.php
3.x/trunk/limb/imagekit/tests/cases/im/lmbImImageContainerTest.class.php
3.x/trunk/limb/imagekit/tests/cases/im/lmbImImageConvertorTest.class.php
Log:
-- tests for ImageMagick extension
Added: 3.x/trunk/limb/imagekit/tests/cases/im/.skipif.php
===================================================================
--- 3.x/trunk/limb/imagekit/tests/cases/im/.skipif.php (rev 0)
+++ 3.x/trunk/limb/imagekit/tests/cases/im/.skipif.php 2008-03-01 07:52:44 UTC (rev 6812)
@@ -0,0 +1,8 @@
+<?php
+if(!extension_loaded('imagick'))
+{
+ echo "Imagick library tests are skipped since Imagick extension is disabled.\n";
+ return true;
+}
+return false;
+
Added: 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImOutputImageFilterTest.class.php
===================================================================
--- 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImOutputImageFilterTest.class.php (rev 0)
+++ 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImOutputImageFilterTest.class.php 2008-03-01 07:52:44 UTC (rev 6812)
@@ -0,0 +1,27 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require(dirname(__FILE__).'/../../../../src/im/lmbImImageContainer.class.php');
+lmb_require(dirname(__FILE__).'/../../../../src/im/filters/lmbImOutputImageFilter.class.php');
+
+class lmbImOutputImageFilterTest extends UnitTestCase
+{
+
+ function testChangeOutput()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->setOutputType('gif');
+
+ $filter = new lmbImOutputImageFilter(array('type' => 'jpeg'));
+ $filter->apply($cont);
+
+ $this->assertEqual($cont->getOutputType(), 'jpeg');
+ }
+
+}
Added: 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImResizeImageFilterTest.class.php
===================================================================
--- 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImResizeImageFilterTest.class.php (rev 0)
+++ 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImResizeImageFilterTest.class.php 2008-03-01 07:52:44 UTC (rev 6812)
@@ -0,0 +1,97 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require(dirname(__FILE__).'/../../../../src/im/lmbImImageContainer.class.php');
+lmb_require(dirname(__FILE__).'/../../../../src/im/filters/lmbImResizeImageFilter.class.php');
+
+class lmbImResizeImageFilterTest extends UnitTestCase
+{
+
+ function _getInputImage()
+ {
+ return dirname(__FILE__).'/../../../var/input.jpg';
+ }
+
+ function _getOutputImage()
+ {
+ return dirname(__FILE__).'/../../../var/output.jpg';
+ }
+
+ function _getContainer()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->load($this->_getInputImage());
+ return $cont;
+ }
+
+ function testSimpleResize()
+ {
+ $cont = $this->_getContainer();
+ $filter = new lmbImResizeImageFilter(array('width' => 50, 'height' => 70, 'preserve_aspect_ratio' => false));
+
+ $filter->apply($cont);
+ $cont->save($this->_getOutputImage());
+ list($width, $height, $type) = getimagesize($this->_getOutputImage());
+ $this->assertEqual($width, 50);
+ $this->assertEqual($height, 70);
+ }
+
+ function testPreserveAspectRatio()
+ {
+ $filter = new lmbImResizeImageFilter(array());
+
+ list($w, $h) = $filter->calcSize(100, 60, 20, 30, true);
+ $this->assertEqual($w, 20);
+ $this->assertEqual($h, 12);
+
+ list($w, $h) = $filter->calcSize(60, 100, 20, 30, true);
+ $this->assertEqual($w, 18);
+ $this->assertEqual($h, 30);
+ }
+
+ function testSaveMinSize()
+ {
+ $filter = new lmbImResizeImageFilter(array());
+
+ list($w, $h) = $filter->calcSize(100, 60, 20, 30, true, true);
+ $this->assertEqual($w, 20);
+ $this->assertEqual($h, 12);
+
+ list($w, $h) = $filter->calcSize(60, 100, 20, 30, true, true);
+ $this->assertEqual($w, 18);
+ $this->assertEqual($h, 30);
+
+ list($w, $h) = $filter->calcSize(10, 20, 20, 30, true, true);
+ $this->assertEqual($w, 10);
+ $this->assertEqual($h, 20);
+
+ list($w, $h) = $filter->calcSize(10, 20, 20, 30, true);
+ $this->assertEqual($w, 15);
+ $this->assertEqual($h, 30);
+
+ list($w, $h) = $filter->calcSize(10, 20, 20, 30, false, true);
+ $this->assertEqual($w, 10);
+ $this->assertEqual($h, 20);
+ }
+
+ function testParams()
+ {
+ $filter = new lmbImResizeImageFilter(array('width' => 90, 'height' => 100, 'preserve_aspect_ratio' => false, 'save_min_size' => true));
+
+ $this->assertEqual($filter->getWidth(), 90);
+ $this->assertEqual($filter->getHeight(), 100);
+ $this->assertFalse($filter->getPreserveAspectRatio());
+ $this->assertTrue($filter->getSaveMinSize());
+ }
+
+ function tearDown()
+ {
+ @unlink($this->_getOutputImage());
+ }
+}
Added: 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImRotateImageFilterTest.class.php
===================================================================
--- 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImRotateImageFilterTest.class.php (rev 0)
+++ 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImRotateImageFilterTest.class.php 2008-03-01 07:52:44 UTC (rev 6812)
@@ -0,0 +1,60 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require(dirname(__FILE__).'/../../../../src/im/lmbImImageContainer.class.php');
+lmb_require(dirname(__FILE__).'/../../../../src/im/filters/lmbImRotateImageFilter.class.php');
+
+class lmbImRotateImageFilterTest extends UnitTestCase
+{
+
+ function _getInputImage()
+ {
+ return dirname(__FILE__).'/../../../var/input.jpg';
+ }
+
+ function _getOutputImage()
+ {
+ return dirname(__FILE__).'/../../../var/output.jpg';
+ }
+
+ function _getContainer()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->load($this->_getInputImage());
+ return $cont;
+ }
+
+ function testRotate()
+ {
+ $cont = $this->_getContainer();
+ $filter = new lmbImRotateImageFilter(array('angle' => 90));
+
+ $filter->apply($cont);
+ $cont->save($this->_getOutputImage());
+ list($width, $height, $type) = getimagesize($this->_getInputImage());
+ list($width2, $height2, $type2) = getimagesize($this->_getOutputImage());
+ $this->assertEqual($width, $height2);
+ $this->assertEqual($height, $width2);
+ $this->assertEqual($type, $type2);
+ }
+
+ function testParams()
+ {
+ $filter = new lmbImRotateImageFilter(array('angle' => 90, 'bgcolor' => 'FF0000'));
+
+ $this->assertEqual($filter->getAngle(), 90);
+ $bgcolor = $filter->getBgColor();
+ $this->assertEqual($bgcolor, 'FF0000');
+ }
+
+ function tearDown()
+ {
+ @unlink($this->_getOutputImage());
+ }
+}
Added: 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImWaterMarkImageFilterTest.class.php
===================================================================
--- 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImWaterMarkImageFilterTest.class.php (rev 0)
+++ 3.x/trunk/limb/imagekit/tests/cases/im/filters/lmbImWaterMarkImageFilterTest.class.php 2008-03-01 07:52:44 UTC (rev 6812)
@@ -0,0 +1,87 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require(dirname(__FILE__).'/../../../../src/im/lmbImImageContainer.class.php');
+lmb_require(dirname(__FILE__).'/../../../../src/im/filters/lmbImWaterMarkImageFilter.class.php');
+
+class lmbImWaterMarkImageFilterTest extends UnitTestCase
+{
+
+ function _getInputImage()
+ {
+ return dirname(__FILE__).'/../../../var/input.jpg';
+ }
+
+ function _getWaterMarkImage()
+ {
+ return dirname(__FILE__).'/../../../var/water_mark.gif';
+ }
+
+ function _getOutputImage()
+ {
+ return dirname(__FILE__).'/../../../var/output.jpg';
+ }
+
+ function _getContainer()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->load($this->_getInputImage());
+ return $cont;
+ }
+
+ function testWaterMark()
+ {
+ $cont = $this->_getContainer();
+ $filter = new lmbImWaterMarkImageFilter(array('water_mark' => $this->_getWaterMarkImage(), 'x' => 5, 'y' => 6));
+
+ $filter->apply($cont);
+ $cont->save($this->_getOutputImage());
+ list($width, $height, $type) = getimagesize($this->_getInputImage());
+ list($width2, $height2, $type2) = getimagesize($this->_getOutputImage());
+ $this->assertEqual($width, $width2);
+ $this->assertEqual($height, $height2);
+ $this->assertEqual($type, $type2);
+ }
+
+ function testParams()
+ {
+ $filter = new lmbImWaterMarkImageFilter(array('water_mark' => 'input.jpg', 'x' => 90, 'y' => 100, 'opacity' => 20));
+
+ $this->assertEqual($filter->getWaterMark(), 'input.jpg');
+ $this->assertEqual($filter->getX(), 90);
+ $this->assertEqual($filter->getY(), 100);
+ $this->assertEqual($filter->getOpacity(), 20);
+ }
+
+ function testCalcPosition()
+ {
+ $filter = new lmbImWaterMarkImageFilter(array());
+
+ $result = $filter->calcPosition(10, 100, 150, 250);
+ $this->assertEqual($result[0], 10);
+ $this->assertEqual($result[1], 100);
+
+ $result = $filter->calcPosition(-10, 100, 150, 250);
+ $this->assertEqual($result[0], 140);
+ $this->assertEqual($result[1], 100);
+
+ $result = $filter->calcPosition(10, -100, 150, 250);
+ $this->assertEqual($result[0], 10);
+ $this->assertEqual($result[1], 150);
+
+ $result = $filter->calcPosition(-10, -100, 150, 250);
+ $this->assertEqual($result[0], 140);
+ $this->assertEqual($result[1], 150);
+ }
+
+ function tearDown()
+ {
+ @unlink($this->_getOutputImage());
+ }
+}
Added: 3.x/trunk/limb/imagekit/tests/cases/im/lmbImImageContainerTest.class.php
===================================================================
--- 3.x/trunk/limb/imagekit/tests/cases/im/lmbImImageContainerTest.class.php (rev 0)
+++ 3.x/trunk/limb/imagekit/tests/cases/im/lmbImImageContainerTest.class.php 2008-03-01 07:52:44 UTC (rev 6812)
@@ -0,0 +1,101 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require(dirname(__FILE__).'/../../../src/im/lmbImImageContainer.class.php');
+
+class lmbImImageContainerTest extends UnitTestCase
+{
+
+ function _getInputImage()
+ {
+ return dirname(__FILE__).'/../../var/input.jpg';
+ }
+
+ function _getPalleteImage()
+ {
+ return dirname(__FILE__).'/../../var/water_mark.gif';
+ }
+
+ function _getOutputImage()
+ {
+ return dirname(__FILE__).'/../../var/output.jpg';
+ }
+
+ function _getOutputImageGif()
+ {
+ return dirname(__FILE__).'/../../var/output.gif';
+ }
+
+ function _getOutputImagePng()
+ {
+ return dirname(__FILE__).'/../../var/output.png';
+ }
+
+ function testLoadSave()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->load($this->_getInputImage());
+ $cont->save($this->_getOutputImage());
+
+ list($width, $height, $type) = getimagesize($this->_getInputImage());
+ list($width2, $height2, $type2) = getimagesize($this->_getOutputImage());
+ $this->assertEqual($width, $width2);
+ $this->assertEqual($height, $height2);
+ $this->assertEqual($type, $type2);
+ }
+
+ function testChangeType()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->load($this->_getInputImage(), 'JPEG');
+ $cont->setOutputType('PNG');
+ $cont->save($this->_getOutputImagePng());
+ list($width, $height, $type) = getimagesize($this->_getInputImage());
+ list($width2, $height2, $type2) = getimagesize($this->_getOutputImagePng());
+ $this->assertEqual($width, $width2);
+ $this->assertEqual($height, $height2);
+ $this->assertNotEqual($type, $type2);
+ $this->assertEqual(lmbImImageContainer::convertImageType($type), "JPEG");
+ $this->assertEqual(lmbImImageContainer::convertImageType($type2), "PNG");
+ }
+
+ function testGetSize()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->load($this->_getInputImage());
+
+ $this->assertEqual($cont->getWidth(), 100);
+ $this->assertEqual($cont->getHeight(), 137);
+ }
+
+ function testIsPallete()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->load($this->_getInputImage());
+ $this->assertFalse($cont->isPallete());
+
+ $cont->load($this->_getPalleteImage());
+ $this->assertTrue($cont->isPallete());
+ }
+
+ function testSetGetOutputType()
+ {
+ $cont = new lmbImImageContainer();
+ $cont->setOutputType('gif');
+
+ $this->assertEqual($cont->getOutputType(), 'gif');
+ }
+
+ function tearDown()
+ {
+ @unlink($this->_getOutputImage());
+ @unlink($this->_getOutputImageGif());
+ @unlink($this->_getOutputImagePng());
+ }
+}
Added: 3.x/trunk/limb/imagekit/tests/cases/im/lmbImImageConvertorTest.class.php
===================================================================
--- 3.x/trunk/limb/imagekit/tests/cases/im/lmbImImageConvertorTest.class.php (rev 0)
+++ 3.x/trunk/limb/imagekit/tests/cases/im/lmbImImageConvertorTest.class.php 2008-03-01 07:52:44 UTC (rev 6812)
@@ -0,0 +1,83 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require(dirname(__FILE__).'/../../../src/im/lmbImImageConvertor.class.php');
+
+class lmbImImageConvertorTest extends UnitTestCase
+{
+
+ function _getInputImage()
+ {
+ return dirname(__FILE__).'/../../var/input.jpg';
+ }
+
+ function _getOutputImage()
+ {
+ return dirname(__FILE__).'/../../var/output1.jpg';
+ }
+
+ function _getConvertor()
+ {
+ return new lmbImImageConvertor();
+ }
+
+ function testApply()
+ {
+ $conv = $this->_getConvertor();
+ $conv->load($this->_getInputImage());
+ $conv->apply('resize', array('width' => 50, 'height' => 70, 'preserve_aspect_ratio' => false));
+
+ $conv->save($this->_getOutputImage());
+ list($width, $height, $type) = getimagesize($this->_getOutputImage());
+ $this->assertEqual($width, 50);
+ $this->assertEqual($height, 70);
+ }
+
+ function testApplyByOverload()
+ {
+ $conv = $this->_getConvertor();
+ $conv->load($this->_getInputImage());
+ $conv->resize(array('width' => 50, 'height' => 70, 'preserve_aspect_ratio' => false, 'xxx' => true));
+
+ $conv->save($this->_getOutputImage());
+ list($width, $height, $type) = getimagesize($this->_getOutputImage());
+ $this->assertEqual($width, 50);
+ $this->assertEqual($height, 70);
+ }
+
+ function testApplyBatch()
+ {
+ $batch = array(
+ array('resize' => array('width' => 50, 'height' => 60, 'preserve_aspect_ratio' => false, 'xxx' => true)),
+ array('rotate' => array('angle' => 90))
+ );
+ $conv = $this->_getConvertor();
+ $conv->load($this->_getInputImage());
+ $conv->applyBatch($batch);
+
+ $conv->save($this->_getOutputImage());
+ list($width, $height, $type) = getimagesize($this->_getOutputImage());
+ $this->assertEqual($width, 60);
+ $this->assertEqual($height, 50);
+ }
+
+ function testCheckSupportConv()
+ {
+ $conv = $this->_getConvertor();
+
+ $this->assertTrue($conv->isSupportConversion('', 'jpeg', 'gif'));
+ $this->assertTrue($conv->isSupportConversion($this->_getInputImage()));
+ $this->assertFalse($conv->isSupportConversion($this->_getInputImage(), '', 'zxzx'));
+ }
+
+ function tearDown()
+ {
+ @unlink($this->_getOutputImage());
+ }
+}
More information about the limb-svn
mailing list