Code25interleavedTest.php 9.1 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-2010 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/Code25interleaved.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Barcode
  28. * @subpackage UnitTests
  29. * @group Zend_Barcode
  30. * @copyright Copyright (c) 2005-2010 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_Code25interleavedTest extends Zend_Barcode_Object_TestCommon
  34. {
  35. protected function _getBarcodeObject($options = null)
  36. {
  37. return new Zend_Barcode_Object_Code25interleaved($options);
  38. }
  39. public function testType()
  40. {
  41. $this->assertSame('code25interleaved', $this->_object->getType());
  42. }
  43. public function testWithBearerBars()
  44. {
  45. $this->_object->setWithBearerBars(1);
  46. $this->assertSame(true, $this->_object->getWithBearerBars());
  47. $this->_object->setWithBearerBars(true);
  48. $this->assertSame(true, $this->_object->getWithBearerBars());
  49. }
  50. public function testChecksum()
  51. {
  52. $this->assertSame(5, $this->_object->getChecksum('0123456789'));
  53. }
  54. public function testSetText()
  55. {
  56. $this->_object->setText('0123456789');
  57. $this->assertSame('0123456789', $this->_object->getRawText());
  58. $this->assertSame('0123456789', $this->_object->getText());
  59. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  60. }
  61. public function testSetTextWithSpaces()
  62. {
  63. $this->_object->setText(' 0123456789 ');
  64. $this->assertSame('0123456789', $this->_object->getRawText());
  65. $this->assertSame('0123456789', $this->_object->getText());
  66. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  67. }
  68. public function testSetTextWithoutEvenNumberOfCharacters()
  69. {
  70. $this->_object->setText('123456789');
  71. $this->assertSame('123456789', $this->_object->getRawText());
  72. $this->assertSame('0123456789', $this->_object->getText());
  73. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  74. }
  75. public function testSetTextWithChecksum()
  76. {
  77. $this->_object->setText('123456789');
  78. $this->_object->setWithChecksum(true);
  79. $this->assertSame('123456789', $this->_object->getRawText());
  80. $this->assertSame('1234567895', $this->_object->getText());
  81. $this->assertSame('123456789', $this->_object->getTextToDisplay());
  82. }
  83. public function testSetTextWithoutEvenNumberOfCharactersWithChecksum()
  84. {
  85. $this->_object->setText('123456789');
  86. $this->_object->setWithChecksum(true);
  87. $this->assertSame('123456789', $this->_object->getRawText());
  88. $this->assertSame('1234567895', $this->_object->getText());
  89. $this->assertSame('123456789', $this->_object->getTextToDisplay());
  90. }
  91. public function testSetTextWithChecksumDisplayed()
  92. {
  93. $this->_object->setText('123456789');
  94. $this->_object->setWithChecksum(true);
  95. $this->_object->setWithChecksumInText(true);
  96. $this->assertSame('123456789', $this->_object->getRawText());
  97. $this->assertSame('1234567895', $this->_object->getText());
  98. $this->assertSame('1234567895', $this->_object->getTextToDisplay());
  99. }
  100. public function testSetTextWithoutEvenNumberOfCharactersWithChecksumDisplayed()
  101. {
  102. $this->_object->setText('0123456789');
  103. $this->_object->setWithChecksum(true);
  104. $this->_object->setWithChecksumInText(true);
  105. $this->assertSame('0123456789', $this->_object->getRawText());
  106. $this->assertSame('001234567895', $this->_object->getText());
  107. $this->assertSame('001234567895', $this->_object->getTextToDisplay());
  108. }
  109. public function testBadTextAlwaysAllowed()
  110. {
  111. $this->_object->setText('a');
  112. $this->assertSame('0a', $this->_object->getText());
  113. }
  114. /**
  115. * @expectedException Zend_Barcode_Object_Exception
  116. */
  117. public function testBadTextDetectedIfChecksumWished()
  118. {
  119. $this->_object->setText('a');
  120. $this->_object->setWithChecksum(true);
  121. $this->_object->getText();
  122. }
  123. public function testCheckGoodParams()
  124. {
  125. $this->_object->setText('0123456789');
  126. $this->assertTrue($this->_object->checkParams());
  127. }
  128. /**
  129. * @expectedException Zend_Barcode_Object_Exception
  130. */
  131. public function testCheckParamsWithLowRatio()
  132. {
  133. $this->_object->setText('0123456789');
  134. $this->_object->setBarThinWidth(21);
  135. $this->_object->setBarThickWidth(40);
  136. $this->_object->checkParams();
  137. }
  138. /**
  139. * @expectedException Zend_Barcode_Object_Exception
  140. */
  141. public function testCheckParamsWithHighRatio()
  142. {
  143. $this->_object->setText('0123456789');
  144. $this->_object->setBarThinWidth(20);
  145. $this->_object->setBarThickWidth(61);
  146. $this->_object->checkParams();
  147. }
  148. public function testGetKnownWidthWithoutOrientation()
  149. {
  150. $this->_object->setText('0123456789');
  151. $this->assertEquals(119, $this->_object->getWidth());
  152. $this->_object->setWithQuietZones(false);
  153. $this->assertEquals(99, $this->_object->getWidth(true));
  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. }