| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Barcode
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- require_once dirname(__FILE__) . '/TestCommon.php';
- require_once 'Zend/Barcode/Renderer/Image.php';
- require_once 'Zend/Barcode/Object/Code39.php';
- /**
- * @category Zend
- * @package Zend_Barcode
- * @subpackage UnitTests
- * @group Zend_Barcode
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Barcode_Renderer_ImageTest extends Zend_Barcode_Renderer_TestCommon
- {
- public function setUp()
- {
- if (!extension_loaded('gd')) {
- $this->markTestSkipped('Zend_Barcode_Renderer_ImageTest requires the GD extension');
- }
- parent::setUp();
- }
- protected function _getRendererObject($options = null)
- {
- return new Zend_Barcode_Renderer_Image($options);
- }
- public function testType()
- {
- $this->assertSame('image', $this->_renderer->getType());
- }
- public function testGoodImageResource()
- {
- $imageResource = imagecreatetruecolor(1, 1);
- $this->_renderer->setResource($imageResource);
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testObjectImageResource()
- {
- $imageResource = new StdClass();
- $this->_renderer->setResource($imageResource);
- }
- public function testGoodHeight()
- {
- $this->assertSame(0, $this->_renderer->getHeight());
- $this->_renderer->setHeight(123);
- $this->assertSame(123, $this->_renderer->getHeight());
- $this->_renderer->setHeight(0);
- $this->assertSame(0, $this->_renderer->getHeight());
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testBadHeight()
- {
- $this->_renderer->setHeight(- 1);
- }
- public function testGoodWidth()
- {
- $this->assertSame(0, $this->_renderer->getWidth());
- $this->_renderer->setWidth(123);
- $this->assertSame(123, $this->_renderer->getWidth());
- $this->_renderer->setWidth(0);
- $this->assertSame(0, $this->_renderer->getWidth());
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testBadWidth()
- {
- $this->_renderer->setWidth(- 1);
- }
- public function testAllowedImageType()
- {
- $types = array('gif' => 'gif' , 'jpg' => 'jpeg' , 'jpeg' => 'jpeg' ,
- 'png' => 'png');
- foreach ($types as $type => $expectedType) {
- $this->_renderer->setImageType($type);
- $this->assertSame($expectedType,
- $this->_renderer->getImageType());
- }
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testNonAllowedImageType()
- {
- $this->_renderer->setImageType('other');
- }
- public function testDrawReturnResource()
- {
- $this->_checkTTFRequirement();
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->_renderer->setBarcode($barcode);
- $resource = $this->_renderer->draw();
- $this->assertTrue(gettype($resource) == 'resource', 'Image must be a resource');
- $this->assertTrue(get_resource_type($resource) == 'gd',
- 'Image must be a GD resource');
- }
- public function testDrawWithExistantResourceReturnResource()
- {
- $this->_checkTTFRequirement();
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->_renderer->setBarcode($barcode);
- $imageResource = imagecreatetruecolor(500, 500);
- $this->_renderer->setResource($imageResource);
- $resource = $this->_renderer->draw();
- $this->assertTrue(gettype($resource) == 'resource', 'Image must be a resource');
- $this->assertTrue(get_resource_type($resource) == 'gd',
- 'Image must be a GD resource');
- $this->assertSame($resource, $imageResource);
- }
- public function testGoodUserHeight()
- {
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->assertEquals(62, $barcode->getHeight());
- $this->_renderer->setBarcode($barcode);
- $this->_renderer->setHeight(62);
- $this->assertTrue($this->_renderer->checkParams());
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testBadUserHeightLessThanBarcodeHeight()
- {
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->assertEquals(62, $barcode->getHeight());
- $this->_renderer->setBarcode($barcode);
- $this->_renderer->setHeight(61);
- $this->_renderer->checkParams();
- }
- public function testGoodUserWidth()
- {
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->assertEquals(211, $barcode->getWidth());
- $this->_renderer->setBarcode($barcode);
- $this->_renderer->setWidth(211);
- $this->assertTrue($this->_renderer->checkParams());
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testBadUserWidthLessThanBarcodeWidth()
- {
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->assertEquals(211, $barcode->getWidth());
- $this->_renderer->setBarcode($barcode);
- $this->_renderer->setWidth(210);
- $this->_renderer->checkParams();
- }
- public function testGoodHeightOfUserResource()
- {
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->assertEquals(62, $barcode->getHeight());
- $imageResource = imagecreatetruecolor(500, 62);
- $this->_renderer->setResource($imageResource);
- $this->_renderer->setBarcode($barcode);
- $this->assertTrue($this->_renderer->checkParams());
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testBadHeightOfUserResource()
- {
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->assertEquals(62, $barcode->getHeight());
- $this->_renderer->setBarcode($barcode);
- $imageResource = imagecreatetruecolor(500, 61);
- $this->_renderer->setResource($imageResource);
- $this->_renderer->checkParams();
- }
- public function testGoodWidthOfUserResource()
- {
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->assertEquals(211, $barcode->getWidth());
- $imageResource = imagecreatetruecolor(211, 500);
- $this->_renderer->setResource($imageResource);
- $this->_renderer->setBarcode($barcode);
- $this->assertTrue($this->_renderer->checkParams());
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testBadWidthOfUserResource()
- {
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $this->assertEquals(211, $barcode->getWidth());
- $this->_renderer->setBarcode($barcode);
- $imageResource = imagecreatetruecolor(210, 500);
- $this->_renderer->setResource($imageResource);
- $this->_renderer->checkParams();
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testNoFontWithOrientation()
- {
- Zend_Barcode::setBarcodeFont('');
- $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
- $barcode->setOrientation(1);
- $this->_renderer->setBarcode($barcode);
- $this->_renderer->draw();
- }
- protected function _getRendererWithWidth500AndHeight300()
- {
- return $this->_renderer->setHeight(300)->setWidth(500);
- }
- /**
- * @expectedException Zend_Barcode_Renderer_Exception
- */
- public function testRendererWithUnknownInstructionProvideByObject()
- {
- parent::testRendererWithUnknownInstructionProvideByObject();
- }
- public function testHorizontalPositionToLeft()
- {
- $this->_checkTTFRequirement();
- parent::testHorizontalPositionToLeft();
- }
- public function testHorizontalPositionToCenter()
- {
- $this->_checkTTFRequirement();
- parent::testHorizontalPositionToCenter();
- }
- public function testHorizontalPositionToRight()
- {
- $this->_checkTTFRequirement();
- parent::testHorizontalPositionToRight();
- }
- public function testVerticalPositionToTop()
- {
- $this->_checkTTFRequirement();
- parent::testVerticalPositionToTop();
- }
- public function testVerticalPositionToMiddle()
- {
- $this->_checkTTFRequirement();
- parent::testVerticalPositionToMiddle();
- }
- public function testVerticalPositionToBottom()
- {
- $this->_checkTTFRequirement();
- parent::testVerticalPositionToBottom();
- }
- public function testLeftOffsetOverrideHorizontalPosition()
- {
- $this->_checkTTFRequirement();
- parent::testLeftOffsetOverrideHorizontalPosition();
- }
- public function testTopOffsetOverrideVerticalPosition()
- {
- $this->_checkTTFRequirement();
- parent::testTopOffsetOverrideVerticalPosition();
- }
- protected function _checkTTFRequirement()
- {
- if (!function_exists('imagettfbbox')) {
- $this->markTestSkipped('TTF (FreeType) support is required in order to run this test');
- }
- }
- }
|