RoyalmailTest.php 5.3 KB

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