diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 420c21abf65..cc8f6c43709 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1627,7 +1627,9 @@ class Account extends CommonObject $error++; $this->error = 'IBANNotValid'; } - if (!checkSwiftForAccount($this) or !(empty($this->bic) && getDolGlobalInt('WITHDRAWAL_WITHOUT_BIC'))) { + // Call function to check Swift/BIC. + // A non valid BIC/Swift is a problem if: it is not empty or always a problem if WITHDRAWAL_WITHOUT_BIC is not set). + if (!checkSwiftForAccount($this) && (!empty($this->bic) || !getDolGlobalInt('WITHDRAWAL_WITHOUT_BIC'))) { $error++; $this->error = 'SwiftNotValid'; } diff --git a/test/phpunit/BankAccountTest.php b/test/phpunit/BankAccountTest.php index dfa85590a37..86192311459 100644 --- a/test/phpunit/BankAccountTest.php +++ b/test/phpunit/BankAccountTest.php @@ -142,6 +142,39 @@ class BankAccountTest extends CommonClassTest print __METHOD__." checkIbanForAccount(".$localobject2->iban.") = ".$result."\n"; $this->assertTrue($result); + return $localobject; + } + + /** + * testCheckSwiftForAccount + * + * @param Account $localobject Account + * @return int + * + * @depends testBankAccountOther + * The depends says test is run only if previous is ok + */ + public function testCheckSwiftForAccount($localobject) + { + global $conf,$user,$langs,$db; + $conf = $this->savconf; + $user = $this->savuser; + $langs = $this->savlangs; + $db = $this->savdb; + + $localobject->bic = 'PSSTFRPPMARBIDON'; + + $result = checkSwiftForAccount($localobject); + print __METHOD__." checkSwiftForAccount ".$localobject->bic." = ".$result."\n"; + $this->assertFalse($result); + + + $localobject->bic = 'PSSTFRPPMAR'; + + $result = checkSwiftForAccount($localobject); + print __METHOD__." checkSwiftForAccount ".$localobject->bic." = ".$result."\n"; + $this->assertTrue($result); + return $localobject->id; } @@ -151,7 +184,7 @@ class BankAccountTest extends CommonClassTest * @param int $id Id of contract * @return int * - * @depends testBankAccountOther + * @depends testCheckSwiftForAccount * The depends says test is run only if previous is ok */ public function testBankAccountDelete($id)