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