/tests/ZendTest/Barcode/Object/Code25interleavedTest.php

https://github.com/cgmartin/zf2 · PHP · 230 lines · 193 code · 27 blank · 10 comment · 0 complexity · 9d72cdecd5b30db06014a99280e5cca5 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace ZendTest\Barcode\Object;
  10. use Zend\Barcode;
  11. /**
  12. * @group Zend_Barcode
  13. */
  14. class Code25interleavedTest extends TestCommon
  15. {
  16. protected function getBarcodeObject($options = null)
  17. {
  18. return new Barcode\Object\Code25interleaved($options);
  19. }
  20. public function testType()
  21. {
  22. $this->assertSame('code25interleaved', $this->object->getType());
  23. }
  24. public function testWithBearerBars()
  25. {
  26. $this->object->setWithBearerBars(1);
  27. $this->assertSame(true, $this->object->getWithBearerBars());
  28. $this->object->setWithBearerBars(true);
  29. $this->assertSame(true, $this->object->getWithBearerBars());
  30. }
  31. public function testChecksum()
  32. {
  33. $this->assertSame(5, $this->object->getChecksum('0123456789'));
  34. }
  35. public function testSetText()
  36. {
  37. $this->object->setText('0123456789');
  38. $this->assertSame('0123456789', $this->object->getRawText());
  39. $this->assertSame('0123456789', $this->object->getText());
  40. $this->assertSame('0123456789', $this->object->getTextToDisplay());
  41. }
  42. public function testSetTextWithSpaces()
  43. {
  44. $this->object->setText(' 0123456789 ');
  45. $this->assertSame('0123456789', $this->object->getRawText());
  46. $this->assertSame('0123456789', $this->object->getText());
  47. $this->assertSame('0123456789', $this->object->getTextToDisplay());
  48. }
  49. public function testSetTextWithoutEvenNumberOfCharacters()
  50. {
  51. $this->object->setText('123456789');
  52. $this->assertSame('123456789', $this->object->getRawText());
  53. $this->assertSame('0123456789', $this->object->getText());
  54. $this->assertSame('0123456789', $this->object->getTextToDisplay());
  55. }
  56. public function testSetTextWithChecksum()
  57. {
  58. $this->object->setText('123456789');
  59. $this->object->setWithChecksum(true);
  60. $this->assertSame('123456789', $this->object->getRawText());
  61. $this->assertSame('1234567895', $this->object->getText());
  62. $this->assertSame('123456789', $this->object->getTextToDisplay());
  63. }
  64. public function testSetTextWithoutEvenNumberOfCharactersWithChecksum()
  65. {
  66. $this->object->setText('123456789');
  67. $this->object->setWithChecksum(true);
  68. $this->assertSame('123456789', $this->object->getRawText());
  69. $this->assertSame('1234567895', $this->object->getText());
  70. $this->assertSame('123456789', $this->object->getTextToDisplay());
  71. }
  72. public function testSetTextWithChecksumDisplayed()
  73. {
  74. $this->object->setText('123456789');
  75. $this->object->setWithChecksum(true);
  76. $this->object->setWithChecksumInText(true);
  77. $this->assertSame('123456789', $this->object->getRawText());
  78. $this->assertSame('1234567895', $this->object->getText());
  79. $this->assertSame('1234567895', $this->object->getTextToDisplay());
  80. }
  81. public function testSetTextWithoutEvenNumberOfCharactersWithChecksumDisplayed()
  82. {
  83. $this->object->setText('0123456789');
  84. $this->object->setWithChecksum(true);
  85. $this->object->setWithChecksumInText(true);
  86. $this->assertSame('0123456789', $this->object->getRawText());
  87. $this->assertSame('001234567895', $this->object->getText());
  88. $this->assertSame('001234567895', $this->object->getTextToDisplay());
  89. }
  90. public function testBadTextAlwaysAllowed()
  91. {
  92. $this->object->setText('a');
  93. $this->assertSame('0a', $this->object->getText());
  94. }
  95. public function testBadTextDetectedIfChecksumWished()
  96. {
  97. $this->setExpectedException('\Zend\Barcode\Object\Exception\ExceptionInterface');
  98. $this->object->setText('a');
  99. $this->object->setWithChecksum(true);
  100. $this->object->getText();
  101. }
  102. public function testCheckGoodParams()
  103. {
  104. $this->object->setText('0123456789');
  105. $this->assertTrue($this->object->checkParams());
  106. }
  107. public function testCheckParamsWithLowRatio()
  108. {
  109. $this->setExpectedException('\Zend\Barcode\Object\Exception\ExceptionInterface');
  110. $this->object->setText('0123456789');
  111. $this->object->setBarThinWidth(21);
  112. $this->object->setBarThickWidth(40);
  113. $this->object->checkParams();
  114. }
  115. public function testCheckParamsWithHighRatio()
  116. {
  117. $this->setExpectedException('\Zend\Barcode\Object\Exception\ExceptionInterface');
  118. $this->object->setText('0123456789');
  119. $this->object->setBarThinWidth(20);
  120. $this->object->setBarThickWidth(61);
  121. $this->object->checkParams();
  122. }
  123. public function testGetKnownWidthWithoutOrientation()
  124. {
  125. $this->object->setText('0123456789');
  126. $this->assertEquals(119, $this->object->getWidth());
  127. $this->object->setWithQuietZones(false);
  128. $this->assertEquals(99, $this->object->getWidth(true));
  129. }
  130. public function testCompleteGeneration()
  131. {
  132. $this->object->setText('0123456789');
  133. $this->object->draw();
  134. $instructions = $this->loadInstructionsFile('Int25_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. 'Int25_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. 'Int25_0123456789_border_instructions');
  153. $this->assertEquals($instructions, $this->object->getInstructions());
  154. }
  155. public function testCompleteGenerationWithBearerBars()
  156. {
  157. $this->object->setText('0123456789');
  158. $this->object->setWithBearerBars(true);
  159. $this->object->draw();
  160. $instructions = $this->loadInstructionsFile(
  161. 'Int25_0123456789_bearerbar_instructions');
  162. $this->assertEquals($instructions, $this->object->getInstructions());
  163. }
  164. public function testCompleteGenerationWithOrientation()
  165. {
  166. $this->object->setText('0123456789');
  167. $this->object->setOrientation(60);
  168. $this->object->draw();
  169. $instructions = $this->loadInstructionsFile(
  170. 'Int25_0123456789_oriented_instructions');
  171. $this->assertEquals($instructions, $this->object->getInstructions());
  172. }
  173. public function testCompleteGenerationWithStretchTextWithOrientation()
  174. {
  175. $this->object->setText('0123456789');
  176. $this->object->setOrientation(60);
  177. $this->object->setStretchText(true);
  178. $this->object->draw();
  179. $instructions = $this->loadInstructionsFile(
  180. 'Int25_0123456789_stretchtext_oriented_instructions');
  181. $this->assertEquals($instructions, $this->object->getInstructions());
  182. }
  183. public function testCompleteGenerationWithBorderWithOrientation()
  184. {
  185. $this->object->setText('0123456789');
  186. $this->object->setOrientation(60);
  187. $this->object->setWithBorder(true);
  188. $this->object->draw();
  189. $instructions = $this->loadInstructionsFile(
  190. 'Int25_0123456789_border_oriented_instructions');
  191. $this->assertEquals($instructions, $this->object->getInstructions());
  192. }
  193. public function testCompleteGenerationWithBearerBarsWithOrientation()
  194. {
  195. $this->object->setText('0123456789');
  196. $this->object->setOrientation(60);
  197. $this->object->setWithBearerBars(true);
  198. $this->object->draw();
  199. $instructions = $this->loadInstructionsFile(
  200. 'Int25_0123456789_bearerbar_oriented_instructions');
  201. $this->assertEquals($instructions, $this->object->getInstructions());
  202. }
  203. }