Files
kupshop/bundles/KupShop/BankAutoPaymentBundle/Tests/BankAutoPaymentTest.php
2025-08-02 16:30:27 +02:00

88 lines
2.7 KiB
PHP

<?php
namespace KupShop\BankAutoPaymentBundle\Tests;
use KupShop\BankAutoPaymentBundle\PaymentSources\FioBankApi;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
class BankAutoPaymentTest extends \DatabaseTestCase
{
protected FioBankApi $fio;
protected function setUp(): void
{
parent::setUp();
$this->fio = ServiceContainer::getService(FioBankApi::class);
}
/**
* @dataProvider data_testFindPaymentOrder
*/
public function testFindPaymentOrder($vs, $ref, $note, $id_order_expected)
{
$transaction = json_decode('{
"column1": {
"value": "100"
},
"column8": {
"value": "Bezhotovostní příjem"
},
"column14": {
"value": "CZK"
},
"column5": {
"value": ""
},
"column22": {
"value": "23453"
},
"column25": {
"value": ""
},
"column27": {
"value": ""
}
}');
$transaction->column25->value = $note;
$transaction->column5->value = $vs;
$transaction->column27->value = $ref;
$vs = $transaction->column5->value ?? false;
if (!$vs) {
$orderIdentifiers = [
// Reference plátce
'ref' => $transaction->column27->value ?? false,
// Zpráva pro příjemce
'msg' => $transaction->column16->value ?? false,
// Poznámka
'note' => $transaction->column25->value ?? false,
];
} else {
$orderIdentifiers = ['vs' => $vs];
}
$orderIdentifiers = array_map(function ($x) {return ltrim(trim($x), '0'); }, $orderIdentifiers);
$orderIdentifiers = array_filter($orderIdentifiers);
$id_order = $this->fio->findPaymentOrder($transaction->column22->value, $orderIdentifiers);
/* spravne pripsane body */
$this->assertEquals($id_order_expected, $id_order);
}
public function data_testFindPaymentOrder()
{
return [
['', '', 'ahoj karle', null],
['201300026', '', 'ahoj karle', 2],
['', '201300026', 'ahoj karle', 2],
['', '0201300026', 'ahoj karle', 2],
['', '', 'ahoj karle1234001 platim ti objednavku vs:201300026', 2],
['', '', 'ahoj karle, platim ti objednavku vs201300026', 2],
['', '', 'ahoj karle, platim ti objednavku 201300026', 2],
['', '', 'VS201300026', 2],
['', '', 'VS:201300026', 2],
['', '', 'VS:201300026 zaplaceno', 2],
['', '', 'VS:201300026 00028', 2],
];
}
}