IbanTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /**
  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-2009 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_IbanTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * Ensures that the validator follows expected behavior
  42. *
  43. * @return void
  44. */
  45. public function testBasic()
  46. {
  47. $validator = new Zend_Validate_Iban();
  48. $valuesExpected = array(
  49. 'AD1200012030200359100100' => true,
  50. 'AT611904300234573201' => true,
  51. 'AT61 1904 3002 3457 3201' => false,
  52. 'AD1200012030200354100100' => false,
  53. );
  54. foreach ($valuesExpected as $input => $result) {
  55. $this->assertEquals($result, $validator->isValid($input),
  56. "'$input' expected to be " . ($result ? '' : 'in') . 'valid');
  57. }
  58. }
  59. public function testSettingAndGettingLocale()
  60. {
  61. $validator = new Zend_Validate_Iban();
  62. try {
  63. $validator->setLocale('de_QA');
  64. $this->fail();
  65. } catch (Zend_Validate_Exception $e) {
  66. $this->assertContains('IBAN validation', $e->getMessage());
  67. }
  68. $validator->setLocale('de_DE');
  69. $this->assertEquals('de_DE', $validator->getLocale());
  70. }
  71. public function testInstanceWithLocale()
  72. {
  73. $validator = new Zend_Validate_Iban('de_AT');
  74. $this->assertTrue($validator->isValid('AT611904300234573201'));
  75. }
  76. public function testIbanNotSupported()
  77. {
  78. $validator = new Zend_Validate_Iban('en_US');
  79. $this->assertFalse($validator->isValid('AT611904300234573201'));
  80. }
  81. }