CcnumTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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-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. /**
  23. * @see Zend_Validate_Ccnum
  24. */
  25. require_once 'Zend/Validate/Ccnum.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Validate
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Validate
  33. */
  34. class Zend_Validate_CcnumTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * Zend_Validate_Ccnum object
  38. *
  39. * @var Zend_Validate_Ccnum
  40. */
  41. protected $_validator;
  42. /**
  43. * Creates a new Zend_Validate_Ccnum object for each test method
  44. *
  45. * @return void
  46. */
  47. public function setUp()
  48. {
  49. set_error_handler(array($this, 'errorHandlerIgnore'));
  50. $this->_validator = new Zend_Validate_Ccnum();
  51. }
  52. /**
  53. * Ensures that the validator follows expected behavior
  54. *
  55. * @return void
  56. */
  57. public function testBasic()
  58. {
  59. $valuesExpected = array(
  60. '4929000000006' => true,
  61. '5404000000000001' => true,
  62. '374200000000004' => true,
  63. '4444555566667777' => false,
  64. 'ABCDEF' => false
  65. );
  66. foreach ($valuesExpected as $input => $result) {
  67. $this->assertEquals($result, $this->_validator->isValid($input));
  68. }
  69. restore_error_handler();
  70. }
  71. /**
  72. * Ensures that getMessages() returns expected default value
  73. *
  74. * @return void
  75. */
  76. public function testGetMessages()
  77. {
  78. $this->assertEquals(array(), $this->_validator->getMessages());
  79. restore_error_handler();
  80. }
  81. /**
  82. * Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
  83. *
  84. * @param integer $errno
  85. * @param string $errstr
  86. * @param string $errfile
  87. * @param integer $errline
  88. * @param array $errcontext
  89. * @return void
  90. */
  91. public function errorHandlerIgnore($errno, $errstr, $errfile, $errline, array $errcontext)
  92. {
  93. $this->_errorOccured = true;
  94. }
  95. }