Loheide-eu-mitarbeiterplatt.../tests/Feature/Plugins/ContentAdminTest.php
Friederich Loheide 28ef1e4a20 Plugin-System; Neuigkeiten und Termine als mitgelieferte Plugins
- Plugins nach WordPress-Prinzip: plugin.json-Manifest mit Versions- und
  Abhängigkeitsprüfung, eigenes PSR-4-Autoloading, register()/boot(),
  activate()/deactivate()/uninstall(), Migrationen, Routen und Views je Plugin
- plugins-core/ (mitgeliefert, aktiv bis zur Deaktivierung) und plugins/
  (Kunden-Plugins, geschützt vor Updates, inaktiv bis zur Aktivierung)
- Zustand in storage/app/plugins.json – Laden ohne Datenbankabfrage
- Wiederherstellungsmodus: Ausnahmen und Fatal Errors beim Laden
  deaktivieren das Plugin, das Portal bleibt erreichbar
- Hooks (Actions/Filter mit Prioritäten) und Registries für Navigation,
  Startseiten-Kacheln, Rechte und Admin-Seiten (Filament-Discovery)
- Admin-Seite „Plugins“: aktivieren, deaktivieren, per ZIP installieren
  (ZIP-Slip-Schutz), löschen mit oder ohne Daten; abschaltbar per
  INHAUS_DISALLOW_FILE_MODS
- Startseite komplett aus Kacheln; Plugin-Seiten als „slug::Seite“
- Version 0.3.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 07:06:16 +00:00

84 lines
3 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\Filament\Resources\NewsPosts\Pages\CreateNewsPost;
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/neuigkeiten/neu', "/admin/neuigkeiten/{$post->id}/bearbeiten", '/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();
}
}
public function test_admin_can_write_a_post(): void
{
$admin = User::factory()->admin()->create();
$category = NewsCategory::factory()->create();
$this->actingAs($admin);
Livewire::test(CreateNewsPost::class)
->fillForm([
'title' => 'Neue Kantine eröffnet',
'teaser' => 'Ab Montag gibt es frisches Essen im Erdgeschoss.',
'category_id' => $category->id,
'published_at' => now()->subMinute()->format('Y-m-d H:i'),
])
->call('create')
->assertHasNoFormErrors();
$post = NewsPost::query()->firstOrFail();
$this->assertSame('neue-kantine-eroeffnet', $post->slug);
$this->assertSame($admin->id, $post->author_id);
$this->assertTrue($post->isPublished());
}
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']);
}
}