File: /var/www/html/wp-content/themes/custom-theme/tests/LoggerTest.php
<?php
use PHPUnit\Framework\TestCase;
class LoggerTest extends TestCase
{
public function test_format_line_includes_all_parts(): void
{
$line = headless_log_format_line('ERROR', 'typesense', 'Request failed');
$this->assertMatchesRegularExpression(
'/^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\] \[ERROR\] \[typesense\] Request failed$/',
$line
);
}
public function test_format_line_appends_json_context(): void
{
$line = headless_log_format_line('WARNING', 'pdf', 'Ghostscript failed', ['status' => 500]);
$this->assertStringContainsString('[WARNING]', $line);
$this->assertStringContainsString('[pdf]', $line);
$this->assertStringContainsString('{"status":500}', $line);
}
public function test_format_line_omits_context_when_empty(): void
{
$line = headless_log_format_line('INFO', 'blocks', 'Resolved', []);
$this->assertStringEndsWith('Resolved', $line);
}
public function test_format_line_handles_special_characters(): void
{
$line = headless_log_format_line('DEBUG', 'test', 'Path check', ['path' => '/uploads/2026/file.pdf']);
$this->assertStringContainsString('/uploads/2026/file.pdf', $line);
}
}