60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
use function Pest\Laravel\get;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| System Log Module Tests
|
|
|--------------------------------------------------------------------------
|
|
| This module reads and parses Laravel log files from storage/logs.
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
describe('System Log Module - Authorization', function () {
|
|
it('redirects to login when accessing logs unauthenticated', function () {
|
|
get(route('system.logs.index'))
|
|
->assertRedirect(route('login'));
|
|
});
|
|
|
|
it('returns 403 when user has no permission to view logs', function () {
|
|
actingAs(createUnauthorizedUser())
|
|
->get(route('system.logs.index'))
|
|
->assertStatus(403);
|
|
});
|
|
});
|
|
|
|
describe('System Log Module - Authorized Actions', function () {
|
|
beforeEach(function () {
|
|
$user = createAuthorizedUser(['View:Log']);
|
|
actingAs($user);
|
|
});
|
|
|
|
it('can access system logs index page', function () {
|
|
// Create a dummy log file to ensure it doesn't crash
|
|
$path = storage_path('logs/laravel.log');
|
|
if (! File::exists(storage_path('logs'))) {
|
|
File::makeDirectory(storage_path('logs'), 0755, true);
|
|
}
|
|
File::put($path, "[2026-04-30 08:00:00] local.INFO: Test system log entry\n");
|
|
|
|
get(route('system.logs.index'))
|
|
->assertOk()
|
|
->assertInertia(fn ($page) => $page
|
|
->component('admin/system/logs/index')
|
|
->has('logFiles')
|
|
->has('logs')
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('System Log Module - Unauthorized Actions', function () {
|
|
it('cannot view system logs without permission', function () {
|
|
actingAs(createUnauthorizedUser())
|
|
->get(route('system.logs.index'))
|
|
->assertStatus(403);
|
|
});
|
|
});
|