52 lines
2.0 KiB
PHP
52 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require __DIR__.'/../public/perspektivwerk/booking/backend.php';
|
|
|
|
function expectSame(string $expected, string $actual, string $message): void
|
|
{
|
|
if ($expected !== $actual) {
|
|
throw new RuntimeException($message."\nExpected: $expected\nActual: $actual");
|
|
}
|
|
}
|
|
|
|
function expectContains(string $needle, string $haystack, string $message): void
|
|
{
|
|
if (!str_contains($haystack, $needle)) throw new RuntimeException($message);
|
|
}
|
|
|
|
$configFile = tempnam(sys_get_temp_dir(), 'sufw-booking-config-');
|
|
if ($configFile === false) throw new RuntimeException('Temporary configuration file could not be created.');
|
|
|
|
try {
|
|
file_put_contents($configFile, "<?php\nreturn ['database_url' => 'mysql://fallback:secret@database:3306/booking'];\n");
|
|
|
|
expectSame(
|
|
'mysql://fallback:secret@database:3306/booking',
|
|
bookingDatabaseUrl('', $configFile),
|
|
'The configuration file must be used when DATABASE_URL is empty.'
|
|
);
|
|
expectSame(
|
|
'mysql://environment:secret@database:3306/booking',
|
|
bookingDatabaseUrl('mysql://environment:secret@database:3306/booking', $configFile),
|
|
'DATABASE_URL must take precedence over the configuration file.'
|
|
);
|
|
expectSame('disabled', bookingMailTransport('disabled'), 'Local mail delivery must be explicitly disabled.');
|
|
|
|
$calendar = bookingIcsCalendar([
|
|
'id' => '44c5d0f9-6c98-4b04-8d25-c32834d21a61',
|
|
'project' => 'perspektivwerk',
|
|
'title' => 'Erstgespräch PerspektivWerk',
|
|
'starts_at' => '2026-09-14 09:00:00',
|
|
'ends_at' => '2026-09-14 10:00:00',
|
|
'format' => 'vor_ort',
|
|
]);
|
|
expectContains('BEGIN:VCALENDAR', $calendar, 'The confirmation attachment must be an iCalendar document.');
|
|
expectContains('UID:44c5d0f9-6c98-4b04-8d25-c32834d21a61@sufw-booking', $calendar, 'The iCalendar attachment must contain the event UID.');
|
|
} finally {
|
|
unlink($configFile);
|
|
}
|
|
|
|
echo "booking backend configuration tests passed\n";
|