Ean5Test.php 5.2 KB

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