Steuerkram/tests/44_CsvDirektverbindungTest.php

68 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
use Steuerkram\Models\BankSource;
/**
* Test 44: Neues CSV-Importformat über "Neue Direktverbindung"-Dialog (BankController::direktStore).
* Prüft die Default-Spaltenzuordnung und dass das Format provider_id=NULL hat
* und nicht in der Direktverbindungs-Liste (api/fints) auftaucht.
*/
class CsvDirektverbindungTest extends TestCase
{
protected string $testName = 'Test 44: CSV-Importformat aus Direktverbindungs-Dialog anlegen';
public function run(): void
{
// Entspricht BankController::direktStore() für provider_id === '__csv__'
// mit unveränderten Vorgabewerten aus dem Formular.
$id = BankSource::create([
'type' => 'csv',
'bezeichnung' => 'Test-CSV-Bank',
'kuerzel' => 'TCB',
'farbe' => '#6366f1',
'skip_rows' => 0,
'has_header_row' => 1,
'delimiter' => ';',
'enclosure' => '"',
'date_format' => 'd.m.Y',
'decimal_separator' => ',',
'thousands_separator' => '.',
'col_buchungstag' => 0,
'col_wertstellung' => 1,
'col_vorgang' => 2,
'col_buchungstext' => 0,
'col_wert' => 4,
]);
$this->assertGreaterThan(0, $id, 'CSV-Format wurde angelegt');
$format = BankSource::find($id);
$this->assertNotEmpty($format, 'CSV-Format abrufbar');
$this->assertEquals('csv', $format['type'], 'Typ ist csv');
$this->assertEquals('TCB', $format['kuerzel'], 'Kürzel korrekt gespeichert');
$this->assert($format['provider_id'] === null, 'provider_id ist NULL (kein Bank-Anbieter)');
$this->assertEquals(0, (int)$format['col_buchungstag'], 'Spalte Buchungstag = 0');
$this->assertEquals(1, (int)$format['col_wertstellung'], 'Spalte Wertstellung = 1');
$this->assertEquals(2, (int)$format['col_vorgang'], 'Spalte Vorgang = 2');
$this->assertEquals(4, (int)$format['col_wert'], 'Spalte Betrag = 4');
$this->assertEquals('d.m.Y', $format['date_format'], 'Datumsformat-Default');
// Format erscheint in der CSV-Formatliste …
$csvFormats = BankSource::all('csv');
$this->assert(
in_array($id, array_map(fn($f) => (int)$f['id'], $csvFormats), true),
'CSV-Format erscheint in BankSource::all(csv)'
);
// … aber nicht in der Direktverbindungs-Liste (BankController::direkt()).
$connections = array_values(array_filter(
BankSource::all(),
fn($s) => in_array($s['type'], ['api', 'fints'], true)
));
$this->assert(
!in_array($id, array_map(fn($c) => (int)$c['id'], $connections), true),
'CSV-Format erscheint nicht in der Direktverbindungs-Liste'
);
}
}