PlanetTest.php 5.7 KB

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