| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- <?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-2014 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__) . '/_files/BarcodeTest.php';
- /**
- * @see Zend_Config
- */
- require_once 'Zend/Config.php';
- /**
- * @category Zend
- * @package Zend_Barcode
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- abstract class Zend_Barcode_Object_TestCommon extends PHPUnit_Framework_TestCase
- {
- /**
- * @var Zend_Barcode_Object
- */
- protected $_object = null;
- abstract protected function _getBarcodeObject($options = null);
- protected function loadInstructionsFile($fileName)
- {
- return include_once (dirname(__FILE__) . "/_files/$fileName.php");
- }
- public function setUp()
- {
- $this->_object = $this->_getBarcodeObject();
- }
- public function tearDown()
- {
- $this->_object = null;
- }
- public function testStaticFontAsString()
- {
- Zend_Barcode_Object_ObjectAbstract::setBarcodeFont('my_static_font.ttf');
- $this->assertEquals('', $this->_object->getFont());
- $object = $this->_getBarcodeObject();
- $this->assertEquals('my_static_font.ttf', $object->getFont());
- Zend_Barcode_Object_ObjectAbstract::setBarcodeFont('');
- }
- public function testStaticFontAsNumber()
- {
- for ($i = 1; $i < 5; $i++) {
- Zend_Barcode_Object_ObjectAbstract::setBarcodeFont($i);
- $this->assertEquals('', $this->_object->getFont());
- $object = $this->_getBarcodeObject();
- $this->assertEquals($i, $object->getFont());
- Zend_Barcode_Object_ObjectAbstract::setBarcodeFont('');
- }
- }
- public function testConstructorWithArray()
- {
- $object = $this->_getBarcodeObject(
- array('barHeight' => 150 ,
- 'unknownProperty' => 'aValue'));
- $this->assertEquals(150, $object->getBarHeight());
- }
- public function testConstructorWithZendConfig()
- {
- $config = new Zend_Config(
- array('barHeight' => 150 ,
- 'unknownProperty' => 'aValue'));
- $object = $this->_getBarcodeObject($config);
- $this->assertEquals(150, $object->getBarHeight());
- }
- public function testSetOptions()
- {
- $this->_object->setOptions(
- array('barHeight' => 150 ,
- 'unknownProperty' => 'aValue'));
- $this->assertEquals(150, $this->_object->getBarHeight());
- }
- public function testSetConfig()
- {
- $config = new Zend_Config(
- array('barHeight' => 150 ,
- 'unknownProperty' => 'aValue'));
- $this->_object->setConfig($config);
- $this->assertEquals(150, $this->_object->getBarHeight());
- }
- public function testBarcodeNamespace()
- {
- $this->_object->setBarcodeNamespace('My_Namespace');
- $this->assertEquals('My_Namespace', $this->_object->getBarcodeNamespace());
- }
- public function testBarHeight()
- {
- $this->_object->setBarHeight(1);
- $this->assertSame(1, $this->_object->getBarHeight());
- $this->_object->setBarHeight(true);
- $this->assertSame(1, $this->_object->getBarHeight());
- $this->_object->setBarHeight('200a');
- $this->assertSame(200, $this->_object->getBarHeight());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testNegativeBarHeight()
- {
- $this->_object->setBarHeight(- 1);
- }
- public function testBarThinWidth()
- {
- $this->_object->setBarThinWidth(1);
- $this->assertSame(1, $this->_object->getBarThinWidth());
- $this->_object->setBarThinWidth(true);
- $this->assertSame(1, $this->_object->getBarThinWidth());
- $this->_object->setBarThinWidth('200a');
- $this->assertSame(200, $this->_object->getBarThinWidth());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testNegativeBarThinWidth()
- {
- $this->_object->setBarThinWidth(- 1);
- }
- public function testBarThickWidth()
- {
- $this->_object->setBarThickWidth(1);
- $this->assertSame(1, $this->_object->getBarThickWidth());
- $this->_object->setBarThickWidth(true);
- $this->assertSame(1, $this->_object->getBarThickWidth());
- $this->_object->setBarThickWidth('200a');
- $this->assertSame(200, $this->_object->getBarThickWidth());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testNegativeBarThickWidth()
- {
- $this->_object->setBarThickWidth(- 1);
- }
- public function testFactor()
- {
- $this->_object->setFactor(1);
- $this->assertSame(1.0, $this->_object->getFactor());
- $this->_object->setFactor(1.25);
- $this->assertSame(1.25, $this->_object->getFactor());
- $this->_object->setFactor(true);
- $this->assertSame(1.0, $this->_object->getFactor());
- $this->_object->setFactor('200a');
- $this->assertSame(200.0, $this->_object->getFactor());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testNegativeFactor()
- {
- $this->_object->setFactor(- 1);
- }
- public function testForeColor()
- {
- $this->_object->setForeColor('#333333');
- $this->assertSame(3355443, $this->_object->getForeColor());
- $this->_object->setForeColor(1000);
- $this->assertSame(1000, $this->_object->getForeColor());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testNegativeForeColor()
- {
- $this->_object->setForeColor(- 1);
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testTooHighForeColor()
- {
- $this->_object->setForeColor(16777126);
- }
- public function testBackgroundColor()
- {
- $this->_object->setBackgroundColor('#333333');
- $this->assertSame(3355443, $this->_object->getBackgroundColor());
- $this->_object->setBackgroundColor(1000);
- $this->assertSame(1000, $this->_object->getBackgroundColor());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testNegativeBackgroundColor()
- {
- $this->_object->setBackgroundColor(- 1);
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testTooHighBackgroundColor()
- {
- $this->_object->setBackgroundColor(16777126);
- }
- public function testWithBorder()
- {
- $this->_object->setWithBorder(1);
- $this->assertSame(true, $this->_object->getWithBorder());
- $this->_object->setWithBorder(true);
- $this->assertSame(true, $this->_object->getWithBorder());
- }
- public function testReverseColor()
- {
- $this->_object->setForeColor(11);
- $this->_object->setBackgroundColor(111);
- $this->_object->setReverseColor();
- $this->assertSame(111, $this->_object->getForeColor());
- $this->assertSame(11, $this->_object->getBackgroundColor());
- }
- public function testOrientation()
- {
- $this->_object->setOrientation(1);
- $this->assertSame(1.0, $this->_object->getOrientation());
- $this->_object->setOrientation(1.25);
- $this->assertSame(1.25, $this->_object->getOrientation());
- $this->_object->setOrientation(true);
- $this->assertSame(1.0, $this->_object->getOrientation());
- $this->_object->setOrientation('200a');
- $this->assertSame(200.0, $this->_object->getOrientation());
- $this->_object->setOrientation(360);
- $this->assertSame(0.0, $this->_object->getOrientation());
- }
- public function testDrawText()
- {
- $this->_object->setDrawText(1);
- $this->assertSame(true, $this->_object->getDrawText());
- $this->_object->setDrawText(true);
- $this->assertSame(true, $this->_object->getDrawText());
- }
- public function testStretchText()
- {
- $this->_object->setStretchText(1);
- $this->assertSame(true, $this->_object->getStretchText());
- $this->_object->setStretchText(true);
- $this->assertSame(true, $this->_object->getStretchText());
- }
- public function testWithChecksum()
- {
- $this->_object->setWithChecksum(1);
- $this->assertSame(true, $this->_object->getWithChecksum());
- $this->_object->setWithChecksum(true);
- $this->assertSame(true, $this->_object->getWithChecksum());
- }
- public function testWithChecksumInText()
- {
- $this->_object->setWithChecksumInText(1);
- $this->assertSame(true, $this->_object->getWithChecksumInText());
- $this->_object->setWithChecksumInText(true);
- $this->assertSame(true, $this->_object->getWithChecksumInText());
- }
- public function testWithoutQuietZones()
- {
- $this->_object->setWithQuietZones(0);
- $this->assertSame(false, $this->_object->getWithQuietZones());
- $this->_object->setWithQuietZones(false);
- $this->assertSame(false, $this->_object->getWithQuietZones());
- }
- public function testSetFontAsNumberForGdImage()
- {
- if (! extension_loaded('gd')) {
- $this->markTestSkipped(
- 'GD extension is required to run this test');
- }
- $gdFontSize = array(8 , 13 , 13 , 16 , 15);
- for ($i = 1; $i <= 5; $i ++) {
- $this->_object->setFont($i);
- $this->assertSame($i, $this->_object->getFont());
- $this->assertSame($gdFontSize[$i - 1],
- $this->_object->getFontSize());
- }
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testSetLowFontAsNumberForGdImage()
- {
- $this->_object->setFont(0);
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testSetHighFontAsNumberForGdImage()
- {
- $this->_object->setFont(6);
- }
- public function testSetFontAsString()
- {
- $this->_object->setFont('my_font.ttf');
- $this->assertSame('my_font.ttf', $this->_object->getFont());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testSetFontAsBoolean()
- {
- $this->_object->setFont(true);
- }
- public function testFontAsNumberWithoutGd()
- {
- if (extension_loaded('gd')) {
- $this->markTestSkipped(
- 'GD extension must not be loaded to run this test');
- }
- $this->setExpectedException('Zend_Barcode_Object_Exception');
- $this->_object->setFont(1);
- }
- public function testFontSize()
- {
- $this->_object->setFontSize(22);
- $this->assertSame(22, $this->_object->getFontSize());
- }
- public function testFontSizeWithoutEffectWithGdInternalFont()
- {
- if (! extension_loaded('gd')) {
- $this->markTestSkipped(
- 'GD extension is required to run this test');
- }
- $this->_object->setFont(1);
- $this->_object->setFontSize(22);
- $this->assertSame(8, $this->_object->getFontSize());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testStringFontSize()
- {
- $this->_object->setFontSize('22a');
- }
- public function testStandardQuietZone()
- {
- $this->_object->setBarThinWidth(3);
- $this->_object->setFactor(4);
- $this->assertSame(120.0, $this->_object->getQuietZone());
- }
- public function testAddInstruction()
- {
- $object = new Zend_Barcode_Object_Test();
- $instructions = array('type' => 'text' , 'text' => 'text' , 'size' => 10 ,
- 'position' => array(5 , 5) ,
- 'font' => 'my_font.ttf' ,
- 'color' => '#123456' ,
- 'alignment' => 'center' ,
- 'orientation' => 45);
- $object->addInstruction($instructions);
- $this->assertSame(array($instructions), $object->getInstructions());
- }
- public function testAddPolygon()
- {
- $object = new Zend_Barcode_Object_Test();
- $points = array();
- $color = '#123456';
- $filled = false;
- $instructions = array('type' => 'polygon' , 'points' => $points ,
- 'color' => $color , 'filled' => $filled);
- $object->addPolygon($points, $color, $filled);
- $this->assertSame(array($instructions), $object->getInstructions());
- }
- public function testAddPolygonWithDefaultColor()
- {
- $object = new Zend_Barcode_Object_Test();
- $points = array();
- $color = 123456;
- $object->setForeColor($color);
- $filled = false;
- $instructions = array('type' => 'polygon' , 'points' => $points ,
- 'color' => $color , 'filled' => $filled);
- $object->addPolygon($points, null, $filled);
- $this->assertSame(array($instructions), $object->getInstructions());
- }
- public function testAddText()
- {
- $object = new Zend_Barcode_Object_Test();
- $size = 10;
- $text = 'foobar';
- $position = array();
- $font = 'my_font.ttf';
- $color = '#123456';
- $alignment = 'right';
- $orientation = 45;
- $instructions = array('type' => 'text' , 'text' => $text , 'size' => $size ,
- 'position' => $position ,
- 'font' => $font , 'color' => $color ,
- 'alignment' => $alignment ,
- 'orientation' => $orientation);
- $object->addText($text, $size, $position, $font, $color, $alignment,
- $orientation);
- $this->assertSame(array($instructions), $object->getInstructions());
- }
- public function testAddTextWithDefaultColor()
- {
- $object = new Zend_Barcode_Object_Test();
- $size = 10;
- $text = 'foobar';
- $position = array();
- $font = 'my_font.ttf';
- $color = 123456;
- $object->setForeColor($color);
- $alignment = 'right';
- $orientation = 45;
- $instructions = array('type' => 'text' , 'text' => $text , 'size' => $size ,
- 'position' => $position ,
- 'font' => $font , 'color' => $color ,
- 'alignment' => $alignment ,
- 'orientation' => $orientation);
- $object->addText($text, $size, $position, $font, null, $alignment, $orientation);
- $this->assertSame(array($instructions), $object->getInstructions());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testCheckParamsFontWithOrientation()
- {
- $this->_object->setText('0');
- $this->_object->setFont(1);
- $this->_object->setOrientation(45);
- $this->_object->checkParams();
- }
- public function testGetDefaultHeight()
- {
- $this->assertEquals(62, $this->_object->getHeight());
- }
- }
|