View source
<?php
namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Component\Validator\Constraints\Iban;
use Symfony\Component\Validator\Constraints\IbanValidator;
use Symfony\Component\Validator\Validation;
class IbanValidatorTest extends AbstractConstraintValidatorTest {
protected function getApiVersion() {
return Validation::API_VERSION_2_5;
}
protected function createValidator() {
return new IbanValidator();
}
public function testNullIsValid() {
$this->validator
->validate(null, new Iban());
$this
->assertNoViolation();
}
public function testEmptyStringIsValid() {
$this->validator
->validate('', new Iban());
$this
->assertNoViolation();
}
public function testValidIbans($iban) {
$this->validator
->validate($iban, new Iban());
$this
->assertNoViolation();
}
public function getValidIbans() {
return array(
array(
'CH9300762011623852957',
),
array(
'CH93 0076 2011 6238 5295 7',
),
array(
'AL47 2121 1009 0000 0002 3569 8741',
),
array(
'AD12 0001 2030 2003 5910 0100',
),
array(
'AT61 1904 3002 3457 3201',
),
array(
'AZ21 NABZ 0000 0000 1370 1000 1944',
),
array(
'BH67 BMAG 0000 1299 1234 56',
),
array(
'BE62 5100 0754 7061',
),
array(
'BA39 1290 0794 0102 8494',
),
array(
'BG80 BNBG 9661 1020 3456 78',
),
array(
'HR12 1001 0051 8630 0016 0',
),
array(
'CY17 0020 0128 0000 0012 0052 7600',
),
array(
'CZ65 0800 0000 1920 0014 5399',
),
array(
'DK50 0040 0440 1162 43',
),
array(
'EE38 2200 2210 2014 5685',
),
array(
'FO97 5432 0388 8999 44',
),
array(
'FI21 1234 5600 0007 85',
),
array(
'FR14 2004 1010 0505 0001 3M02 606',
),
array(
'GE29 NB00 0000 0101 9049 17',
),
array(
'DE89 3704 0044 0532 0130 00',
),
array(
'GI75 NWBK 0000 0000 7099 453',
),
array(
'GR16 0110 1250 0000 0001 2300 695',
),
array(
'GL56 0444 9876 5432 10',
),
array(
'HU42 1177 3016 1111 1018 0000 0000',
),
array(
'IS14 0159 2600 7654 5510 7303 39',
),
array(
'IE29 AIBK 9311 5212 3456 78',
),
array(
'IL62 0108 0000 0009 9999 999',
),
array(
'IT40 S054 2811 1010 0000 0123 456',
),
array(
'LV80 BANK 0000 4351 9500 1',
),
array(
'LB62 0999 0000 0001 0019 0122 9114',
),
array(
'LI21 0881 0000 2324 013A A',
),
array(
'LT12 1000 0111 0100 1000',
),
array(
'LU28 0019 4006 4475 0000',
),
array(
'MK072 5012 0000 0589 84',
),
array(
'MT84 MALT 0110 0001 2345 MTLC AST0 01S',
),
array(
'MU17 BOMM 0101 1010 3030 0200 000M UR',
),
array(
'MD24 AG00 0225 1000 1310 4168',
),
array(
'MC93 2005 2222 1001 1223 3M44 555',
),
array(
'ME25 5050 0001 2345 6789 51',
),
array(
'NL39 RABO 0300 0652 64',
),
array(
'NO93 8601 1117 947',
),
array(
'PK36 SCBL 0000 0011 2345 6702',
),
array(
'PL60 1020 1026 0000 0422 7020 1111',
),
array(
'PT50 0002 0123 1234 5678 9015 4',
),
array(
'RO49 AAAA 1B31 0075 9384 0000',
),
array(
'SM86 U032 2509 8000 0000 0270 100',
),
array(
'SA03 8000 0000 6080 1016 7519',
),
array(
'RS35 2600 0560 1001 6113 79',
),
array(
'SK31 1200 0000 1987 4263 7541',
),
array(
'SI56 1910 0000 0123 438',
),
array(
'ES80 2310 0001 1800 0001 2345',
),
array(
'SE35 5000 0000 0549 1000 0003',
),
array(
'CH93 0076 2011 6238 5295 7',
),
array(
'TN59 1000 6035 1835 9847 8831',
),
array(
'TR33 0006 1005 1978 6457 8413 26',
),
array(
'AE07 0331 2345 6789 0123 456',
),
array(
'GB12 CPBK 0892 9965 0449 91',
),
array(
'AO06000600000100037131174',
),
array(
'AZ21NABZ00000000137010001944',
),
array(
'BH29BMAG1299123456BH00',
),
array(
'BJ11B00610100400271101192591',
),
array(
'BR9700360305000010009795493P1',
),
array(
'BR1800000000141455123924100C2',
),
array(
'VG96VPVG0000012345678901',
),
array(
'BF1030134020015400945000643',
),
array(
'BI43201011067444',
),
array(
'CM2110003001000500000605306',
),
array(
'CV64000300004547069110176',
),
array(
'FR7630007000110009970004942',
),
array(
'CG5230011000202151234567890',
),
array(
'CR0515202001026284066',
),
array(
'DO28BAGR00000001212453611324',
),
array(
'GT82TRAJ01020000001210029690',
),
array(
'IR580540105180021273113007',
),
array(
'IL620108000000099999999',
),
array(
'CI05A00060174100178530011852',
),
array(
'JO94CBJO0010000000000131000302',
),
array(
'KZ176010251000042993',
),
array(
'KW74NBOK0000000000001000372151',
),
array(
'LB30099900000001001925579115',
),
array(
'MG4600005030010101914016056',
),
array(
'ML03D00890170001002120000447',
),
array(
'MR1300012000010000002037372',
),
array(
'MU17BOMM0101101030300200000MUR',
),
array(
'MZ59000100000011834194157',
),
array(
'PS92PALS000000000400123456702',
),
array(
'QA58DOHB00001234567890ABCDEFG',
),
array(
'XK051212012345678906',
),
array(
'PT50000200000163099310355',
),
array(
'SA0380000000608010167519',
),
array(
'SN12K00100152000025690007542',
),
array(
'TL380080012345678910157',
),
array(
'TN5914207207100707129648',
),
array(
'TR330006100519786457841326',
),
array(
'AE260211000000230064016',
),
);
}
public function testIbansWithInvalidFormat($iban) {
$this
->assertViolationRaised($iban, Iban::INVALID_FORMAT_ERROR);
}
public function getIbansWithInvalidFormat() {
return array(
array(
'AL47 2121 1009 0000 0002 3569 874',
),
array(
'AD12 0001 2030 2003 5910 010',
),
array(
'AT61 1904 3002 3457 320',
),
array(
'AZ21 NABZ 0000 0000 1370 1000 194',
),
array(
'AZ21 N1BZ 0000 0000 1370 1000 1944',
),
array(
'BH67 BMAG 0000 1299 1234 5',
),
array(
'BH67 B2AG 0000 1299 1234 56',
),
array(
'BE62 5100 0754 7061 2',
),
array(
'BA39 1290 0794 0102 8494 4',
),
array(
'BG80 BNBG 9661 1020 3456 7',
),
array(
'BG80 B2BG 9661 1020 3456 78',
),
array(
'HR12 1001 0051 8630 0016 01',
),
array(
'CY17 0020 0128 0000 0012 0052 7600 1',
),
array(
'CZ65 0800 0000 1920 0014 5399 1',
),
array(
'DK50 0040 0440 1162 431',
),
array(
'EE38 2200 2210 2014 5685 1',
),
array(
'FO97 5432 0388 8999 441',
),
array(
'FI21 1234 5600 0007 851',
),
array(
'FR14 2004 1010 0505 0001 3M02 6061',
),
array(
'GE29 NB00 0000 0101 9049 171',
),
array(
'DE89 3704 0044 0532 0130 001',
),
array(
'GI75 NWBK 0000 0000 7099 4531',
),
array(
'GR16 0110 1250 0000 0001 2300 6951',
),
array(
'GL56 0444 9876 5432 101',
),
array(
'HU42 1177 3016 1111 1018 0000 0000 1',
),
array(
'IS14 0159 2600 7654 5510 7303 391',
),
array(
'IE29 AIBK 9311 5212 3456 781',
),
array(
'IL62 0108 0000 0009 9999 9991',
),
array(
'IT40 S054 2811 1010 0000 0123 4561',
),
array(
'LV80 BANK 0000 4351 9500 11',
),
array(
'LB62 0999 0000 0001 0019 0122 9114 1',
),
array(
'LI21 0881 0000 2324 013A A1',
),
array(
'LT12 1000 0111 0100 1000 1',
),
array(
'LU28 0019 4006 4475 0000 1',
),
array(
'MK072 5012 0000 0589 84 1',
),
array(
'MT84 MALT 0110 0001 2345 MTLC AST0 01SA',
),
array(
'MU17 BOMM 0101 1010 3030 0200 000M URA',
),
array(
'MD24 AG00 0225 1000 1310 4168 1',
),
array(
'MC93 2005 2222 1001 1223 3M44 5551',
),
array(
'ME25 5050 0001 2345 6789 511',
),
array(
'NL39 RABO 0300 0652 641',
),
array(
'NO93 8601 1117 9471',
),
array(
'PK36 SCBL 0000 0011 2345 6702 1',
),
array(
'PL60 1020 1026 0000 0422 7020 1111 1',
),
array(
'PT50 0002 0123 1234 5678 9015 41',
),
array(
'RO49 AAAA 1B31 0075 9384 0000 1',
),
array(
'SM86 U032 2509 8000 0000 0270 1001',
),
array(
'SA03 8000 0000 6080 1016 7519 1',
),
array(
'RS35 2600 0560 1001 6113 791',
),
array(
'SK31 1200 0000 1987 4263 7541 1',
),
array(
'SI56 1910 0000 0123 4381',
),
array(
'ES80 2310 0001 1800 0001 2345 1',
),
array(
'SE35 5000 0000 0549 1000 0003 1',
),
array(
'CH93 0076 2011 6238 5295 71',
),
array(
'TN59 1000 6035 1835 9847 8831 1',
),
array(
'TR33 0006 1005 1978 6457 8413 261',
),
array(
'AE07 0331 2345 6789 0123 4561',
),
array(
'GB12 CPBK 0892 9965 0449 911',
),
array(
'AO060006000001000371311741',
),
array(
'AZ21NABZ000000001370100019441',
),
array(
'BH29BMAG1299123456BH001',
),
array(
'BJ11B006101004002711011925911',
),
array(
'BR9700360305000010009795493P11',
),
array(
'BR1800000000141455123924100C21',
),
array(
'VG96VPVG00000123456789011',
),
array(
'BF10301340200154009450006431',
),
array(
'BI432010110674441',
),
array(
'CM21100030010005000006053061',
),
array(
'CV640003000045470691101761',
),
array(
'FR76300070001100099700049421',
),
array(
'CG52300110002021512345678901',
),
array(
'CR05152020010262840661',
),
array(
'DO28BAGR000000012124536113241',
),
array(
'GT82TRAJ010200000012100296901',
),
array(
'IR5805401051800212731130071',
),
array(
'IL6201080000000999999991',
),
array(
'CI05A000601741001785300118521',
),
array(
'JO94CBJO00100000000001310003021',
),
array(
'KZ1760102510000429931',
),
array(
'KW74NBOK00000000000010003721511',
),
array(
'LB300999000000010019255791151',
),
array(
'MG46000050300101019140160561',
),
array(
'ML03D008901700010021200004471',
),
array(
'MR13000120000100000020373721',
),
array(
'MU17BOMM0101101030300200000MUR1',
),
array(
'MZ590001000000118341941571',
),
array(
'PS92PALS0000000004001234567021',
),
array(
'QA58DOHB00001234567890ABCDEFG1',
),
array(
'XK0512120123456789061',
),
array(
'PT500002000001630993103551',
),
array(
'SA03800000006080101675191',
),
array(
'SN12K001001520000256900075421',
),
array(
'TL3800800123456789101571',
),
array(
'TN59142072071007071296481',
),
array(
'TR3300061005197864578413261',
),
array(
'AE2602110000002300640161',
),
);
}
public function testIbansWithValidFormatButIncorrectChecksum($iban) {
$this
->assertViolationRaised($iban, Iban::CHECKSUM_FAILED_ERROR);
}
public function getIbansWithValidFormatButIncorrectChecksum() {
return array(
array(
'AL47 2121 1009 0000 0002 3569 8742',
),
array(
'AD12 0001 2030 2003 5910 0101',
),
array(
'AT61 1904 3002 3457 3202',
),
array(
'AZ21 NABZ 0000 0000 1370 1000 1945',
),
array(
'BH67 BMAG 0000 1299 1234 57',
),
array(
'BE62 5100 0754 7062',
),
array(
'BA39 1290 0794 0102 8495',
),
array(
'BG80 BNBG 9661 1020 3456 79',
),
array(
'HR12 1001 0051 8630 0016 1',
),
array(
'CY17 0020 0128 0000 0012 0052 7601',
),
array(
'CZ65 0800 0000 1920 0014 5398',
),
array(
'DK50 0040 0440 1162 44',
),
array(
'EE38 2200 2210 2014 5684',
),
array(
'FO97 5432 0388 8999 43',
),
array(
'FI21 1234 5600 0007 84',
),
array(
'FR14 2004 1010 0505 0001 3M02 605',
),
array(
'GE29 NB00 0000 0101 9049 16',
),
array(
'DE89 3704 0044 0532 0130 01',
),
array(
'GI75 NWBK 0000 0000 7099 452',
),
array(
'GR16 0110 1250 0000 0001 2300 694',
),
array(
'GL56 0444 9876 5432 11',
),
array(
'HU42 1177 3016 1111 1018 0000 0001',
),
array(
'IS14 0159 2600 7654 5510 7303 38',
),
array(
'IE29 AIBK 9311 5212 3456 79',
),
array(
'IL62 0108 0000 0009 9999 998',
),
array(
'IT40 S054 2811 1010 0000 0123 457',
),
array(
'LV80 BANK 0000 4351 9500 2',
),
array(
'LB62 0999 0000 0001 0019 0122 9115',
),
array(
'LI21 0881 0000 2324 013A B',
),
array(
'LT12 1000 0111 0100 1001',
),
array(
'LU28 0019 4006 4475 0001',
),
array(
'MK072 5012 0000 0589 85',
),
array(
'MT84 MALT 0110 0001 2345 MTLC AST0 01T',
),
array(
'MU17 BOMM 0101 1010 3030 0200 000M UP',
),
array(
'MD24 AG00 0225 1000 1310 4169',
),
array(
'MC93 2005 2222 1001 1223 3M44 554',
),
array(
'ME25 5050 0001 2345 6789 52',
),
array(
'NL39 RABO 0300 0652 65',
),
array(
'NO93 8601 1117 948',
),
array(
'PK36 SCBL 0000 0011 2345 6703',
),
array(
'PL60 1020 1026 0000 0422 7020 1112',
),
array(
'PT50 0002 0123 1234 5678 9015 5',
),
array(
'RO49 AAAA 1B31 0075 9384 0001',
),
array(
'SM86 U032 2509 8000 0000 0270 101',
),
array(
'SA03 8000 0000 6080 1016 7518',
),
array(
'RS35 2600 0560 1001 6113 78',
),
array(
'SK31 1200 0000 1987 4263 7542',
),
array(
'SI56 1910 0000 0123 439',
),
array(
'ES80 2310 0001 1800 0001 2346',
),
array(
'SE35 5000 0000 0549 1000 0004',
),
array(
'CH93 0076 2011 6238 5295 8',
),
array(
'TN59 1000 6035 1835 9847 8832',
),
array(
'TR33 0006 1005 1978 6457 8413 27',
),
array(
'AE07 0331 2345 6789 0123 457',
),
array(
'GB12 CPBK 0892 9965 0449 92',
),
array(
'AO06000600000100037131175',
),
array(
'AZ21NABZ00000000137010001945',
),
array(
'BH29BMAG1299123456BH01',
),
array(
'BJ11B00610100400271101192592',
),
array(
'BR9700360305000010009795493P2',
),
array(
'BR1800000000141455123924100C3',
),
array(
'VG96VPVG0000012345678902',
),
array(
'BF1030134020015400945000644',
),
array(
'BI43201011067445',
),
array(
'CM2110003001000500000605307',
),
array(
'CV64000300004547069110177',
),
array(
'FR7630007000110009970004943',
),
array(
'CG5230011000202151234567891',
),
array(
'CR0515202001026284067',
),
array(
'DO28BAGR00000001212453611325',
),
array(
'GT82TRAJ01020000001210029691',
),
array(
'IR580540105180021273113008',
),
array(
'IL620108000000099999998',
),
array(
'CI05A00060174100178530011853',
),
array(
'JO94CBJO0010000000000131000303',
),
array(
'KZ176010251000042994',
),
array(
'KW74NBOK0000000000001000372152',
),
array(
'LB30099900000001001925579116',
),
array(
'MG4600005030010101914016057',
),
array(
'ML03D00890170001002120000448',
),
array(
'MR1300012000010000002037373',
),
array(
'MU17BOMM0101101030300200000MUP',
),
array(
'MZ59000100000011834194158',
),
array(
'PS92PALS000000000400123456703',
),
array(
'QA58DOHB00001234567890ABCDEFH',
),
array(
'XK051212012345678907',
),
array(
'PT50000200000163099310356',
),
array(
'SA0380000000608010167518',
),
array(
'SN12K00100152000025690007543',
),
array(
'TL380080012345678910158',
),
array(
'TN5914207207100707129649',
),
array(
'TR330006100519786457841327',
),
array(
'AE260211000000230064017',
),
);
}
public function testIbansWithUnsupportedCountryCode($countryCode) {
$this
->assertViolationRaised($countryCode . '260211000000230064016', Iban::NOT_SUPPORTED_COUNTRY_CODE_ERROR);
}
public function getUnsupportedCountryCodes() {
return array(
array(
'AG',
),
array(
'AI',
),
array(
'AQ',
),
array(
'AS',
),
array(
'AW',
),
);
}
public function testIbansWithInvalidCharacters() {
$this
->assertViolationRaised('CH930076201162385295]', Iban::INVALID_CHARACTERS_ERROR);
}
public function testIbansWithInvalidCountryCode($iban) {
$this
->assertViolationRaised($iban, Iban::INVALID_COUNTRY_CODE_ERROR);
}
public function getIbansWithInvalidCountryCode() {
return array(
array(
'0750447346',
),
array(
'2X0750447346',
),
array(
'A20750447346',
),
);
}
private function assertViolationRaised($iban, $code) {
$constraint = new Iban(array(
'message' => 'myMessage',
));
$this->validator
->validate($iban, $constraint);
$this
->buildViolation('myMessage')
->setParameter('{{ value }}', '"' . $iban . '"')
->setCode($code)
->assertRaised();
}
}