2
0

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