Code128Test.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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-2012 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(__FILE__) . '/TestCommon.php';
  23. require_once 'Zend/Barcode/Object/Code128.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Barcode
  27. * @subpackage UnitTests
  28. * @group Zend_Barcode
  29. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Barcode_Object_Code128Test extends Zend_Barcode_Object_TestCommon
  33. {
  34. protected function _getBarcodeObject($options = null)
  35. {
  36. return new Zend_Barcode_Object_Code128($options);
  37. }
  38. public function testType()
  39. {
  40. $this->assertSame('code128', $this->_object->getType());
  41. }
  42. public function testChecksum()
  43. {
  44. $this->assertSame(33, $this->_object->getChecksum('BarCode 1'));
  45. $this->assertSame(47, $this->_object->getChecksum('CODE-128'));
  46. $this->assertSame(32, $this->_object->getChecksum('FRAMEWORK-ZEND-COM'));
  47. }
  48. public function testKnownBarcodeConversion()
  49. {
  50. require_once dirname(__FILE__) . '/_files/Code128Test.php';
  51. $barcode = new Code128Test();
  52. $this->assertSame(array(104, 13, 17, 18, 19), $barcode->_convertToBarcodeChars(-123));
  53. $this->assertSame(array(104, 40, 41, 99, 34, 56, 78), $barcode->_convertToBarcodeChars('HI345678'));
  54. }
  55. public function testSetText()
  56. {
  57. $this->_object->setText('0123456789');
  58. $this->assertSame('0123456789', $this->_object->getRawText());
  59. $this->assertSame('0123456789', $this->_object->getText());
  60. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  61. }
  62. public function testSetTextWithSpaces()
  63. {
  64. $this->_object->setText(' 0123456789 ');
  65. $this->assertSame(' 0123456789 ', $this->_object->getRawText());
  66. $this->assertSame(' 0123456789 ', $this->_object->getText());
  67. $this->assertSame(' 0123456789 ', $this->_object->getTextToDisplay());
  68. }
  69. public function testSetTextWithChecksum()
  70. {
  71. $this->_object->setText('0123456789');
  72. $this->_object->setWithChecksum(true);
  73. $this->assertSame('0123456789', $this->_object->getRawText());
  74. $this->assertSame('0123456789', $this->_object->getText());
  75. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  76. }
  77. public function testSetTextWithChecksumDisplayed()
  78. {
  79. $this->_object->setText('0123456789');
  80. $this->_object->setWithChecksum(true);
  81. $this->_object->setWithChecksumInText(true);
  82. $this->assertSame('0123456789', $this->_object->getRawText());
  83. $this->assertSame('0123456789', $this->_object->getText());
  84. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  85. }
  86. public function testGetKnownWidthWithoutOrientation()
  87. {
  88. $this->_object->setText('CODE-128');
  89. $this->assertEquals(143, $this->_object->getWidth());
  90. $this->_object->setWithQuietZones(false);
  91. $this->assertEquals(123, $this->_object->getWidth(true));
  92. }
  93. public function testCompleteGeneration()
  94. {
  95. $this->_object->setText('HI345678');
  96. $this->_object->draw();
  97. $instructions = $this->loadInstructionsFile('Code128_HI345678_instructions');
  98. $this->assertEquals($instructions, $this->_object->getInstructions());
  99. }
  100. public function testCompleteGenerationWithStretchText()
  101. {
  102. $this->_object->setText('HI345678');
  103. $this->_object->setStretchText(true);
  104. $this->_object->draw();
  105. $instructions = $this->loadInstructionsFile(
  106. 'Code128_HI345678_stretchtext_instructions');
  107. $this->assertEquals($instructions, $this->_object->getInstructions());
  108. }
  109. public function testCompleteGenerationWithBorder()
  110. {
  111. $this->_object->setText('HI345678');
  112. $this->_object->setWithBorder(true);
  113. $this->_object->draw();
  114. $instructions = $this->loadInstructionsFile(
  115. 'Code128_HI345678_border_instructions');
  116. $this->assertEquals($instructions, $this->_object->getInstructions());
  117. }
  118. public function testCompleteGenerationWithOrientation()
  119. {
  120. $this->_object->setText('HI345678');
  121. $this->_object->setOrientation(60);
  122. $this->_object->draw();
  123. $instructions = $this->loadInstructionsFile(
  124. 'Code128_HI345678_oriented_instructions');
  125. $this->assertEquals($instructions, $this->_object->getInstructions());
  126. }
  127. public function testCompleteGenerationWithStretchTextWithOrientation()
  128. {
  129. $this->_object->setText('HI345678');
  130. $this->_object->setOrientation(60);
  131. $this->_object->setStretchText(true);
  132. $this->_object->draw();
  133. $instructions = $this->loadInstructionsFile(
  134. 'Code128_HI345678_stretchtext_oriented_instructions');
  135. $this->assertEquals($instructions, $this->_object->getInstructions());
  136. }
  137. public function testCompleteGenerationWithBorderWithOrientation()
  138. {
  139. $this->_object->setText('HI345678');
  140. $this->_object->setOrientation(60);
  141. $this->_object->setWithBorder(true);
  142. $this->_object->draw();
  143. $instructions = $this->loadInstructionsFile(
  144. 'Code128_HI345678_border_oriented_instructions');
  145. $this->assertEquals($instructions, $this->_object->getInstructions());
  146. }
  147. }