Code128Test.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Barcode
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Code25Test.php 21667 2010-03-28 17:45:14Z mikaelkael $
  21. */
  22. require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  23. require_once dirname(__FILE__) . '/TestCommon.php';
  24. require_once 'Zend/Barcode/Object/Code128.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Barcode
  28. * @subpackage UnitTests
  29. * @group Zend_Barcode
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Barcode_Object_Code128Test extends Zend_Barcode_Object_TestCommon
  34. {
  35. protected function _getBarcodeObject($options = null)
  36. {
  37. return new Zend_Barcode_Object_Code128($options);
  38. }
  39. public function testType()
  40. {
  41. $this->assertSame('code128', $this->_object->getType());
  42. }
  43. public function testChecksum()
  44. {
  45. $this->assertSame(33, $this->_object->getChecksum('BarCode 1'));
  46. $this->assertSame(47, $this->_object->getChecksum('CODE-128'));
  47. $this->assertSame(32, $this->_object->getChecksum('FRAMEWORK-ZEND-COM'));
  48. }
  49. public function testKnownBarcodeConversion()
  50. {
  51. require_once dirname(__FILE__) . '/_files/Code128Test.php';
  52. $barcode = new Code128Test();
  53. $this->assertSame(array(104, 13, 17, 18, 19), $barcode->_convertToBarcodeChars(-123));
  54. $this->assertSame(array(104, 40, 41, 99, 34, 56, 78), $barcode->_convertToBarcodeChars('HI345678'));
  55. }
  56. public function testSetText()
  57. {
  58. $this->_object->setText('0123456789');
  59. $this->assertSame('0123456789', $this->_object->getRawText());
  60. $this->assertSame('0123456789', $this->_object->getText());
  61. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  62. }
  63. public function testSetTextWithSpaces()
  64. {
  65. $this->_object->setText(' 0123456789 ');
  66. $this->assertSame(' 0123456789 ', $this->_object->getRawText());
  67. $this->assertSame(' 0123456789 ', $this->_object->getText());
  68. $this->assertSame(' 0123456789 ', $this->_object->getTextToDisplay());
  69. }
  70. public function testSetTextWithChecksum()
  71. {
  72. $this->_object->setText('0123456789');
  73. $this->_object->setWithChecksum(true);
  74. $this->assertSame('0123456789', $this->_object->getRawText());
  75. $this->assertSame('0123456789', $this->_object->getText());
  76. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  77. }
  78. public function testSetTextWithChecksumDisplayed()
  79. {
  80. $this->_object->setText('0123456789');
  81. $this->_object->setWithChecksum(true);
  82. $this->_object->setWithChecksumInText(true);
  83. $this->assertSame('0123456789', $this->_object->getRawText());
  84. $this->assertSame('0123456789', $this->_object->getText());
  85. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  86. }
  87. public function testGetKnownWidthWithoutOrientation()
  88. {
  89. $this->_object->setText('CODE-128');
  90. $this->assertEquals(143, $this->_object->getWidth());
  91. $this->_object->setWithQuietZones(false);
  92. $this->assertEquals(123, $this->_object->getWidth(true));
  93. }
  94. public function testCompleteGeneration()
  95. {
  96. $this->_object->setText('HI345678');
  97. $this->_object->draw();
  98. $instructions = $this->loadInstructionsFile('Code128_HI345678_instructions');
  99. $this->assertEquals($instructions, $this->_object->getInstructions());
  100. }
  101. public function testCompleteGenerationWithStretchText()
  102. {
  103. $this->_object->setText('HI345678');
  104. $this->_object->setStretchText(true);
  105. $this->_object->draw();
  106. $instructions = $this->loadInstructionsFile(
  107. 'Code128_HI345678_stretchtext_instructions');
  108. $this->assertEquals($instructions, $this->_object->getInstructions());
  109. }
  110. public function testCompleteGenerationWithBorder()
  111. {
  112. $this->_object->setText('HI345678');
  113. $this->_object->setWithBorder(true);
  114. $this->_object->draw();
  115. $instructions = $this->loadInstructionsFile(
  116. 'Code128_HI345678_border_instructions');
  117. $this->assertEquals($instructions, $this->_object->getInstructions());
  118. }
  119. public function testCompleteGenerationWithOrientation()
  120. {
  121. $this->_object->setText('HI345678');
  122. $this->_object->setOrientation(60);
  123. $this->_object->draw();
  124. $instructions = $this->loadInstructionsFile(
  125. 'Code128_HI345678_oriented_instructions');
  126. $this->assertEquals($instructions, $this->_object->getInstructions());
  127. }
  128. public function testCompleteGenerationWithStretchTextWithOrientation()
  129. {
  130. $this->_object->setText('HI345678');
  131. $this->_object->setOrientation(60);
  132. $this->_object->setStretchText(true);
  133. $this->_object->draw();
  134. $instructions = $this->loadInstructionsFile(
  135. 'Code128_HI345678_stretchtext_oriented_instructions');
  136. $this->assertEquals($instructions, $this->_object->getInstructions());
  137. }
  138. public function testCompleteGenerationWithBorderWithOrientation()
  139. {
  140. $this->_object->setText('HI345678');
  141. $this->_object->setOrientation(60);
  142. $this->_object->setWithBorder(true);
  143. $this->_object->draw();
  144. $instructions = $this->loadInstructionsFile(
  145. 'Code128_HI345678_border_oriented_instructions');
  146. $this->assertEquals($instructions, $this->_object->getInstructions());
  147. }
  148. }