Itf14Test.php 7.9 KB

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