IbanTest.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. namespace Faker\Test\Calculator;
  3. use Faker\Calculator\Iban;
  4. class IbanTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function checksumProvider()
  7. {
  8. return array(
  9. array('AL47212110090000000235698741', '47'),
  10. array('AD1200012030200359100100', '12'),
  11. array('AT611904300234573201', '61'),
  12. array('AZ21NABZ00000000137010001944', '21'),
  13. array('BH67BMAG00001299123456', '67'),
  14. array('BE68539007547034', '68'),
  15. array('BA391290079401028494', '39'),
  16. array('BR7724891749412660603618210F3', '77'),
  17. array('BG80BNBG96611020345678', '80'),
  18. array('CR0515202001026284066', '05'),
  19. array('HR1210010051863000160', '12'),
  20. array('CY17002001280000001200527600', '17'),
  21. array('CZ6508000000192000145399', '65'),
  22. array('DK5000400440116243', '50'),
  23. array('DO28BAGR00000001212453611324', '28'),
  24. array('EE382200221020145685', '38'),
  25. array('FO6264600001631634', '62'),
  26. array('FI2112345600000785', '21'),
  27. array('FR1420041010050500013M02606', '14'),
  28. array('GE29NB0000000101904917', '29'),
  29. array('DE89370400440532013000', '89'),
  30. array('GI75NWBK000000007099453', '75'),
  31. array('GR1601101250000000012300695', '16'),
  32. array('GL8964710001000206', '89'),
  33. array('GT82TRAJ01020000001210029690', '82'),
  34. array('HU42117730161111101800000000', '42'),
  35. array('IS140159260076545510730339', '14'),
  36. array('IE29AIBK93115212345678', '29'),
  37. array('IL620108000000099999999', '62'),
  38. array('IT60X0542811101000000123456', '60'),
  39. array('KZ86125KZT5004100100', '86'),
  40. array('KW81CBKU0000000000001234560101', '81'),
  41. array('LV80BANK0000435195001', '80'),
  42. array('LB62099900000001001901229114', '62'),
  43. array('LI21088100002324013AA', '21'),
  44. array('LT121000011101001000', '12'),
  45. array('LU280019400644750000', '28'),
  46. array('MK07250120000058984', '07'),
  47. array('MT84MALT011000012345MTLCAST001S', '84'),
  48. array('MR1300020001010000123456753', '13'),
  49. array('MU17BOMM0101101030300200000MUR', '17'),
  50. array('MD24AG000225100013104168', '24'),
  51. array('MC5811222000010123456789030', '58'),
  52. array('ME25505000012345678951', '25'),
  53. array('NL91ABNA0417164300', '91'),
  54. array('NO9386011117947', '93'),
  55. array('PK36SCBL0000001123456702', '36'),
  56. array('PL61109010140000071219812874', '61'),
  57. array('PS92PALS000000000400123456702', '92'),
  58. array('PT50000201231234567890154', '50'),
  59. array('QA58DOHB00001234567890ABCDEFG', '58'),
  60. array('RO49AAAA1B31007593840000', '49'),
  61. array('SM86U0322509800000000270100', '86'),
  62. array('SA0380000000608010167519', '03'),
  63. array('RS35260005601001611379', '35'),
  64. array('SK3112000000198742637541', '31'),
  65. array('SI56263300012039086', '56'),
  66. array('ES9121000418450200051332', '91'),
  67. array('SE4550000000058398257466', '45'),
  68. array('CH9300762011623852957', '93'),
  69. array('TN5910006035183598478831', '59'),
  70. array('TR330006100519786457841326', '33'),
  71. array('AE070331234567890123456', '07'),
  72. array('GB29NWBK60161331926819', '29'),
  73. array('VG96VPVG0000012345678901', '96'),
  74. array('YY24KIHB12476423125915947930915268', '24'),
  75. array('ZZ25VLQT382332233206588011313776421', '25'),
  76. );
  77. }
  78. /**
  79. * @dataProvider checksumProvider
  80. */
  81. public function testChecksum($iban, $checksum)
  82. {
  83. $this->assertEquals($checksum, Iban::checksum($iban), $iban);
  84. }
  85. public function validatorProvider()
  86. {
  87. return array(
  88. array('AL47212110090000000235698741', true),
  89. array('AD1200012030200359100100', true),
  90. array('AT611904300234573201', true),
  91. array('AZ21NABZ00000000137010001944', true),
  92. array('BH67BMAG00001299123456', true),
  93. array('BE68539007547034', true),
  94. array('BA391290079401028494', true),
  95. array('BR7724891749412660603618210F3', true),
  96. array('BG80BNBG96611020345678', true),
  97. array('CR0515202001026284066', true),
  98. array('HR1210010051863000160', true),
  99. array('CY17002001280000001200527600', true),
  100. array('CZ6508000000192000145399', true),
  101. array('DK5000400440116243', true),
  102. array('DO28BAGR00000001212453611324', true),
  103. array('EE382200221020145685', true),
  104. array('FO6264600001631634', true),
  105. array('FI2112345600000785', true),
  106. array('FR1420041010050500013M02606', true),
  107. array('GE29NB0000000101904917', true),
  108. array('DE89370400440532013000', true),
  109. array('GI75NWBK000000007099453', true),
  110. array('GR1601101250000000012300695', true),
  111. array('GL8964710001000206', true),
  112. array('GT82TRAJ01020000001210029690', true),
  113. array('HU42117730161111101800000000', true),
  114. array('IS140159260076545510730339', true),
  115. array('IE29AIBK93115212345678', true),
  116. array('IL620108000000099999999', true),
  117. array('IT60X0542811101000000123456', true),
  118. array('KZ86125KZT5004100100', true),
  119. array('KW81CBKU0000000000001234560101', true),
  120. array('LV80BANK0000435195001', true),
  121. array('LB62099900000001001901229114', true),
  122. array('LI21088100002324013AA', true),
  123. array('LT121000011101001000', true),
  124. array('LU280019400644750000', true),
  125. array('MK07250120000058984', true),
  126. array('MT84MALT011000012345MTLCAST001S', true),
  127. array('MR1300020001010000123456753', true),
  128. array('MU17BOMM0101101030300200000MUR', true),
  129. array('MD24AG000225100013104168', true),
  130. array('MC5811222000010123456789030', true),
  131. array('ME25505000012345678951', true),
  132. array('NL91ABNA0417164300', true),
  133. array('NO9386011117947', true),
  134. array('PK36SCBL0000001123456702', true),
  135. array('PL61109010140000071219812874', true),
  136. array('PS92PALS000000000400123456702', true),
  137. array('PT50000201231234567890154', true),
  138. array('QA58DOHB00001234567890ABCDEFG', true),
  139. array('RO49AAAA1B31007593840000', true),
  140. array('SM86U0322509800000000270100', true),
  141. array('SA0380000000608010167519', true),
  142. array('RS35260005601001611379', true),
  143. array('SK3112000000198742637541', true),
  144. array('SI56263300012039086', true),
  145. array('ES9121000418450200051332', true),
  146. array('SE4550000000058398257466', true),
  147. array('CH9300762011623852957', true),
  148. array('TN5910006035183598478831', true),
  149. array('TR330006100519786457841326', true),
  150. array('AE070331234567890123456', true),
  151. array('GB29NWBK60161331926819', true),
  152. array('VG96VPVG0000012345678901', true),
  153. array('YY24KIHB12476423125915947930915268', true),
  154. array('ZZ25VLQT382332233206588011313776421', true),
  155. array('AL4721211009000000023569874', false),
  156. array('AD120001203020035910010', false),
  157. array('AT61190430023457320', false),
  158. array('AZ21NABZ0000000013701000194', false),
  159. array('BH67BMAG0000129912345', false),
  160. array('BE6853900754703', false),
  161. array('BA39129007940102849', false),
  162. array('BR7724891749412660603618210F', false),
  163. array('BG80BNBG9661102034567', false),
  164. array('CR051520200102628406', false),
  165. array('HR121001005186300016', false),
  166. array('CY1700200128000000120052760', false),
  167. array('CZ650800000019200014539', false),
  168. array('DK500040044011624', false),
  169. array('DO28BAGR0000000121245361132', false),
  170. array('EE38220022102014568', false),
  171. array('FO626460000163163', false),
  172. array('FI2112345600000780', false),
  173. array('FR1420041010050500013M0260', false),
  174. array('GE29NB000000010190491', false),
  175. array('DE8937040044053201300', false),
  176. array('GI75NWBK00000000709945', false),
  177. array('GR160110125000000001230069', false),
  178. array('GL896471000100020', false),
  179. array('GT82TRAJ0102000000121002969', false),
  180. array('HU4211773016111110180000000', false),
  181. array('IS14015926007654551073033', false),
  182. array('IE29AIBK9311521234567', false),
  183. array('IL62010800000009999999', false),
  184. array('IT60X054281110100000012345', false),
  185. array('KZ86125KZT500410010', false),
  186. array('KW81CBKU000000000000123456010', false),
  187. array('LV80BANK000043519500', false),
  188. array('LB6209990000000100190122911', false),
  189. array('LI21088100002324013A', false),
  190. array('LT12100001110100100', false),
  191. array('LU28001940064475000', false),
  192. array('MK0725012000005898', false),
  193. array('MT84MALT011000012345MTLCAST001', false),
  194. array('MR130002000101000012345675', false),
  195. array('MU17BOMM0101101030300200000MU', false),
  196. array('MD24AG00022510001310416', false),
  197. array('MC58112220000101234567890', false),
  198. array('ME2550500001234567895', false),
  199. array('NL91ABNA041716430', false),
  200. array('NO938601111794', false),
  201. array('PK36SCBL000000112345670', false),
  202. array('PL6110901014000007121981287', false),
  203. array('PS92PALS00000000040012345670', false),
  204. array('PT5000020123123456789015', false),
  205. array('QA58DOHB00001234567890ABCDEF', false),
  206. array('RO49AAAA1B3100759384000', false),
  207. array('SM86U032250980000000027010', false),
  208. array('SA038000000060801016751', false),
  209. array('RS3526000560100161137', false),
  210. array('SK311200000019874263754', false),
  211. array('SI5626330001203908', false),
  212. array('ES912100041845020005133', false),
  213. array('SE455000000005839825746', false),
  214. array('CH930076201162385295', false),
  215. array('TN591000603518359847883', false),
  216. array('TR33000610051978645784132', false),
  217. array('AE07033123456789012345', false),
  218. array('GB29NWBK6016133192681', false),
  219. array('VG96VPVG000001234567890', false),
  220. array('YY24KIHB1247642312591594793091526', false),
  221. array('ZZ25VLQT38233223320658801131377642', false),
  222. );
  223. }
  224. /**
  225. * @dataProvider validatorProvider
  226. */
  227. public function testIsValid($iban, $isValid)
  228. {
  229. $this->assertEquals($isValid, Iban::isValid($iban), $iban);
  230. }
  231. public function alphaToNumberProvider()
  232. {
  233. return array(
  234. array('A', 10),
  235. array('B', 11),
  236. array('C', 12),
  237. array('D', 13),
  238. array('E', 14),
  239. array('F', 15),
  240. array('G', 16),
  241. array('H', 17),
  242. array('I', 18),
  243. array('J', 19),
  244. array('K', 20),
  245. array('L', 21),
  246. array('M', 22),
  247. array('N', 23),
  248. array('O', 24),
  249. array('P', 25),
  250. array('Q', 26),
  251. array('R', 27),
  252. array('S', 28),
  253. array('T', 29),
  254. array('U', 30),
  255. array('V', 31),
  256. array('W', 32),
  257. array('X', 33),
  258. array('Y', 34),
  259. array('Z', 35),
  260. );
  261. }
  262. /**
  263. * @dataProvider alphaToNumberProvider
  264. */
  265. public function testAlphaToNumber($letter, $number)
  266. {
  267. $this->assertEquals($number, Iban::alphaToNumber($letter), $letter);
  268. }
  269. public function mod97Provider()
  270. {
  271. // Large numbers
  272. $return = array(
  273. array('123456789123456789', 7),
  274. array('111222333444555666', 73),
  275. array('4242424242424242424242', 19),
  276. array('271828182845904523536028', 68),
  277. );
  278. // 0-200
  279. for ($i = 0; $i < 200; $i++) {
  280. $return[] = array((string)$i, $i % 97);
  281. }
  282. return $return;
  283. }
  284. /**
  285. * @dataProvider mod97Provider
  286. */
  287. public function testMod97($number, $result)
  288. {
  289. $this->assertEquals($result, Iban::mod97($number), $number);
  290. }
  291. }