HEX
Server: Apache/2.4.66 (Debian)
System: Linux 6dfabc3b2241 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64
User: (1000)
PHP: 8.3.30
Disabled: NONE
Upload Files
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);
    }
}