Int25Test.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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/Int25.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_Int25Test extends Zend_Barcode_Object_TestCommon
  34. {
  35. protected function _getBarcodeObject($options = null)
  36. {
  37. return new Zend_Barcode_Object_Int25($options);
  38. }
  39. public function testType()
  40. {
  41. $this->assertSame('int25', $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. }
  153. public function testCompleteGeneration()
  154. {
  155. $this->_object->setText('0123456789');
  156. $this->_object->draw();
  157. $instructions = $this->loadInstructionsFile('Int25_0123456789_instructions');
  158. $this->assertEquals($instructions, $this->_object->getInstructions());
  159. }
  160. public function testCompleteGenerationWithStretchText()
  161. {
  162. $this->_object->setText('0123456789');
  163. $this->_object->setStretchText(true);
  164. $this->_object->draw();
  165. $instructions = $this->loadInstructionsFile(
  166. 'Int25_0123456789_stretchtext_instructions');
  167. $this->assertEquals($instructions, $this->_object->getInstructions());
  168. }
  169. public function testCompleteGenerationWithBorder()
  170. {
  171. $this->_object->setText('0123456789');
  172. $this->_object->setWithBorder(true);
  173. $this->_object->draw();
  174. $instructions = $this->loadInstructionsFile(
  175. 'Int25_0123456789_border_instructions');
  176. $this->assertEquals($instructions, $this->_object->getInstructions());
  177. }
  178. public function testCompleteGenerationWithBearerBars()
  179. {
  180. $this->_object->setText('0123456789');
  181. $this->_object->setWithBearerBars(true);
  182. $this->_object->draw();
  183. $instructions = $this->loadInstructionsFile(
  184. 'Int25_0123456789_bearerbar_instructions');
  185. $this->assertEquals($instructions, $this->_object->getInstructions());
  186. }
  187. public function testCompleteGenerationWithOrientation()
  188. {
  189. $this->_object->setText('0123456789');
  190. $this->_object->setOrientation(60);
  191. $this->_object->draw();
  192. $instructions = $this->loadInstructionsFile(
  193. 'Int25_0123456789_oriented_instructions');
  194. $this->assertEquals($instructions, $this->_object->getInstructions());
  195. }
  196. public function testCompleteGenerationWithStretchTextWithOrientation()
  197. {
  198. $this->_object->setText('0123456789');
  199. $this->_object->setOrientation(60);
  200. $this->_object->setStretchText(true);
  201. $this->_object->draw();
  202. $instructions = $this->loadInstructionsFile(
  203. 'Int25_0123456789_stretchtext_oriented_instructions');
  204. $this->assertEquals($instructions, $this->_object->getInstructions());
  205. }
  206. public function testCompleteGenerationWithBorderWithOrientation()
  207. {
  208. $this->_object->setText('0123456789');
  209. $this->_object->setOrientation(60);
  210. $this->_object->setWithBorder(true);
  211. $this->_object->draw();
  212. $instructions = $this->loadInstructionsFile(
  213. 'Int25_0123456789_border_oriented_instructions');
  214. $this->assertEquals($instructions, $this->_object->getInstructions());
  215. }
  216. public function testCompleteGenerationWithBearerBarsWithOrientation()
  217. {
  218. $this->_object->setText('0123456789');
  219. $this->_object->setOrientation(60);
  220. $this->_object->setWithBearerBars(true);
  221. $this->_object->draw();
  222. $instructions = $this->loadInstructionsFile(
  223. 'Int25_0123456789_bearerbar_oriented_instructions');
  224. $this->assertEquals($instructions, $this->_object->getInstructions());
  225. }
  226. }