Steuerkram/tests/39_BankFetchRangeTest.php

54 lines
2.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
use Steuerkram\Models\BankSource;
/**
* Test 39: BankSource::computeStartDate – "Abrufen ab"-Auswahl im Direktverbindungs-Dialog.
*/
class BankFetchRangeTest extends TestCase
{
protected string $testName = 'Test 39: BankSource::computeStartDate – Start-Datum aus fetch_range';
public function run(): void
{
// Fester Bezugstag, damit der Test reproduzierbar bleibt.
$today = new \DateTimeImmutable('2026-05-22');
// 1. last_fetched mit vorhandenem Zeitstempel → Tag des letzten Abrufs 00:00 Uhr
[$start, $label] = BankSource::computeStartDate('last_fetched', '2026-05-15 13:42:01', $today);
$this->assertEquals('2026-05-15', $start->format('Y-m-d'), 'last_fetched nutzt Datum des letzten Abrufs');
$this->assert(str_contains($label, '15.05.2026'), 'Label enthält Datum des letzten Abrufs');
// 2. last_fetched ohne vorherigen Abruf → Fallback 365 Tage
[$start] = BankSource::computeStartDate('last_fetched', null, $today);
$this->assertEquals('2025-05-22', $start->format('Y-m-d'), 'Ohne last_fetched: 365 Tage zurück');
// 3. last_week → 7 Tage zurück
[$start, $label] = BankSource::computeStartDate('last_week', '2026-05-20 00:00:00', $today);
$this->assertEquals('2026-05-15', $start->format('Y-m-d'), 'last_week = today - 7d');
$this->assert(str_contains($label, '7 Tage'), 'Label nennt 7 Tage');
// 4. current_month → 01. des aktuellen Monats
[$start] = BankSource::computeStartDate('current_month', null, $today);
$this->assertEquals('2026-05-01', $start->format('Y-m-d'), 'current_month = erster Tag des Monats');
// 5. last_30_days → 30 Tage zurück
[$start] = BankSource::computeStartDate('last_30_days', null, $today);
$this->assertEquals('2026-04-22', $start->format('Y-m-d'), 'last_30_days = today - 30d');
// 6. full → 365 Tage zurück (überschreibt last_fetched_at)
[$start, $label] = BankSource::computeStartDate('full', '2026-05-20 00:00:00', $today);
$this->assertEquals('2025-05-22', $start->format('Y-m-d'), 'full ignoriert last_fetched');
$this->assert(str_contains($label, '365'), 'Label nennt 365 Tage');
// 7. Unbekannter Wert fällt auf last_fetched zurück (Validierung im Modell selbst)
[$start] = BankSource::computeStartDate('quark', '2026-05-10 00:00:00', $today);
$this->assertEquals('2026-05-10', $start->format('Y-m-d'), 'Unbekanntes Range → last_fetched');
// 8. null Range → last_fetched
[$start] = BankSource::computeStartDate(null, '2026-05-10 00:00:00', $today);
$this->assertEquals('2026-05-10', $start->format('Y-m-d'), 'null Range → last_fetched');
}
}