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