2
0

IbanTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: DateTest.php 13371 2008-12-19 11:41:09Z thomas $
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /**
  27. * @see Zend_Validate_Iban
  28. */
  29. require_once 'Zend/Validate/Iban.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Validate
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Validate_IbanTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * Ensures that the validator follows expected behavior
  41. *
  42. * @return void
  43. */
  44. public function testBasic()
  45. {
  46. $validator = new Zend_Validate_Iban();
  47. $valuesExpected = array(
  48. 'AD1200012030200359100100' => true,
  49. 'AT611904300234573201' => true,
  50. 'AT61 1904 3002 3457 3201' => false,
  51. 'AD1200012030200354100100' => false,
  52. );
  53. foreach ($valuesExpected as $input => $result) {
  54. $this->assertEquals($result, $validator->isValid($input),
  55. "'$input' expected to be " . ($result ? '' : 'in') . 'valid');
  56. }
  57. }
  58. public function testSettingAndGettingLocale()
  59. {
  60. $validator = new Zend_Validate_Iban();
  61. try {
  62. $validator->setLocale('de_QA');
  63. $this->fail();
  64. } catch (Zend_Validate_Exception $e) {
  65. $this->assertContains('IBAN validation', $e->getMessage());
  66. }
  67. $validator->setLocale('de_DE');
  68. $this->assertEquals('de_DE', $validator->getLocale());
  69. }
  70. public function testInstanceWithLocale()
  71. {
  72. $validator = new Zend_Validate_Iban('de_AT');
  73. $this->assertTrue($validator->isValid('AT611904300234573201'));
  74. }
  75. public function testIbanNotSupported()
  76. {
  77. $validator = new Zend_Validate_Iban('en_US');
  78. $this->assertFalse($validator->isValid('AT611904300234573201'));
  79. }
  80. }