IbanTest.php 2.7 KB

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