2
0

BarcodeTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_Validate
  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. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /** Zend_Validate_Barcode */
  27. require_once 'Zend/Validate/Barcode.php';
  28. /**
  29. * Zend_Validate_Barcode
  30. *
  31. * @category Zend
  32. * @package Zend_Validate
  33. * @subpackage UnitTests
  34. * @uses Zend_Validate_Barcode
  35. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_Validate
  38. */
  39. class Zend_Validate_BarcodeTest extends PHPUnit_Framework_TestCase
  40. {
  41. public function testUpcA()
  42. {
  43. $barcode = new Zend_Validate_Barcode('upc-a');
  44. $this->assertTrue($barcode->isValid('065100004327'));
  45. $this->assertFalse($barcode->isValid('123'));
  46. $this->assertFalse($barcode->isValid('065100004328'));
  47. }
  48. public function testEan13()
  49. {
  50. $barcode = new Zend_Validate_Barcode('ean-13');
  51. $this->assertTrue($barcode->isValid('0075678164125'));
  52. $this->assertFalse($barcode->isValid('123'));
  53. $this->assertFalse($barcode->isValid('0075678164124'));
  54. }
  55. /**
  56. * Test if EAN-13 contains only numeric characters
  57. *
  58. * @group ZF-3297
  59. */
  60. public function testEan13ContainsOnlyNumeric()
  61. {
  62. $barcode = new Zend_Validate_Barcode('ean-13');
  63. $this->assertFalse($barcode->isValid('3RH1131-1BB40'));
  64. }
  65. public function testNoneExisting()
  66. {
  67. try {
  68. $barcode = new Zend_Validate_Barcode('Zend');
  69. $this->fail("'Zend' is not a valid barcode type'");
  70. } catch (Exception $e) {
  71. $this->assertContains("'Zend' is not supported", $e->getMessage());
  72. }
  73. }
  74. public function testSetType()
  75. {
  76. $barcode = new Zend_Validate_Barcode('upc-a');
  77. $this->assertTrue($barcode->isValid('065100004327'));
  78. $barcode->setType('ean-13');
  79. $this->assertTrue($barcode->isValid('0075678164125'));
  80. }
  81. /**
  82. * @ZF-4352
  83. */
  84. public function testNonStringValidation()
  85. {
  86. $barcode = new Zend_Validate_Barcode('upc-a');
  87. $this->assertFalse($barcode->isValid(106510000.4327));
  88. $this->assertFalse($barcode->isValid(array('065100004327')));
  89. $barcode = new Zend_Validate_Barcode('ean-13');
  90. $this->assertFalse($barcode->isValid(06510000.4327));
  91. $this->assertFalse($barcode->isValid(array('065100004327')));
  92. }
  93. }