Files

34 lines
1.7 KiB
PHP

<?php
require_once __DIR__ . '/unraid-mcp-status-helper.php';
set_error_handler(function ($severity, $message) { throw new RuntimeException($message); });
function expect_same(string $label, mixed $expected, mixed $actual): void {
if ($expected !== $actual) throw new RuntimeException('FAIL: ' . $label);
echo "PASS: $label\n";
}
$record = <<<'NOTIFY'
timestamp=1789870052
event="URBM"
subject="✅ Backup (nightly)"
description="First line
📦 Repository: Test
Literal "quotes", semicolons; equals=signs
importance=alert
${PATH} ${HOME} null true OFF
✅ Status: Erfolgreich"
importance="normal"
NOTIFY;
$fields = notification_fields($record);
expect_same('timestamp stays literal', '1789870052', $fields['timestamp']);
expect_same('multiline Unicode and punctuation', "First line\n\n📦 Repository: Test\nLiteral \"quotes\", semicolons; equals=signs\nimportance=alert\n" . '${PATH} ${HOME} null true OFF' . "\n✅ Status: Erfolgreich", $fields['description']);
expect_same('embedded key is description text', 'normal', $fields['importance']);
expect_same('CRLF records', $fields, notification_fields(str_replace("\n", "\r\n", $record)));
expect_same('empty field and raw scalars', ['event'=>'', 'subject'=>'OFF', 'timestamp'=>'001'], notification_fields("event=\"\"\nsubject=OFF\ntimestamp=001\n"));
expect_same('comments and whitespace', ['event'=>'test'], notification_fields("; comment\n# comment\n\nevent=\"test\" \n"));
expect_same('truncated record is rejected', [], notification_fields("event=\"URBM\"\ndescription=\"unfinished\n"));
expect_same('malformed record is rejected', [], notification_fields("not a record\n"));
expect_same('empty record', [], notification_fields(''));
echo "All notification parser tests passed.\n";