<?php

declare(strict_types=1);

require_once dirname(__DIR__, 2) . '/feca_mailshots_plugin/src/autoload.php';

use FecaMailshots\Admin\DownloadPdfAdminPage;

$page = (new ReflectionClass(DownloadPdfAdminPage::class))->newInstanceWithoutConstructor();
$method = new ReflectionMethod(DownloadPdfAdminPage::class, 'safeDownloadBaseName');
$method->setAccessible(true);

$cases = [
    'Renewals (pending accounts and contacts)' => 'Renewals_pending_accounts_and_contacts',
    'Invoice run: May/June 2026' => 'Invoice_run_May_June_2026',
    '  ...  ' => 'mailshot',
    'Quotes " and spaces' => 'Quotes_and_spaces',
];

foreach ($cases as $input => $expected) {
    $actual = $method->invoke($page, $input);
    if ($actual !== $expected) {
        fwrite(STDERR, sprintf("Expected %s => %s, got %s\n", $input, $expected, (string) $actual));
        exit(1);
    }
}

echo "Download PDF filename regression test passed\n";
