PostnetTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  23. require_once dirname(__FILE__) . '/TestCommon.php';
  24. require_once 'Zend/Barcode/Object/Postnet.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Barcode
  28. * @subpackage UnitTests
  29. * @group Zend_Barcode
  30. * @copyright Copyright (c) 2005-2009 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_PostnetTest extends Zend_Barcode_Object_TestCommon
  34. {
  35. protected function _getBarcodeObject($options = null)
  36. {
  37. return new Zend_Barcode_Object_Postnet($options);
  38. }
  39. public function testType()
  40. {
  41. $this->assertSame('postnet', $this->_object->getType());
  42. }
  43. public function testChecksum()
  44. {
  45. $this->assertSame(5, $this->_object->getChecksum('012345'));
  46. $this->assertSame(0, $this->_object->getChecksum('01234'));
  47. }
  48. public function testSetText()
  49. {
  50. $this->_object->setText('012345');
  51. $this->assertSame('012345', $this->_object->getRawText());
  52. $this->assertSame('0123455', $this->_object->getText());
  53. $this->assertSame('0123455', $this->_object->getTextToDisplay());
  54. }
  55. /**
  56. * @expectedException Zend_Barcode_Object_Exception
  57. */
  58. public function testSetTextWithoutGoodNumberOfCharacters()
  59. {
  60. $this->_object->setText('1234');
  61. $this->_object->getText();
  62. }
  63. public function testSetTextWithoutChecksumHasNoEffect()
  64. {
  65. $this->_object->setText('012345');
  66. $this->_object->setWithChecksum(false);
  67. $this->assertSame('012345', $this->_object->getRawText());
  68. $this->assertSame('0123455', $this->_object->getText());
  69. $this->assertSame('0123455', $this->_object->getTextToDisplay());
  70. }
  71. public function testSetTextWithSpaces()
  72. {
  73. $this->_object->setText(' 012345 ');
  74. $this->assertSame('012345', $this->_object->getRawText());
  75. $this->assertSame('0123455', $this->_object->getText());
  76. $this->assertSame('0123455', $this->_object->getTextToDisplay());
  77. }
  78. public function testSetTextWithChecksumNotDisplayed()
  79. {
  80. $this->_object->setText('012345');
  81. $this->_object->setWithChecksumInText(false);
  82. $this->assertSame('012345', $this->_object->getRawText());
  83. $this->assertSame('0123455', $this->_object->getText());
  84. $this->assertSame('0123455', $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('012345');
  98. $this->assertTrue($this->_object->checkParams());
  99. }
  100. public function testGetKnownWidthWithoutOrientation()
  101. {
  102. $this->_object->setText('012345');
  103. $this->assertEquals(186, $this->_object->getWidth());
  104. }
  105. public function testCompleteGeneration()
  106. {
  107. $this->_object->setText('012345');
  108. $this->_object->draw();
  109. $instructions = $this->loadInstructionsFile('Postnet_012345_instructions');
  110. $this->assertEquals($instructions, $this->_object->getInstructions());
  111. }
  112. public function testCompleteGenerationWithBorder()
  113. {
  114. $this->_object->setText('012345');
  115. $this->_object->setWithBorder(true);
  116. $this->_object->draw();
  117. $instructions = $this->loadInstructionsFile(
  118. 'Postnet_012345_border_instructions');
  119. $this->assertEquals($instructions, $this->_object->getInstructions());
  120. }
  121. public function testCompleteGenerationWithOrientation()
  122. {
  123. $this->_object->setText('012345');
  124. $this->_object->setOrientation(60);
  125. $this->_object->draw();
  126. $instructions = $this->loadInstructionsFile(
  127. 'Postnet_012345_oriented_instructions');
  128. $this->assertEquals($instructions, $this->_object->getInstructions());
  129. }
  130. public function testCompleteGenerationWithBorderWithOrientation()
  131. {
  132. $this->_object->setText('012345');
  133. $this->_object->setOrientation(60);
  134. $this->_object->setWithBorder(true);
  135. $this->_object->draw();
  136. $instructions = $this->loadInstructionsFile(
  137. 'Postnet_012345_border_oriented_instructions');
  138. $this->assertEquals($instructions, $this->_object->getInstructions());
  139. }
  140. public function testGetDefaultHeight()
  141. {
  142. // Checksum activated => text needed
  143. $this->_object->setText('012345');
  144. $this->assertEquals(20, $this->_object->getHeight(true));
  145. }
  146. }