Profil zeigt geschriebene Beiträge, Als Person anmelden (0.27.1)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m47s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m40s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m51s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m1s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m45s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m36s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m21s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m47s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m40s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m51s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m1s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m45s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m36s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m21s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1469f50401
commit
546c94db1c
127 changed files with 643 additions and 337 deletions
68
tests/Feature/Admin/ImpersonationTest.php
Normal file
68
tests/Feature/Admin/ImpersonationTest.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use App\Filament\Resources\Users\Pages\ListUsers;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ImpersonationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_admin_sees_the_portal_as_another_person_and_returns(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->create();
|
||||
$anna = User::factory()->create(['name' => 'Anna Schmidt']);
|
||||
|
||||
$this->actingAs($admin)->post("/anmelden-als/{$anna->id}")->assertRedirect('/');
|
||||
$this->assertAuthenticatedAs($anna);
|
||||
|
||||
$this->get('/')->assertInertia(fn (Assert $page) => $page
|
||||
->where('auth.user.id', $anna->id)
|
||||
->where('auth.user.can_admin', false)
|
||||
->where('impersonation.name', $anna->name));
|
||||
$this->get('/admin')->assertForbidden();
|
||||
|
||||
// Nicht verschachteln
|
||||
$this->post("/anmelden-als/{$admin->id}")->assertForbidden();
|
||||
|
||||
$this->post('/anmelden-als/beenden')->assertRedirect('/admin/benutzer');
|
||||
$this->assertAuthenticatedAs($admin);
|
||||
$this->get('/')->assertInertia(fn (Assert $page) => $page->where('impersonation', null));
|
||||
$this->assertDatabaseHas('audit_logs', ['action' => 'user.impersonation_started']);
|
||||
}
|
||||
|
||||
public function test_only_user_managers_and_never_into_full_administrators(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->create();
|
||||
$role = Role::query()->create(['name' => 'Personal']);
|
||||
$role->grants()->create(['ability' => 'users.manage']);
|
||||
$hr = User::factory()->withRoles([$role])->create();
|
||||
$employee = User::factory()->create();
|
||||
|
||||
$this->actingAs($employee)->post("/anmelden-als/{$hr->id}")->assertForbidden();
|
||||
$this->actingAs($hr)->post("/anmelden-als/{$admin->id}")->assertForbidden();
|
||||
$this->actingAs($hr)->post('/anmelden-als/'.User::factory()->inactive()->create()->id)->assertForbidden();
|
||||
$this->actingAs($hr)->post("/anmelden-als/{$employee->id}")->assertRedirect('/');
|
||||
}
|
||||
|
||||
public function test_user_list_offers_the_action(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->create();
|
||||
$anna = User::factory()->create();
|
||||
|
||||
$this->actingAs($admin);
|
||||
Livewire::test(ListUsers::class)
|
||||
->assertTableActionVisible('impersonate', $anna)
|
||||
->assertTableActionHidden('impersonate', $admin)
|
||||
->callTableAction('impersonate', $anna)
|
||||
->assertRedirect('/');
|
||||
|
||||
$this->assertAuthenticatedAs($anna);
|
||||
}
|
||||
}
|
||||
|
|
@ -223,4 +223,22 @@ class NewsWorkflowTest extends TestCase
|
|||
$this->assertSame(['title' => 'MAV', 'count' => 3, 'layout' => 'cards', 'filter' => 'include', 'categories' => ['mav-info']], $items[0]['blocks'][0]['data']);
|
||||
$this->assertSame('all', $items[1]['blocks'][0]['data']['filter']);
|
||||
}
|
||||
|
||||
public function test_profile_lists_the_posts_a_person_has_written(): void
|
||||
{
|
||||
NewsPost::factory()->create(['author_id' => $this->author->id, 'category_id' => $this->company->id, 'title' => 'Neues Leitbild', 'published_at' => now()->subDay()]);
|
||||
NewsPost::factory()->draft()->create(['author_id' => $this->author->id, 'category_id' => $this->company->id, 'title' => 'Entwurf']);
|
||||
$viewer = User::factory()->create();
|
||||
|
||||
$this->actingAs($viewer)->get("/personen/{$this->author->id}")->assertInertia(fn ($page) => $page
|
||||
->where('panels', fn ($panels) => ($posts = collect($panels)->firstWhere('key', 'news.posts'))
|
||||
&& $posts['props']['total'] === 1 && $posts['props']['posts'][0]['title'] === 'Neues Leitbild'));
|
||||
|
||||
$this->get("/neuigkeiten?autor={$this->author->id}")->assertInertia(fn ($page) => $page
|
||||
->where('filter', 'Von: '.$this->author->name)
|
||||
->where('posts.data', fn ($posts) => collect($posts)->pluck('title')->all() === ['Neues Leitbild']));
|
||||
|
||||
// Ohne Beiträge kein Bereich
|
||||
$this->get("/personen/{$viewer->id}")->assertInertia(fn ($page) => $page->where('panels', fn ($panels) => ! collect($panels)->contains('key', 'news.posts')));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue