Code25Test.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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-2012 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/Code25.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Barcode
  27. * @subpackage UnitTests
  28. * @group Zend_Barcode
  29. * @copyright Copyright (c) 2005-2012 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_Code25Test extends Zend_Barcode_Object_TestCommon
  33. {
  34. protected function _getBarcodeObject($options = null)
  35. {
  36. return new Zend_Barcode_Object_Code25($options);
  37. }
  38. public function testType()
  39. {
  40. $this->assertSame('code25', $this->_object->getType());
  41. }
  42. public function testChecksum()
  43. {
  44. $this->assertSame(5, $this->_object->getChecksum('0123456789'));
  45. $this->assertSame(0, $this->_object->getChecksum('13'));
  46. }
  47. public function testSetText()
  48. {
  49. $this->_object->setText('0123456789');
  50. $this->assertSame('0123456789', $this->_object->getRawText());
  51. $this->assertSame('0123456789', $this->_object->getText());
  52. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  53. }
  54. public function testSetTextWithOddNumberOfCharacters()
  55. {
  56. $this->_object->setText('123456789');
  57. $this->assertSame('123456789', $this->_object->getRawText());
  58. $this->assertSame('123456789', $this->_object->getText());
  59. $this->assertSame('123456789', $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 testSetTextWithChecksum()
  69. {
  70. $this->_object->setText('0123456789');
  71. $this->_object->setWithChecksum(true);
  72. $this->assertSame('0123456789', $this->_object->getRawText());
  73. $this->assertSame('01234567895', $this->_object->getText());
  74. $this->assertSame('0123456789', $this->_object->getTextToDisplay());
  75. }
  76. public function testSetTextWithChecksumDisplayed()
  77. {
  78. $this->_object->setText('0123456789');
  79. $this->_object->setWithChecksum(true);
  80. $this->_object->setWithChecksumInText(true);
  81. $this->assertSame('0123456789', $this->_object->getRawText());
  82. $this->assertSame('01234567895', $this->_object->getText());
  83. $this->assertSame('01234567895', $this->_object->getTextToDisplay());
  84. }
  85. public function testBadTextAlwaysAllowed()
  86. {
  87. $this->_object->setText('a');
  88. $this->assertSame('a', $this->_object->getText());
  89. }
  90. /**
  91. * @expectedException Zend_Barcode_Object_Exception
  92. */
  93. public function testBadTextDetectedIfChecksumWished()
  94. {
  95. $this->_object->setText('a');
  96. $this->_object->setWithChecksum(true);
  97. $this->_object->getText();
  98. }
  99. public function testCheckGoodParams()
  100. {
  101. $this->_object->setText('0123456789');
  102. $this->assertTrue($this->_object->checkParams());
  103. }
  104. /**
  105. * @expectedException Zend_Barcode_Object_Exception
  106. */
  107. public function testCheckParamsWithLowRatio()
  108. {
  109. $this->_object->setText('0123456789');
  110. $this->_object->setBarThinWidth(21);
  111. $this->_object->setBarThickWidth(40);
  112. $this->_object->checkParams();
  113. }
  114. /**
  115. * @expectedException Zend_Barcode_Object_Exception
  116. */
  117. public function testCheckParamsWithHighRatio()
  118. {
  119. $this->_object->setText('0123456789');
  120. $this->_object->setBarThinWidth(20);
  121. $this->_object->setBarThickWidth(61);
  122. $this->_object->checkParams();
  123. }
  124. public function testGetKnownWidthWithoutOrientation()
  125. {
  126. $this->_object->setText('0123456789');
  127. $this->assertEquals(180, $this->_object->getWidth());
  128. $this->_object->setWithQuietZones(false);
  129. $this->assertEquals(160, $this->_object->getWidth(true));
  130. }
  131. public function testCompleteGeneration()
  132. {
  133. $this->_object->setText('0123456789');
  134. $this->_object->draw();
  135. $instructions = $this->loadInstructionsFile('Code25_0123456789_instructions');
  136. $this->assertEquals($instructions, $this->_object->getInstructions());
  137. }
  138. public function testCompleteGenerationWithStretchText()
  139. {
  140. $this->_object->setText('0123456789');
  141. $this->_object->setStretchText(true);
  142. $this->_object->draw();
  143. $instructions = $this->loadInstructionsFile(
  144. 'Code25_0123456789_stretchtext_instructions');
  145. $this->assertEquals($instructions, $this->_object->getInstructions());
  146. }
  147. public function testCompleteGenerationWithBorder()
  148. {
  149. $this->_object->setText('0123456789');
  150. $this->_object->setWithBorder(true);
  151. $this->_object->draw();
  152. $instructions = $this->loadInstructionsFile(
  153. 'Code25_0123456789_border_instructions');
  154. $this->assertEquals($instructions, $this->_object->getInstructions());
  155. }
  156. public function testCompleteGenerationWithOrientation()
  157. {
  158. $this->_object->setText('0123456789');
  159. $this->_object->setOrientation(60);
  160. $this->_object->draw();
  161. $instructions = $this->loadInstructionsFile(
  162. 'Code25_0123456789_oriented_instructions');
  163. $this->assertEquals($instructions, $this->_object->getInstructions());
  164. }
  165. public function testCompleteGenerationWithStretchTextWithOrientation()
  166. {
  167. $this->_object->setText('0123456789');
  168. $this->_object->setOrientation(60);
  169. $this->_object->setStretchText(true);
  170. $this->_object->draw();
  171. $instructions = $this->loadInstructionsFile(
  172. 'Code25_0123456789_stretchtext_oriented_instructions');
  173. $this->assertEquals($instructions, $this->_object->getInstructions());
  174. }
  175. public function testCompleteGenerationWithBorderWithOrientation()
  176. {
  177. $this->_object->setText('0123456789');
  178. $this->_object->setOrientation(60);
  179. $this->_object->setWithBorder(true);
  180. $this->_object->draw();
  181. $instructions = $this->loadInstructionsFile(
  182. 'Code25_0123456789_border_oriented_instructions');
  183. $this->assertEquals($instructions, $this->_object->getInstructions());
  184. }
  185. }