Code39Test.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once dirname(__FILE__) . '/TestCommon.php';
  23. require_once 'Zend/Barcode/Object/Code39.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Barcode
  27. * @subpackage UnitTests
  28. * @group Zend_Barcode
  29. * @copyright Copyright (c) 2005-2015 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_Code39Test extends Zend_Barcode_Object_TestCommon
  33. {
  34. protected function _getBarcodeObject($options = null)
  35. {
  36. return new Zend_Barcode_Object_Code39($options);
  37. }
  38. public function testType()
  39. {
  40. $this->assertSame('code39', $this->_object->getType());
  41. }
  42. public function testChecksum()
  43. {
  44. $this->assertSame(2, $this->_object->getChecksum('0123456789'));
  45. $this->assertSame('W', $this->_object->getChecksum('CODE39'));
  46. $this->assertSame('J', $this->_object->getChecksum('FRAMEWORK-ZEND-COM'));
  47. }
  48. public function testSetText()
  49. {
  50. $this->_object->setText('0123456789');
  51. $this->assertSame('0123456789', $this->_object->getRawText());
  52. $this->assertSame('*0123456789*', $this->_object->getText());
  53. $this->assertSame('*0123456789*', $this->_object->getTextToDisplay());
  54. }
  55. public function testSetTextWithSpaces()
  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 testSetTextWithChecksum()
  63. {
  64. $this->_object->setText('0123456789');
  65. $this->_object->setWithChecksum(true);
  66. $this->assertSame('0123456789', $this->_object->getRawText());
  67. $this->assertSame('*01234567892*', $this->_object->getText());
  68. $this->assertSame('*0123456789*', $this->_object->getTextToDisplay());
  69. }
  70. public function testSetTextWithChecksumDisplayed()
  71. {
  72. $this->_object->setText('0123456789');
  73. $this->_object->setWithChecksum(true);
  74. $this->_object->setWithChecksumInText(true);
  75. $this->assertSame('0123456789', $this->_object->getRawText());
  76. $this->assertSame('*01234567892*', $this->_object->getText());
  77. $this->assertSame('*01234567892*', $this->_object->getTextToDisplay());
  78. }
  79. public function testBadTextAlwaysAllowed()
  80. {
  81. $this->_object->setText('&');
  82. $this->assertSame('&', $this->_object->getRawText());
  83. }
  84. /**
  85. * @expectedException Zend_Barcode_Object_Exception
  86. */
  87. public function testBadTextDetectedIfChecksumWished()
  88. {
  89. $this->_object->setText('&');
  90. $this->_object->setWithChecksum(true);
  91. $this->_object->getText();
  92. }
  93. public function testCheckGoodParams()
  94. {
  95. $this->_object->setText('0123456789');
  96. $this->assertTrue($this->_object->checkParams());
  97. }
  98. /**
  99. * @expectedException Zend_Barcode_Object_Exception
  100. */
  101. public function testCheckParamsWithLowRatio()
  102. {
  103. $this->_object->setText('TEST');
  104. $this->_object->setBarThinWidth(21);
  105. $this->_object->setBarThickWidth(40);
  106. $this->_object->checkParams();
  107. }
  108. /**
  109. * @expectedException Zend_Barcode_Object_Exception
  110. */
  111. public function testCheckParamsWithHighRatio()
  112. {
  113. $this->_object->setText('TEST');
  114. $this->_object->setBarThinWidth(20);
  115. $this->_object->setBarThickWidth(61);
  116. $this->_object->checkParams();
  117. }
  118. public function testGetKnownWidthWithoutOrientation()
  119. {
  120. $this->_object->setText('0123456789');
  121. $this->assertEquals(211, $this->_object->getWidth());
  122. $this->_object->setWithQuietZones(false);
  123. $this->assertEquals(191, $this->_object->getWidth(true));
  124. }
  125. public function testCompleteGeneration()
  126. {
  127. $this->_object->setText('0123456789');
  128. $this->_object->draw();
  129. $instructions = $this->loadInstructionsFile('Code39_0123456789_instructions');
  130. $this->assertEquals($instructions, $this->_object->getInstructions());
  131. }
  132. public function testCompleteGenerationWithStretchText()
  133. {
  134. $this->_object->setText('0123456789');
  135. $this->_object->setStretchText(true);
  136. $this->_object->draw();
  137. $instructions = $this->loadInstructionsFile(
  138. 'Code39_0123456789_stretchtext_instructions');
  139. $this->assertEquals($instructions, $this->_object->getInstructions());
  140. }
  141. public function testCompleteGenerationWithBorder()
  142. {
  143. $this->_object->setText('0123456789');
  144. $this->_object->setWithBorder(true);
  145. $this->_object->draw();
  146. $instructions = $this->loadInstructionsFile(
  147. 'Code39_0123456789_border_instructions');
  148. $this->assertEquals($instructions, $this->_object->getInstructions());
  149. }
  150. public function testCompleteGenerationWithOrientation()
  151. {
  152. $this->_object->setText('0123456789');
  153. $this->_object->setOrientation(60);
  154. $this->_object->draw();
  155. $instructions = $this->loadInstructionsFile(
  156. 'Code39_0123456789_oriented_instructions');
  157. $this->assertEquals($instructions, $this->_object->getInstructions());
  158. }
  159. public function testCompleteGenerationWithStretchTextWithOrientation()
  160. {
  161. $this->_object->setText('0123456789');
  162. $this->_object->setOrientation(60);
  163. $this->_object->setStretchText(true);
  164. $this->_object->draw();
  165. $instructions = $this->loadInstructionsFile(
  166. 'Code39_0123456789_stretchtext_oriented_instructions');
  167. $this->assertEquals($instructions, $this->_object->getInstructions());
  168. }
  169. public function testCompleteGenerationWithBorderWithOrientation()
  170. {
  171. $this->_object->setText('0123456789');
  172. $this->_object->setOrientation(60);
  173. $this->_object->setWithBorder(true);
  174. $this->_object->draw();
  175. $instructions = $this->loadInstructionsFile(
  176. 'Code39_0123456789_border_oriented_instructions');
  177. $this->assertEquals($instructions, $this->_object->getInstructions());
  178. }
  179. }