First public release. - docs: document the audit log, user offboarding, CSV export and the "require a reason for destructive actions" setting across README, docs/ and CLAUDE/AGENTS.md; note retention for panel_audit - docs: fill the publishing placeholders (repo URL, security contact, issue-template links) and add a semantic-versioning policy - move agent/contributor context into CLAUDE/ (AGENTS.md + a README); root CLAUDE.md is now a thin @-import pointer - add a favicon (shield-lock, matching the login screen) to the login page and the app layout - CHANGELOG: promote [Unreleased] to [1.0.0]; keep the earlier internal build as [0.1.0] Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UfuvfwexztdS7LDpGuKsuK
51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Models\AuditLog;
|
|
use App\Services\AuditLogger;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tests\TestCase;
|
|
|
|
class AuditLoggerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_it_writes_an_entry_with_the_acting_admin(): void
|
|
{
|
|
$this->actingAsPanelAdmin();
|
|
|
|
app(AuditLogger::class)->log('user.disable', [
|
|
'target_type' => 'user',
|
|
'target' => 'jkowalski',
|
|
'reason' => 'porzucone konto',
|
|
]);
|
|
|
|
$entry = AuditLog::query()->latest('id')->first();
|
|
|
|
$this->assertSame('user.disable', $entry->action);
|
|
$this->assertSame('tester', $entry->actor);
|
|
$this->assertSame('jkowalski', $entry->target);
|
|
$this->assertSame('porzucone konto', $entry->reason);
|
|
$this->assertNotNull($entry->created_at);
|
|
}
|
|
|
|
public function test_it_falls_back_to_system_actor_without_a_session(): void
|
|
{
|
|
app(AuditLogger::class)->log('config.settings');
|
|
|
|
$this->assertDatabaseHas('panel_audit', ['action' => 'config.settings', 'actor' => 'system']);
|
|
}
|
|
|
|
public function test_a_write_failure_does_not_bubble_up(): void
|
|
{
|
|
// Tabela zniknęła - log nie może powstać, ale metoda nie może rzucić.
|
|
Schema::drop('panel_audit');
|
|
|
|
app(AuditLogger::class)->log('user.delete', ['target' => 'x']);
|
|
|
|
$this->assertTrue(true);
|
|
}
|
|
}
|