Ean5Test.php 5.2 KB

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