UpceTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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-2014 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/Upce.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Barcode
  27. * @subpackage UnitTests
  28. * @group Zend_Barcode
  29. * @copyright Copyright (c) 2005-2014 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_UpceTest extends Zend_Barcode_Object_TestCommon
  33. {
  34. protected function _getBarcodeObject($options = null)
  35. {
  36. return new Zend_Barcode_Object_Upce($options);
  37. }
  38. public function testType()
  39. {
  40. $this->assertSame('upce', $this->_object->getType());
  41. }
  42. public function testChecksum()
  43. {
  44. $this->assertSame(9, $this->_object->getChecksum('3456789'));
  45. }
  46. public function testSetText()
  47. {
  48. $this->_object->setText('1234567');
  49. $this->assertSame('1234567', $this->_object->getRawText());
  50. $this->assertSame('12345670', $this->_object->getText());
  51. $this->assertSame('12345670', $this->_object->getTextToDisplay());
  52. }
  53. public function testSetTextWithout8Characters()
  54. {
  55. $this->_object->setText('12345');
  56. $this->assertSame('12345', $this->_object->getRawText());
  57. $this->assertSame('00123457', $this->_object->getText());
  58. $this->assertSame('00123457', $this->_object->getTextToDisplay());
  59. }
  60. public function testSetTextWithout0or1AtBeginning()
  61. {
  62. $this->_object->setText('3234567');
  63. $this->assertSame('3234567', $this->_object->getRawText());
  64. $this->assertSame('02345673', $this->_object->getText());
  65. $this->assertSame('02345673', $this->_object->getTextToDisplay());
  66. }
  67. public function testSetTextWithoutChecksumHasNoEffect()
  68. {
  69. $this->_object->setText('1234567');
  70. $this->_object->setWithChecksum(false);
  71. $this->assertSame('1234567', $this->_object->getRawText());
  72. $this->assertSame('12345670', $this->_object->getText());
  73. $this->assertSame('12345670', $this->_object->getTextToDisplay());
  74. }
  75. public function testSetTextWithSpaces()
  76. {
  77. $this->_object->setText(' 1234567 ');
  78. $this->assertSame('1234567', $this->_object->getRawText());
  79. $this->assertSame('12345670', $this->_object->getText());
  80. $this->assertSame('12345670', $this->_object->getTextToDisplay());
  81. }
  82. public function testSetTextWithChecksumNotDisplayed()
  83. {
  84. $this->_object->setText('1234567');
  85. $this->_object->setWithChecksumInText(false);
  86. $this->assertSame('1234567', $this->_object->getRawText());
  87. $this->assertSame('12345670', $this->_object->getText());
  88. $this->assertSame('12345670', $this->_object->getTextToDisplay());
  89. }
  90. /**
  91. * @expectedException Zend_Barcode_Object_Exception
  92. */
  93. public function testBadTextDetectedIfChecksumWished()
  94. {
  95. $this->_object->setText('a');
  96. $this->_object->setWithChecksum(true);
  97. $this->_object->getText();
  98. }
  99. public function testCheckGoodParams()
  100. {
  101. $this->_object->setText('1234567');
  102. $this->assertTrue($this->_object->checkParams());
  103. }
  104. public function testGetKnownWidthWithoutOrientation()
  105. {
  106. $this->_object->setText('1234567');
  107. $this->assertEquals(71, $this->_object->getWidth());
  108. $this->_object->setWithQuietZones(false);
  109. $this->assertEquals(71, $this->_object->getWidth(true));
  110. }
  111. public function testCompleteGeneration()
  112. {
  113. $this->_object->setText('1234567');
  114. $this->_object->draw();
  115. $instructions = $this->loadInstructionsFile('Upce_1234567_instructions');
  116. $this->assertEquals($instructions, $this->_object->getInstructions());
  117. }
  118. public function testCompleteGenerationWithBorder()
  119. {
  120. $this->_object->setText('1234567');
  121. $this->_object->setWithBorder(true);
  122. $this->_object->draw();
  123. $instructions = $this->loadInstructionsFile(
  124. 'Upce_1234567_border_instructions');
  125. $this->assertEquals($instructions, $this->_object->getInstructions());
  126. }
  127. public function testCompleteGenerationWithOrientation()
  128. {
  129. $this->_object->setText('1234567');
  130. $this->_object->setOrientation(60);
  131. $this->_object->draw();
  132. $instructions = $this->loadInstructionsFile(
  133. 'Upce_1234567_oriented_instructions');
  134. $this->assertEquals($instructions, $this->_object->getInstructions());
  135. }
  136. public function testCompleteGenerationWithBorderWithOrientation()
  137. {
  138. $this->_object->setText('1234567');
  139. $this->_object->setOrientation(60);
  140. $this->_object->setWithBorder(true);
  141. $this->_object->draw();
  142. $instructions = $this->loadInstructionsFile(
  143. 'Upce_1234567_border_oriented_instructions');
  144. $this->assertEquals($instructions, $this->_object->getInstructions());
  145. }
  146. public function testGetDefaultHeight()
  147. {
  148. // Checksum activated => text needed
  149. $this->_object->setText('1234567');
  150. $this->assertEquals(62, $this->_object->getHeight(true));
  151. }
  152. }