CcnumTest.php 2.8 KB

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