Files
Jeremy Graham b7d7ea95d5 fix: skip syntax highlighting for large HTML in the search debug panel (#224)
Phiki takes about 1 second for 10 KB of HTML and much longer for long lines.
A full search results page exceeded the 30 second PHP time limit. HTML over
10 KB, or with a line over 500 characters, now shows as escaped plain text.
2026-10-06 16:38:29 +11:00

41 lines
1.4 KiB
PHP

<?php
namespace Tests\Unit\Services;
use App\Services\Helpers\CodeHelper;
use Tests\TestCase;
class CodeHelperTest extends TestCase
{
public function test_small_html_is_highlighted(): void
{
$html = CodeHelper::formatHtml('<b class="price">$10</b>');
$this->assertStringContainsString('class="phiki', $html);
$this->assertStringContainsString('<span class="token"', $html);
}
public function test_large_html_is_escaped_without_highlighting(): void
{
$row = '<div class="item"><a href="/p/1">Product</a></div>'."\n";
$code = str_repeat($row, intdiv(CodeHelper::MAX_HIGHLIGHT_LENGTH, strlen($row)) + 1);
$start = microtime(true);
$html = CodeHelper::formatHtml($code);
$this->assertLessThan(1, microtime(true) - $start);
$this->assertStringContainsString('class="phiki', $html);
$this->assertStringNotContainsString('<span class="token"', $html);
$this->assertStringContainsString('&lt;div class=&quot;item&quot;&gt;', $html);
$this->assertStringNotContainsString('<div class="item">', $html);
}
public function test_long_line_is_not_highlighted(): void
{
$code = str_repeat('<i>x</i>', intdiv(CodeHelper::MAX_HIGHLIGHT_LINE_LENGTH, 8) + 1);
$this->assertFalse(CodeHelper::canHighlight($code));
$this->assertTrue(CodeHelper::canHighlight(str_replace('>', ">\n", $code)));
}
}