Code39Test.php 6.8 KB

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