Int25Test.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/Int25.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_Int25Test extends Zend_Barcode_Object_TestCommon
  36. {
  37. protected function _getBarcodeObject($options = null)
  38. {
  39. return new Zend_Barcode_Object_Int25($options);
  40. }
  41. public function testType()
  42. {
  43. $this->assertSame('int25', $this->_object->getType());
  44. }
  45. public function testWithBearerBars()
  46. {
  47. $this->_object->setWithBearerBars(1);
  48. $this->assertSame(true, $this->_object->getWithBearerBars());
  49. $this->_object->setWithBearerBars(true);
  50. $this->assertSame(true, $this->_object->getWithBearerBars());
  51. }
  52. public function testChecksum()
  53. {
  54. $this->assertSame(5, $this->_object->getChecksum('0123456789'));
  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 testSetTextWithoutEvenNumberOfCharacters()
  71. {
  72. $this->_object->setText('123456789');
  73. $this->assertSame('123456789', $this->_object->getRawText());
  74. $this->assertSame('0123456789', $this->_object->getText());
  75. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  76. }
  77. public function testSetTextWithChecksum()
  78. {
  79. $this->_object->setText('123456789');
  80. $this->_object->setWithChecksum(true);
  81. $this->assertSame('123456789', $this->_object->getRawText());
  82. $this->assertSame('1234567895', $this->_object->getText());
  83. $this->assertSame('123456789', $this->_object->getTextToDisplay());
  84. }
  85. public function testSetTextWithoutEvenNumberOfCharactersWithChecksum()
  86. {
  87. $this->_object->setText('123456789');
  88. $this->_object->setWithChecksum(true);
  89. $this->assertSame('123456789', $this->_object->getRawText());
  90. $this->assertSame('1234567895', $this->_object->getText());
  91. $this->assertSame('123456789', $this->_object->getTextToDisplay());
  92. }
  93. public function testSetTextWithChecksumDisplayed()
  94. {
  95. $this->_object->setText('123456789');
  96. $this->_object->setWithChecksum(true);
  97. $this->_object->setWithChecksumInText(true);
  98. $this->assertSame('123456789', $this->_object->getRawText());
  99. $this->assertSame('1234567895', $this->_object->getText());
  100. $this->assertSame('1234567895', $this->_object->getTextToDisplay());
  101. }
  102. public function testSetTextWithoutEvenNumberOfCharactersWithChecksumDisplayed()
  103. {
  104. $this->_object->setText('0123456789');
  105. $this->_object->setWithChecksum(true);
  106. $this->_object->setWithChecksumInText(true);
  107. $this->assertSame('0123456789', $this->_object->getRawText());
  108. $this->assertSame('001234567895', $this->_object->getText());
  109. $this->assertSame('001234567895', $this->_object->getTextToDisplay());
  110. }
  111. public function testBadTextAlwaysAllowed()
  112. {
  113. $this->_object->setText('a');
  114. $this->assertSame('0a', $this->_object->getText());
  115. }
  116. /**
  117. * @expectedException Zend_Barcode_Object_Exception
  118. */
  119. public function testBadTextDetectedIfChecksumWished()
  120. {
  121. $this->_object->setText('a');
  122. $this->_object->setWithChecksum(true);
  123. $this->_object->getText();
  124. }
  125. public function testCheckGoodParams()
  126. {
  127. $this->_object->setText('0123456789');
  128. $this->assertTrue($this->_object->checkParams());
  129. }
  130. /**
  131. * @expectedException Zend_Barcode_Object_Exception
  132. */
  133. public function testCheckParamsWithLowRatio()
  134. {
  135. $this->_object->setText('0123456789');
  136. $this->_object->setBarThinWidth(21);
  137. $this->_object->setBarThickWidth(40);
  138. $this->_object->checkParams();
  139. }
  140. /**
  141. * @expectedException Zend_Barcode_Object_Exception
  142. */
  143. public function testCheckParamsWithHighRatio()
  144. {
  145. $this->_object->setText('0123456789');
  146. $this->_object->setBarThinWidth(20);
  147. $this->_object->setBarThickWidth(61);
  148. $this->_object->checkParams();
  149. }
  150. public function testGetKnownWidthWithoutOrientation()
  151. {
  152. $this->_object->setText('0123456789');
  153. $this->assertEquals(119, $this->_object->getWidth());
  154. }
  155. public function testCompleteGeneration()
  156. {
  157. $this->_object->setText('0123456789');
  158. $this->_object->draw();
  159. $instructions = $this->loadInstructionsFile('Int25_0123456789_instructions');
  160. $this->assertEquals($instructions, $this->_object->getInstructions());
  161. }
  162. public function testCompleteGenerationWithStretchText()
  163. {
  164. $this->_object->setText('0123456789');
  165. $this->_object->setStretchText(true);
  166. $this->_object->draw();
  167. $instructions = $this->loadInstructionsFile(
  168. 'Int25_0123456789_stretchtext_instructions');
  169. $this->assertEquals($instructions, $this->_object->getInstructions());
  170. }
  171. public function testCompleteGenerationWithBorder()
  172. {
  173. $this->_object->setText('0123456789');
  174. $this->_object->setWithBorder(true);
  175. $this->_object->draw();
  176. $instructions = $this->loadInstructionsFile(
  177. 'Int25_0123456789_border_instructions');
  178. $this->assertEquals($instructions, $this->_object->getInstructions());
  179. }
  180. public function testCompleteGenerationWithBearerBars()
  181. {
  182. $this->_object->setText('0123456789');
  183. $this->_object->setWithBearerBars(true);
  184. $this->_object->draw();
  185. $instructions = $this->loadInstructionsFile(
  186. 'Int25_0123456789_bearerbar_instructions');
  187. $this->assertEquals($instructions, $this->_object->getInstructions());
  188. }
  189. public function testCompleteGenerationWithOrientation()
  190. {
  191. $this->_object->setText('0123456789');
  192. $this->_object->setOrientation(60);
  193. $this->_object->draw();
  194. $instructions = $this->loadInstructionsFile(
  195. 'Int25_0123456789_oriented_instructions');
  196. $this->assertEquals($instructions, $this->_object->getInstructions());
  197. }
  198. public function testCompleteGenerationWithStretchTextWithOrientation()
  199. {
  200. $this->_object->setText('0123456789');
  201. $this->_object->setOrientation(60);
  202. $this->_object->setStretchText(true);
  203. $this->_object->draw();
  204. $instructions = $this->loadInstructionsFile(
  205. 'Int25_0123456789_stretchtext_oriented_instructions');
  206. $this->assertEquals($instructions, $this->_object->getInstructions());
  207. }
  208. public function testCompleteGenerationWithBorderWithOrientation()
  209. {
  210. $this->_object->setText('0123456789');
  211. $this->_object->setOrientation(60);
  212. $this->_object->setWithBorder(true);
  213. $this->_object->draw();
  214. $instructions = $this->loadInstructionsFile(
  215. 'Int25_0123456789_border_oriented_instructions');
  216. $this->assertEquals($instructions, $this->_object->getInstructions());
  217. }
  218. public function testCompleteGenerationWithBearerBarsWithOrientation()
  219. {
  220. $this->_object->setText('0123456789');
  221. $this->_object->setOrientation(60);
  222. $this->_object->setWithBearerBars(true);
  223. $this->_object->draw();
  224. $instructions = $this->loadInstructionsFile(
  225. 'Int25_0123456789_bearerbar_oriented_instructions');
  226. $this->assertEquals($instructions, $this->_object->getInstructions());
  227. }
  228. }