RoyalmailTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/Royalmail.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_RoyalmailTest extends Zend_Barcode_Object_TestCommon
  34. {
  35. protected function _getBarcodeObject($options = null)
  36. {
  37. return new Zend_Barcode_Object_Royalmail($options);
  38. }
  39. public function testType()
  40. {
  41. $this->assertSame('royalmail', $this->_object->getType());
  42. }
  43. public function testChecksum()
  44. {
  45. $this->assertSame('W', $this->_object->getChecksum('012345'));
  46. $this->assertSame('H', $this->_object->getChecksum('06CIOU'));
  47. $this->assertSame('K', $this->_object->getChecksum('SN34RD1A'));
  48. }
  49. public function testSetText()
  50. {
  51. $this->_object->setText('012345');
  52. $this->assertSame('012345', $this->_object->getRawText());
  53. $this->assertSame('012345W', $this->_object->getText());
  54. $this->assertSame('012345W', $this->_object->getTextToDisplay());
  55. }
  56. public function testSetTextWithoutChecksumHasNoEffect()
  57. {
  58. $this->_object->setText('012345');
  59. $this->_object->setWithChecksum(false);
  60. $this->assertSame('012345', $this->_object->getRawText());
  61. $this->assertSame('012345W', $this->_object->getText());
  62. $this->assertSame('012345W', $this->_object->getTextToDisplay());
  63. }
  64. public function testSetTextWithSpaces()
  65. {
  66. $this->_object->setText(' 012345 ');
  67. $this->assertSame('012345', $this->_object->getRawText());
  68. $this->assertSame('012345W', $this->_object->getText());
  69. $this->assertSame('012345W', $this->_object->getTextToDisplay());
  70. }
  71. public function testSetTextWithChecksumNotDisplayed()
  72. {
  73. $this->_object->setText('012345');
  74. $this->_object->setWithChecksumInText(false);
  75. $this->assertSame('012345', $this->_object->getRawText());
  76. $this->assertSame('012345W', $this->_object->getText());
  77. $this->assertSame('012345W', $this->_object->getTextToDisplay());
  78. }
  79. /**
  80. * @expectedException Zend_Barcode_Object_Exception
  81. */
  82. public function testBadTextDetectedIfChecksumWished()
  83. {
  84. $this->_object->setText('a');
  85. $this->_object->setWithChecksum(true);
  86. $this->_object->getText();
  87. }
  88. public function testCheckGoodParams()
  89. {
  90. $this->_object->setText('012345');
  91. $this->assertTrue($this->_object->checkParams());
  92. }
  93. public function testGetKnownWidthWithoutOrientation()
  94. {
  95. $this->_object->setText('012345');
  96. $this->assertEquals(158, $this->_object->getWidth());
  97. $this->_object->setWithQuietZones(false);
  98. $this->assertEquals(118, $this->_object->getWidth(true));
  99. }
  100. public function testCompleteGeneration()
  101. {
  102. $this->_object->setText('012345');
  103. $this->_object->draw();
  104. $instructions = $this->loadInstructionsFile('Royalmail_012345_instructions');
  105. $this->assertEquals($instructions, $this->_object->getInstructions());
  106. }
  107. public function testCompleteGenerationWithBorder()
  108. {
  109. $this->_object->setText('012345');
  110. $this->_object->setWithBorder(true);
  111. $this->_object->draw();
  112. $instructions = $this->loadInstructionsFile(
  113. 'Royalmail_012345_border_instructions');
  114. $this->assertEquals($instructions, $this->_object->getInstructions());
  115. }
  116. public function testCompleteGenerationWithOrientation()
  117. {
  118. $this->_object->setText('012345');
  119. $this->_object->setOrientation(60);
  120. $this->_object->draw();
  121. $instructions = $this->loadInstructionsFile(
  122. 'Royalmail_012345_oriented_instructions');
  123. $this->assertEquals($instructions, $this->_object->getInstructions());
  124. }
  125. public function testCompleteGenerationWithBorderWithOrientation()
  126. {
  127. $this->_object->setText('012345');
  128. $this->_object->setOrientation(60);
  129. $this->_object->setWithBorder(true);
  130. $this->_object->draw();
  131. $instructions = $this->loadInstructionsFile(
  132. 'Royalmail_012345_border_oriented_instructions');
  133. $this->assertEquals($instructions, $this->_object->getInstructions());
  134. }
  135. public function testGetDefaultHeight()
  136. {
  137. // Checksum activated => text needed
  138. $this->_object->setText('012345');
  139. $this->assertEquals(20, $this->_object->getHeight(true));
  140. }
  141. }