108 lines
4.2 KiB
PHP
108 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Cms\Page;
|
|
use App\Domain\Cms\PageService;
|
|
use App\Domain\Identity\AssignStaffRoles;
|
|
use App\Domain\Identity\StaffRole;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AdministrationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_guests_and_members_cannot_open_the_administration(): void
|
|
{
|
|
$this->get('/verwaltung')->assertRedirect('/verwaltung/login');
|
|
|
|
$member = User::factory()->create();
|
|
|
|
$this->actingAs($member)->get('/verwaltung')->assertRedirect('/verwaltung/login');
|
|
$this->actingAs($member, 'staff')->get('/verwaltung')->assertForbidden();
|
|
}
|
|
|
|
public function test_editor_must_set_up_multi_factor_authentication(): void
|
|
{
|
|
$editor = User::factory()->redakteur()->create();
|
|
|
|
$this->actingAs($editor, 'staff')
|
|
->get('/verwaltung')
|
|
->assertRedirect();
|
|
}
|
|
|
|
public function test_editor_with_multi_factor_can_open_pages_but_not_user_management(): void
|
|
{
|
|
$editor = User::factory()->redakteur()->create();
|
|
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
|
|
|
$this->actingAs($editor, 'staff')->get('/verwaltung')->assertOk();
|
|
$this->actingAs($editor, 'staff')->get('/verwaltung/pages')->assertOk();
|
|
$this->actingAs($editor, 'staff')->get('/verwaltung/users')->assertForbidden();
|
|
$this->assertTrue($editor->can('update', Page::query()->first()));
|
|
$this->assertFalse($editor->can('viewAny', User::class));
|
|
}
|
|
|
|
public function test_system_administrator_manages_roles_and_does_not_publish_pages(): void
|
|
{
|
|
$admin = User::factory()->systemverwalter()->create();
|
|
$admin->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
|
$member = User::factory()->create();
|
|
$page = Page::query()->where('path', '/')->firstOrFail();
|
|
|
|
$this->actingAs($admin, 'staff')->get('/verwaltung/users')->assertOk();
|
|
$this->actingAs($admin, 'staff')->get('/verwaltung/pages')->assertForbidden();
|
|
$this->assertFalse($admin->can('publish', $page));
|
|
|
|
app(AssignStaffRoles::class)->sync($member, [StaffRole::Redakteur->value], $admin);
|
|
|
|
$this->assertTrue($member->fresh()->hasStaffRole(StaffRole::Redakteur));
|
|
}
|
|
|
|
public function test_draft_does_not_change_the_public_page_until_it_is_published(): void
|
|
{
|
|
$editor = User::factory()->redakteur()->create();
|
|
$page = Page::query()->where('path', '/')->firstOrFail();
|
|
$publishedId = $page->published_revision_id;
|
|
|
|
$revision = app(PageService::class)->saveRevision($page, [
|
|
['type' => 'heading', 'heading' => 'Nur ein Entwurf', 'intro' => 'Noch nicht live.'],
|
|
], 'Entwurf', 'Entwurf', $editor);
|
|
|
|
$this->get('/')->assertOk()->assertDontSee('Nur ein Entwurf');
|
|
$this->assertSame($publishedId, $page->fresh()->published_revision_id);
|
|
|
|
$this->actingAs($editor);
|
|
app(PageService::class)->publish($page->fresh(), $revision);
|
|
|
|
$this->get('/')->assertOk()->assertSee('Nur ein Entwurf');
|
|
}
|
|
|
|
public function test_restoring_a_revision_creates_a_new_revision_and_keeps_the_live_page(): void
|
|
{
|
|
$editor = User::factory()->redakteur()->create();
|
|
$service = app(PageService::class);
|
|
$page = Page::query()->where('path', '/praevention')->firstOrFail();
|
|
$original = $page->publishedRevision;
|
|
|
|
$second = $service->saveRevision($page, [
|
|
['type' => 'heading', 'heading' => 'Zweite Fassung', 'intro' => 'Ersetzt die erste nach Veröffentlichung.'],
|
|
], null, null, $editor);
|
|
$service->publish($page->fresh(), $second);
|
|
|
|
$this->get('/praevention')->assertSee('Zweite Fassung');
|
|
|
|
$restored = $service->restore($page->fresh(), $original, $editor);
|
|
|
|
$this->assertNotSame($original->id, $restored->id);
|
|
$this->assertSame($original->blocks, $restored->blocks);
|
|
$this->get('/praevention')->assertSee('Zweite Fassung')->assertDontSee('Prävention im Alltag');
|
|
|
|
$service->publish($page->fresh(), $restored);
|
|
|
|
$this->get('/praevention')->assertSee('Prävention im Alltag')->assertDontSee('Zweite Fassung');
|
|
}
|
|
}
|