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