Ean13Test.php 5.7 KB

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