Stelle das U0-Fundament mit CMS, Mitgliedern und Filament bereit.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
89b35ac480
commit
2035c46edd
130 files changed
+18519
-50
No files matched your search
@@ -0,0 +1,107 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PublicPageTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_home_page_is_published_from_the_cms(): void
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee('Lara & Felix', false);
|
||||
$response->assertSee('Stark im Alltag');
|
||||
$response->assertSee('Anmelden');
|
||||
$response->assertSee('href="'.route('login').'"', false);
|
||||
$response->assertDontSee('/verwaltung');
|
||||
}
|
||||
|
||||
public function test_known_pages_and_sitemap_are_available(): void
|
||||
{
|
||||
$this->get('/praevention')->assertOk()->assertSee('Prävention im Alltag');
|
||||
$this->get('/angebote')->assertOk()->assertDontSee('€');
|
||||
$this->get('/sitemap.xml')->assertOk()->assertSee(url('/praevention'), false);
|
||||
}
|
||||
|
||||
public function test_missing_page_is_not_found(): void
|
||||
{
|
||||
$this->get('/gibt-es-nicht')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_page_paths_are_unique(): void
|
||||
{
|
||||
$this->expectException(QueryException::class);
|
||||
|
||||
Page::query()->create(['path' => '/']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Auth\Notifications\VerifyEmail;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RegistrationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_registration_requires_an_adult_confirmation(): void
|
||||
{
|
||||
$response = $this->from('/registrieren')->post('/registrieren', [
|
||||
'name' => 'Ada Trainer',
|
||||
'email' => 'ada@example.com',
|
||||
'password' => 'password-pass',
|
||||
'password_confirmation' => 'password-pass',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/registrieren');
|
||||
$response->assertSessionHasErrors('adult');
|
||||
$this->assertDatabaseCount('users', 0);
|
||||
}
|
||||
|
||||
public function test_registration_creates_a_person_and_sends_verification(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$response = $this->post('/registrieren', [
|
||||
'name' => 'Ada Trainer',
|
||||
'email' => 'ada@example.com',
|
||||
'password' => 'password-pass',
|
||||
'password_confirmation' => 'password-pass',
|
||||
'adult' => '1',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('verification.notice'));
|
||||
|
||||
$user = User::query()->where('email', 'ada@example.com')->first();
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($user->confirmed_adult_at);
|
||||
$this->assertSame('person', $user->party->type->value);
|
||||
$this->assertSame('private', $user->party->profile->visibility['display_name']);
|
||||
$this->assertAuthenticatedAs($user);
|
||||
Notification::assertSentTo($user, VerifyEmail::class);
|
||||
}
|
||||
|
||||
public function test_verified_member_can_log_in_and_reaches_the_dashboard(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'ada@example.com',
|
||||
'password' => 'password-pass',
|
||||
]);
|
||||
|
||||
$response = $this->post('/anmelden', [
|
||||
'email' => 'ada@example.com',
|
||||
'password' => 'password-pass',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('member.dashboard'));
|
||||
$this->assertAuthenticatedAs($user);
|
||||
$this->get('/bereich')->assertOk()->assertSee('Guten Tag');
|
||||
$this->get('/bereich/bibliothek')->assertOk()->assertSee('noch kein Material');
|
||||
}
|
||||
|
||||
public function test_unverified_member_cannot_open_the_member_area(): void
|
||||
{
|
||||
$user = User::factory()->unverified()->create([
|
||||
'password' => 'password-pass',
|
||||
]);
|
||||
|
||||
$this->post('/anmelden', [
|
||||
'email' => $user->email,
|
||||
'password' => 'password-pass',
|
||||
])->assertRedirect(route('member.dashboard'));
|
||||
|
||||
$this->get('/bereich')->assertRedirect(route('verification.notice'));
|
||||
}
|
||||
|
||||
public function test_password_reset_sends_a_link(): void
|
||||
{
|
||||
Notification::fake();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post('/passwort/vergessen', ['email' => $user->email])
|
||||
->assertSessionHas('status');
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class);
|
||||
}
|
||||
|
||||
public function test_guests_cannot_open_the_member_area(): void
|
||||
{
|
||||
$this->get('/bereich')->assertRedirect('/anmelden');
|
||||
$this->get('/bereich/berechtigungen')->assertRedirect('/anmelden');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->withoutVite();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Domain\Cms\Blocks\BlockRegistry;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BlockRegistryTest extends TestCase
|
||||
{
|
||||
public function test_image_text_requires_an_alternative_text(): void
|
||||
{
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
app(BlockRegistry::class)->normalize([
|
||||
['type' => 'image_text', 'body' => 'Text', 'image' => 'cms/bild.jpg'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_action_links_reject_script_urls(): void
|
||||
{
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
app(BlockRegistry::class)->normalize([
|
||||
[
|
||||
'type' => 'call_to_action',
|
||||
'heading' => 'Weiter',
|
||||
'label' => 'Öffnen',
|
||||
'url' => 'javascript:alert(1)',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user