Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m3s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m32s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m41s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m5s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m57s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m59s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m35s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
96 lines
4 KiB
PHP
96 lines
4 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\Plugins;
|
||
|
||
use App\Models\User;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Inhaus\Plugins\Events\Filament\Resources\Events\Pages\CreateEvent;
|
||
use Inhaus\Plugins\Events\Models\Event;
|
||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||
use Inhaus\Plugins\News\Models\NewsPost;
|
||
use Livewire\Livewire;
|
||
use Tests\TestCase;
|
||
|
||
class ContentAdminTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
public function test_content_pages_are_reachable_for_admins_only(): void
|
||
{
|
||
$admin = User::factory()->admin()->create();
|
||
$post = NewsPost::factory()->create();
|
||
$event = Event::factory()->create();
|
||
|
||
foreach (['/admin/neuigkeiten', '/admin/kategorien', '/admin/termine', '/admin/termine/neu', "/admin/termine/{$event->id}/bearbeiten"] as $url) {
|
||
$this->actingAs($admin)->get($url)->assertOk();
|
||
$this->actingAs(User::factory()->create())->get($url)->assertForbidden();
|
||
}
|
||
|
||
// Beiträge schreibt man im Baukasten-Editor des Portals – das Backend leitet dorthin
|
||
$this->actingAs($admin)->get('/admin/neuigkeiten/neu')->assertRedirect(route('news.editor.create'));
|
||
$this->actingAs($admin)->get("/admin/neuigkeiten/{$post->id}/bearbeiten")->assertRedirect(route('news.editor.edit', $post));
|
||
$this->actingAs(User::factory()->create())->get("/admin/neuigkeiten/{$post->id}/bearbeiten")->assertForbidden();
|
||
}
|
||
|
||
public function test_admin_can_write_a_post(): void
|
||
{
|
||
$admin = User::factory()->admin()->create();
|
||
$category = NewsCategory::factory()->create();
|
||
$this->actingAs($admin);
|
||
|
||
$this->post('/redaktion/neuigkeiten', [
|
||
'title' => 'Neue Kantine eröffnet',
|
||
'teaser' => 'Ab Montag gibt es frisches Essen im Erdgeschoss.',
|
||
'category_id' => $category->id,
|
||
'content' => json_encode(['blocks' => [
|
||
['type' => 'heading', 'data' => ['text' => 'Was es gibt']],
|
||
['type' => 'text', 'data' => ['html' => '<p>Suppe, Salat und <strong>zwei Hauptgerichte</strong>.</p><script>alert(1)</script>']],
|
||
]]),
|
||
'action' => 'publish',
|
||
])->assertSessionHasNoErrors();
|
||
|
||
$post = NewsPost::query()->firstOrFail();
|
||
$this->assertSame('neue-kantine-eroeffnet', $post->slug);
|
||
$this->assertSame($admin->id, $post->author_id);
|
||
$this->assertTrue($post->isPublished());
|
||
$this->assertSame(['heading', 'text'], array_column($post->content['blocks'], 'type'));
|
||
$this->assertStringNotContainsString('script', json_encode($post->content));
|
||
$this->assertStringContainsString('zwei Hauptgerichte', $post->body, 'Text für Suche und Lesezeit');
|
||
|
||
$this->get("/neuigkeiten/{$post->slug}")->assertOk()->assertInertia(fn ($page) => $page
|
||
->where('post.body_html', null)
|
||
->where('content.blocks.1.data.html', fn ($html) => str_contains($html, 'zwei Hauptgerichte')));
|
||
}
|
||
|
||
public function test_admin_can_create_an_event(): void
|
||
{
|
||
$this->actingAs(User::factory()->admin()->create());
|
||
|
||
Livewire::test(CreateEvent::class)
|
||
->fillForm([
|
||
'title' => 'Sommerfest',
|
||
'starts_at' => now()->addWeek()->format('Y-m-d 14:00'),
|
||
'ends_at' => now()->addWeek()->format('Y-m-d 18:00'),
|
||
'location' => 'Garten',
|
||
'is_published' => true,
|
||
])
|
||
->call('create')
|
||
->assertHasNoFormErrors();
|
||
|
||
$this->assertSame('Garten', Event::query()->firstOrFail()->location);
|
||
}
|
||
|
||
public function test_event_end_must_not_be_before_start(): void
|
||
{
|
||
$this->actingAs(User::factory()->admin()->create());
|
||
|
||
Livewire::test(CreateEvent::class)
|
||
->fillForm([
|
||
'title' => 'Falsch herum',
|
||
'starts_at' => now()->addWeek()->format('Y-m-d 14:00'),
|
||
'ends_at' => now()->addWeek()->format('Y-m-d 10:00'),
|
||
])
|
||
->call('create')
|
||
->assertHasFormErrors(['ends_at']);
|
||
}
|
||
}
|