Files
coruna-lab/tests/Feature/RawLogControllerTest.php
T
2026-08-14 13:43:53 +08:00

68 lines
2.1 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Admin;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class RawLogControllerTest extends TestCase
{
use RefreshDatabase;
private function superAdmin(): Admin
{
return Admin::query()->create([
'username' => 'root',
'password' => 'secret12',
'is_super' => 1,
]);
}
#[Test]
public function xxbb_log_show_pages_instead_of_loading_the_whole_file(): void
{
$dir = public_path('log/xxbb');
if (! is_dir($dir)) {
mkdir($dir, 0775, true);
}
$file = $dir.'/20990101.log';
$chunks = [];
for ($i = 1; $i <= 90; $i++) {
$chunks[] = '2026-08-14 13:00:00 /event {"n":'.$i.',"marker":"ENTRY-'.$i.'"}';
}
file_put_contents($file, implode("\r\n\r\n", $chunks)."\r\n\r\n");
try {
$admin = $this->superAdmin();
$page1 = $this->actingAs($admin, 'admin')
->get(route('admin.logs.show', [
'file' => '20990101.log',
'kind' => 'xxbb',
'per_page' => 40,
]))
->assertOk();
$html1 = $page1->getContent();
$this->assertSame(40, substr_count($html1, 'class="json-block"'));
$this->assertStringContainsString('ENTRY-90', $html1);
$this->assertStringNotContainsString('ENTRY-50', $html1);
$this->assertStringContainsString('更早', $html1);
$page2 = $this->actingAs($admin, 'admin')
->get(route('admin.logs.show', [
'file' => '20990101.log',
'kind' => 'xxbb',
'per_page' => 40,
'page' => 2,
]))
->assertOk();
$html2 = $page2->getContent();
$this->assertStringContainsString('ENTRY-50', $html2);
$this->assertStringNotContainsString('ENTRY-90', $html2);
} finally {
@unlink($file);
}
}
}