| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?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-2012 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/Object/Code39.php';
- /**
- * @category Zend
- * @package Zend_Barcode
- * @subpackage UnitTests
- * @group Zend_Barcode
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Barcode_Object_Code39Test extends Zend_Barcode_Object_TestCommon
- {
- protected function _getBarcodeObject($options = null)
- {
- return new Zend_Barcode_Object_Code39($options);
- }
- public function testType()
- {
- $this->assertSame('code39', $this->_object->getType());
- }
- public function testChecksum()
- {
- $this->assertSame(2, $this->_object->getChecksum('0123456789'));
- $this->assertSame('W', $this->_object->getChecksum('CODE39'));
- $this->assertSame('J', $this->_object->getChecksum('FRAMEWORK-ZEND-COM'));
- }
- public function testSetText()
- {
- $this->_object->setText('0123456789');
- $this->assertSame('0123456789', $this->_object->getRawText());
- $this->assertSame('*0123456789*', $this->_object->getText());
- $this->assertSame('*0123456789*', $this->_object->getTextToDisplay());
- }
- public function testSetTextWithSpaces()
- {
- $this->_object->setText(' 0123456789 ');
- $this->assertSame(' 0123456789 ', $this->_object->getRawText());
- $this->assertSame('* 0123456789 *', $this->_object->getText());
- $this->assertSame('* 0123456789 *', $this->_object->getTextToDisplay());
- }
- public function testSetTextWithChecksum()
- {
- $this->_object->setText('0123456789');
- $this->_object->setWithChecksum(true);
- $this->assertSame('0123456789', $this->_object->getRawText());
- $this->assertSame('*01234567892*', $this->_object->getText());
- $this->assertSame('*0123456789*', $this->_object->getTextToDisplay());
- }
- public function testSetTextWithChecksumDisplayed()
- {
- $this->_object->setText('0123456789');
- $this->_object->setWithChecksum(true);
- $this->_object->setWithChecksumInText(true);
- $this->assertSame('0123456789', $this->_object->getRawText());
- $this->assertSame('*01234567892*', $this->_object->getText());
- $this->assertSame('*01234567892*', $this->_object->getTextToDisplay());
- }
- public function testBadTextAlwaysAllowed()
- {
- $this->_object->setText('&');
- $this->assertSame('&', $this->_object->getRawText());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testBadTextDetectedIfChecksumWished()
- {
- $this->_object->setText('&');
- $this->_object->setWithChecksum(true);
- $this->_object->getText();
- }
- public function testCheckGoodParams()
- {
- $this->_object->setText('0123456789');
- $this->assertTrue($this->_object->checkParams());
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testCheckParamsWithLowRatio()
- {
- $this->_object->setText('TEST');
- $this->_object->setBarThinWidth(21);
- $this->_object->setBarThickWidth(40);
- $this->_object->checkParams();
- }
- /**
- * @expectedException Zend_Barcode_Object_Exception
- */
- public function testCheckParamsWithHighRatio()
- {
- $this->_object->setText('TEST');
- $this->_object->setBarThinWidth(20);
- $this->_object->setBarThickWidth(61);
- $this->_object->checkParams();
- }
- public function testGetKnownWidthWithoutOrientation()
- {
- $this->_object->setText('0123456789');
- $this->assertEquals(211, $this->_object->getWidth());
- $this->_object->setWithQuietZones(false);
- $this->assertEquals(191, $this->_object->getWidth(true));
- }
- public function testCompleteGeneration()
- {
- $this->_object->setText('0123456789');
- $this->_object->draw();
- $instructions = $this->loadInstructionsFile('Code39_0123456789_instructions');
- $this->assertEquals($instructions, $this->_object->getInstructions());
- }
- public function testCompleteGenerationWithStretchText()
- {
- $this->_object->setText('0123456789');
- $this->_object->setStretchText(true);
- $this->_object->draw();
- $instructions = $this->loadInstructionsFile(
- 'Code39_0123456789_stretchtext_instructions');
- $this->assertEquals($instructions, $this->_object->getInstructions());
- }
- public function testCompleteGenerationWithBorder()
- {
- $this->_object->setText('0123456789');
- $this->_object->setWithBorder(true);
- $this->_object->draw();
- $instructions = $this->loadInstructionsFile(
- 'Code39_0123456789_border_instructions');
- $this->assertEquals($instructions, $this->_object->getInstructions());
- }
- public function testCompleteGenerationWithOrientation()
- {
- $this->_object->setText('0123456789');
- $this->_object->setOrientation(60);
- $this->_object->draw();
- $instructions = $this->loadInstructionsFile(
- 'Code39_0123456789_oriented_instructions');
- $this->assertEquals($instructions, $this->_object->getInstructions());
- }
- public function testCompleteGenerationWithStretchTextWithOrientation()
- {
- $this->_object->setText('0123456789');
- $this->_object->setOrientation(60);
- $this->_object->setStretchText(true);
- $this->_object->draw();
- $instructions = $this->loadInstructionsFile(
- 'Code39_0123456789_stretchtext_oriented_instructions');
- $this->assertEquals($instructions, $this->_object->getInstructions());
- }
- public function testCompleteGenerationWithBorderWithOrientation()
- {
- $this->_object->setText('0123456789');
- $this->_object->setOrientation(60);
- $this->_object->setWithBorder(true);
- $this->_object->draw();
- $instructions = $this->loadInstructionsFile(
- 'Code39_0123456789_border_oriented_instructions');
- $this->assertEquals($instructions, $this->_object->getInstructions());
- }
- }
|