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