Itf14Test.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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-2015 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(__FILE__) . '/TestCommon.php';
  23. require_once 'Zend/Barcode/Object/Itf14.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Barcode
  27. * @subpackage UnitTests
  28. * @group Zend_Barcode
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Barcode_Object_Itf14Test extends Zend_Barcode_Object_TestCommon
  33. {
  34. protected function _getBarcodeObject($options = null)
  35. {
  36. return new Zend_Barcode_Object_Itf14($options);
  37. }
  38. public function testType()
  39. {
  40. $this->assertSame('itf14', $this->_object->getType());
  41. }
  42. public function testChecksum()
  43. {
  44. $this->assertSame(5, $this->_object->getChecksum('0000123456789'));
  45. }
  46. public function testSetText()
  47. {
  48. $this->_object->setText('0000123456789');
  49. $this->assertSame('0000123456789', $this->_object->getRawText());
  50. $this->assertSame('00001234567895', $this->_object->getText());
  51. $this->assertSame('00001234567895', $this->_object->getTextToDisplay());
  52. }
  53. public function testSetTextWithout14Characters()
  54. {
  55. $this->_object->setText('123456789');
  56. $this->assertSame('123456789', $this->_object->getRawText());
  57. $this->assertSame('00001234567895', $this->_object->getText());
  58. $this->assertSame('00001234567895', $this->_object->getTextToDisplay());
  59. }
  60. public function testSetTextWithoutChecksumHasNoEffect()
  61. {
  62. $this->_object->setText('0000123456789');
  63. $this->_object->setWithChecksum(false);
  64. $this->assertSame('0000123456789', $this->_object->getRawText());
  65. $this->assertSame('00001234567895', $this->_object->getText());
  66. $this->assertSame('00001234567895', $this->_object->getTextToDisplay());
  67. }
  68. public function testSetTextWithSpaces()
  69. {
  70. $this->_object->setText(' 0000123456789 ');
  71. $this->assertSame('0000123456789', $this->_object->getRawText());
  72. $this->assertSame('00001234567895', $this->_object->getText());
  73. $this->assertSame('00001234567895', $this->_object->getTextToDisplay());
  74. }
  75. public function testSetTextWithChecksumNotDisplayed()
  76. {
  77. $this->_object->setText('0000123456789');
  78. $this->_object->setWithChecksumInText(false);
  79. $this->assertSame('0000123456789', $this->_object->getRawText());
  80. $this->assertSame('00001234567895', $this->_object->getText());
  81. $this->assertSame('00001234567895', $this->_object->getTextToDisplay());
  82. }
  83. /**
  84. * @expectedException Zend_Barcode_Object_Exception
  85. */
  86. public function testBadTextDetectedIfChecksumWished()
  87. {
  88. $this->_object->setText('a');
  89. $this->_object->setWithChecksum(true);
  90. $this->_object->getText();
  91. }
  92. public function testCheckGoodParams()
  93. {
  94. $this->_object->setText('0000123456789');
  95. $this->assertTrue($this->_object->checkParams());
  96. }
  97. /**
  98. * @expectedException Zend_Barcode_Object_Exception
  99. */
  100. public function testCheckParamsWithLowRatio()
  101. {
  102. $this->_object->setText('0000123456789');
  103. $this->_object->setBarThinWidth(21);
  104. $this->_object->setBarThickWidth(40);
  105. $this->_object->checkParams();
  106. }
  107. /**
  108. * @expectedException Zend_Barcode_Object_Exception
  109. */
  110. public function testCheckParamsWithHighRatio()
  111. {
  112. $this->_object->setText('0000123456789');
  113. $this->_object->setBarThinWidth(20);
  114. $this->_object->setBarThickWidth(61);
  115. $this->_object->checkParams();
  116. }
  117. public function testGetKnownWidthWithoutOrientation()
  118. {
  119. $this->_object->setText('0000123456789');
  120. $this->assertEquals(155, $this->_object->getWidth());
  121. $this->_object->setWithQuietZones(false);
  122. $this->assertEquals(135, $this->_object->getWidth(true));
  123. }
  124. public function testCompleteGeneration()
  125. {
  126. $this->_object->setText('0000123456789');
  127. $this->_object->draw();
  128. $instructions = $this->loadInstructionsFile('Itf14_0000123456789_instructions');
  129. $this->assertEquals($instructions, $this->_object->getInstructions());
  130. }
  131. public function testCompleteGenerationWithStretchText()
  132. {
  133. $this->_object->setText('0000123456789');
  134. $this->_object->setStretchText(true);
  135. $this->_object->draw();
  136. $instructions = $this->loadInstructionsFile(
  137. 'Itf14_0000123456789_stretchtext_instructions');
  138. $this->assertEquals($instructions, $this->_object->getInstructions());
  139. }
  140. public function testCompleteGenerationWithBorder()
  141. {
  142. $this->_object->setText('0000123456789');
  143. $this->_object->setWithBorder(true);
  144. $this->_object->draw();
  145. $instructions = $this->loadInstructionsFile(
  146. 'Itf14_0000123456789_border_instructions');
  147. $this->assertEquals($instructions, $this->_object->getInstructions());
  148. }
  149. public function testCompleteGenerationWithBearerBars()
  150. {
  151. $this->_object->setText('0000123456789');
  152. $this->_object->setWithBearerBars(true);
  153. $this->_object->draw();
  154. $instructions = $this->loadInstructionsFile(
  155. 'Itf14_0000123456789_bearerbar_instructions');
  156. $this->assertEquals($instructions, $this->_object->getInstructions());
  157. }
  158. public function testCompleteGenerationWithOrientation()
  159. {
  160. $this->_object->setText('0000123456789');
  161. $this->_object->setOrientation(60);
  162. $this->_object->draw();
  163. $instructions = $this->loadInstructionsFile(
  164. 'Itf14_0000123456789_oriented_instructions');
  165. $this->assertEquals($instructions, $this->_object->getInstructions());
  166. }
  167. public function testCompleteGenerationWithStretchTextWithOrientation()
  168. {
  169. $this->_object->setText('0000123456789');
  170. $this->_object->setOrientation(60);
  171. $this->_object->setStretchText(true);
  172. $this->_object->draw();
  173. $instructions = $this->loadInstructionsFile(
  174. 'Itf14_0000123456789_stretchtext_oriented_instructions');
  175. $this->assertEquals($instructions, $this->_object->getInstructions());
  176. }
  177. public function testCompleteGenerationWithBorderWithOrientation()
  178. {
  179. $this->_object->setText('0000123456789');
  180. $this->_object->setOrientation(60);
  181. $this->_object->setWithBorder(true);
  182. $this->_object->draw();
  183. $instructions = $this->loadInstructionsFile(
  184. 'Itf14_0000123456789_border_oriented_instructions');
  185. $this->assertEquals($instructions, $this->_object->getInstructions());
  186. }
  187. public function testCompleteGenerationWithBearerBarsWithOrientation()
  188. {
  189. $this->_object->setText('0000123456789');
  190. $this->_object->setOrientation(60);
  191. $this->_object->setWithBearerBars(true);
  192. $this->_object->draw();
  193. $instructions = $this->loadInstructionsFile(
  194. 'Itf14_0000123456789_bearerbar_oriented_instructions');
  195. $this->assertEquals($instructions, $this->_object->getInstructions());
  196. }
  197. public function testGetDefaultHeight()
  198. {
  199. // Checksum activated => text needed
  200. $this->_object->setText('0000123456789');
  201. $this->assertEquals(62, $this->_object->getHeight(true));
  202. }
  203. }