BicValidatorTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Tests\Constraints;
  11. use Symfony\Component\Validator\Constraints\Bic;
  12. use Symfony\Component\Validator\Constraints\BicValidator;
  13. class BicValidatorTest extends AbstractConstraintValidatorTest
  14. {
  15. protected function createValidator()
  16. {
  17. return new BicValidator();
  18. }
  19. public function testNullIsValid()
  20. {
  21. $this->validator->validate(null, new Bic());
  22. $this->assertNoViolation();
  23. }
  24. public function testEmptyStringIsValid()
  25. {
  26. $this->validator->validate('', new Bic());
  27. $this->assertNoViolation();
  28. }
  29. /**
  30. * @dataProvider getValidBics
  31. */
  32. public function testValidBics($bic)
  33. {
  34. $this->validator->validate($bic, new Bic());
  35. $this->assertNoViolation();
  36. }
  37. public function getValidBics()
  38. {
  39. // http://formvalidation.io/validators/bic/
  40. return array(
  41. array('ASPKAT2LXXX'),
  42. array('ASPKAT2L'),
  43. array('DSBACNBXSHA'),
  44. array('UNCRIT2B912'),
  45. array('DABADKKK'),
  46. array('RZOOAT2L303'),
  47. );
  48. }
  49. /**
  50. * @dataProvider getInvalidBics
  51. */
  52. public function testInvalidBics($bic, $code)
  53. {
  54. $constraint = new Bic(array(
  55. 'message' => 'myMessage',
  56. ));
  57. $this->validator->validate($bic, $constraint);
  58. $this->buildViolation('myMessage')
  59. ->setParameter('{{ value }}', '"'.$bic.'"')
  60. ->setCode($code)
  61. ->assertRaised();
  62. }
  63. public function getInvalidBics()
  64. {
  65. return array(
  66. array('DEUTD', Bic::INVALID_LENGTH_ERROR),
  67. array('ASPKAT2LXX', Bic::INVALID_LENGTH_ERROR),
  68. array('ASPKAT2LX', Bic::INVALID_LENGTH_ERROR),
  69. array('ASPKAT2LXXX1', Bic::INVALID_LENGTH_ERROR),
  70. array('DABADKK', Bic::INVALID_LENGTH_ERROR),
  71. array('1SBACNBXSHA', Bic::INVALID_BANK_CODE_ERROR),
  72. array('RZ00AT2L303', Bic::INVALID_BANK_CODE_ERROR),
  73. array('D2BACNBXSHA', Bic::INVALID_BANK_CODE_ERROR),
  74. array('DS3ACNBXSHA', Bic::INVALID_BANK_CODE_ERROR),
  75. array('DSB4CNBXSHA', Bic::INVALID_BANK_CODE_ERROR),
  76. array('DEUT12HH', Bic::INVALID_COUNTRY_CODE_ERROR),
  77. array('DSBAC6BXSHA', Bic::INVALID_COUNTRY_CODE_ERROR),
  78. array('DSBA5NBXSHA', Bic::INVALID_COUNTRY_CODE_ERROR),
  79. // branch code error
  80. array('THISSVAL1D]', Bic::INVALID_CHARACTERS_ERROR),
  81. // location code error
  82. array('DEUTDEF]', Bic::INVALID_CHARACTERS_ERROR),
  83. // lower case values are invalid
  84. array('DeutAT2LXXX', Bic::INVALID_CASE_ERROR),
  85. array('DEUTAT2lxxx', Bic::INVALID_CASE_ERROR),
  86. );
  87. }
  88. }