Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m0s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m52s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m31s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 53s
- Formular-Plugin: Baukasten mit 13 Feldtypen, Bedingungen, Vorbelegung aus dem Profil, Datei-Uploads (geschützt), anonyme Formulare, „nur einmal“, Einsendeschluss, Sichtbarkeit, Löschfrist; Einsendungen im Backend und per Mail (optional ohne Angaben, Kopie an die Person); Rechte je Formular und Rolle für Ansehen/Export und Löschen; CSV für Excel; Pagebuilder-Block - WordPress-Import (Plugin): WXR-Datei einlesen, Kategorien/Personen zuordnen, Beiträge mit Status, Datum, Beitragsbild und Bildern im Text übernehmen, optional Seiten mit Hierarchie; in Portionen, wiederholbar ohne Doppelungen - E-Mail-Versand im Admin (SMTP, verschlüsseltes Passwort, Test-Mail) - Speichertest unabhängig vom Verbrauch der Test-Suite Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
155 lines
6.3 KiB
PHP
155 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Plugins;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Inhaus\Plugins\News\Models\NewsCategory;
|
|
use Inhaus\Plugins\News\Models\NewsPost;
|
|
use Tests\TestCase;
|
|
|
|
class NewsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_only_published_posts_are_listed(): void
|
|
{
|
|
NewsPost::factory()->count(2)->create();
|
|
NewsPost::factory()->draft()->create();
|
|
NewsPost::factory()->scheduled()->create();
|
|
|
|
$this->actingAs(User::factory()->create())
|
|
->get('/neuigkeiten')
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page->component('news::Index')->where('posts.meta.total', 2));
|
|
}
|
|
|
|
public function test_posts_can_be_filtered_by_category(): void
|
|
{
|
|
$mav = NewsCategory::factory()->create(['name' => 'MAV', 'slug' => 'mav']);
|
|
NewsPost::factory()->create(['category_id' => $mav->id]);
|
|
NewsPost::factory()->count(2)->create();
|
|
|
|
$this->actingAs(User::factory()->create())
|
|
->get('/neuigkeiten?kategorie=mav')
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->where('posts.meta.total', 1)
|
|
->where('posts.data.0.category.name', 'MAV')
|
|
->where('activeCategory', 'mav'));
|
|
}
|
|
|
|
public function test_published_post_is_shown_with_author(): void
|
|
{
|
|
$author = User::factory()->create(['first_name' => 'Grete', 'last_name' => 'Müller']);
|
|
$post = NewsPost::factory()->create(['author_id' => $author->id, 'title' => 'Sommerfest 2026']);
|
|
|
|
$this->assertSame('sommerfest-2026', $post->slug);
|
|
|
|
$this->actingAs(User::factory()->create())
|
|
->get('/neuigkeiten/sommerfest-2026')
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('news::Show')
|
|
->where('post.title', 'Sommerfest 2026')
|
|
->where('post.author.name', 'Grete Müller'));
|
|
}
|
|
|
|
public function test_drafts_and_scheduled_posts_are_not_reachable(): void
|
|
{
|
|
$draft = NewsPost::factory()->draft()->create();
|
|
$scheduled = NewsPost::factory()->scheduled()->create();
|
|
$user = User::factory()->create();
|
|
|
|
$this->actingAs($user)->get("/neuigkeiten/{$draft->slug}")->assertNotFound();
|
|
$this->actingAs($user)->get("/neuigkeiten/{$scheduled->slug}")->assertNotFound();
|
|
}
|
|
|
|
public function test_slugs_are_unique(): void
|
|
{
|
|
$a = NewsPost::factory()->create(['title' => 'Neuigkeit']);
|
|
$b = NewsPost::factory()->create(['title' => 'Neuigkeit']);
|
|
|
|
$this->assertSame('neuigkeit', $a->slug);
|
|
$this->assertSame('neuigkeit-2', $b->slug);
|
|
}
|
|
|
|
public function test_body_is_sanitized_when_saved(): void
|
|
{
|
|
$post = NewsPost::factory()->create([
|
|
'body' => '<p onclick="alert(1)">Hallo <strong>Welt</strong></p><script>alert(1)</script><a href="javascript:alert(1)">Link</a><iframe src="https://evil.example"></iframe>',
|
|
]);
|
|
|
|
$this->assertStringContainsString('<strong>Welt</strong>', $post->body_html);
|
|
$this->assertStringNotContainsString('script', $post->body_html);
|
|
$this->assertStringNotContainsString('onclick', $post->body_html);
|
|
$this->assertStringNotContainsString('javascript:', $post->body_html);
|
|
$this->assertStringNotContainsString('iframe', $post->body_html);
|
|
}
|
|
|
|
public function test_reading_time_is_calculated(): void
|
|
{
|
|
$post = NewsPost::factory()->create(['body' => '<p>'.str_repeat('Wort ', 450).'</p>']);
|
|
|
|
$this->assertSame(3, $post->reading_minutes);
|
|
}
|
|
|
|
public function test_cover_variants_are_created_and_removed(): void
|
|
{
|
|
Storage::fake('uploads');
|
|
Storage::disk('uploads')->put('news/cover.jpg', UploadedFile::fake()->image('cover.jpg', 2000, 1200)->getContent());
|
|
|
|
$post = NewsPost::factory()->create(['cover_path' => 'news/cover.jpg']);
|
|
|
|
Storage::disk('uploads')->assertExists('news/cover-thumb.webp');
|
|
Storage::disk('uploads')->assertExists('news/cover-large.webp');
|
|
$this->assertStringEndsWith('news/cover-thumb.webp', $post->coverUrl('thumb'));
|
|
|
|
$post->delete();
|
|
|
|
Storage::disk('uploads')->assertMissing('news/cover.jpg');
|
|
Storage::disk('uploads')->assertMissing('news/cover-thumb.webp');
|
|
}
|
|
|
|
public function test_large_photos_fit_into_shared_hosting_memory_limit(): void
|
|
{
|
|
Storage::fake('uploads');
|
|
|
|
// Testbild (12 Megapixel wie ein Handyfoto) mit großzügigem Limit erzeugen …
|
|
ini_set('memory_limit', '512M');
|
|
Storage::disk('uploads')->put('news/handyfoto.jpg', UploadedFile::fake()->image('handyfoto.jpg', 4000, 3000)->getContent());
|
|
gc_collect_cycles();
|
|
|
|
// … dann wie auf typischem Shared Hosting mit 128 MB verarbeiten. Der Test-Prozess
|
|
// selbst belegt schon Speicher (viele Tests in einem Lauf), daher 128 MB zusätzlich dazu.
|
|
$limit = memory_get_usage(true) + 128 * 1024 * 1024;
|
|
$this->assertNotFalse(ini_set('memory_limit', (string) $limit));
|
|
|
|
NewsPost::factory()->create(['cover_path' => 'news/handyfoto.jpg']);
|
|
|
|
Storage::disk('uploads')->assertExists('news/handyfoto-large.webp');
|
|
Storage::disk('uploads')->assertExists('news/handyfoto-thumb.webp');
|
|
|
|
ini_set('memory_limit', '512M');
|
|
}
|
|
|
|
public function test_dashboard_shows_featured_and_latest_news(): void
|
|
{
|
|
Storage::fake('uploads');
|
|
Storage::disk('uploads')->put('news/a.jpg', UploadedFile::fake()->image('a.jpg', 800, 450)->getContent());
|
|
|
|
$featured = NewsPost::factory()->create(['is_featured' => true, 'cover_path' => 'news/a.jpg']);
|
|
NewsPost::factory()->count(5)->create();
|
|
NewsPost::factory()->draft()->create(['is_featured' => true, 'cover_path' => 'news/a.jpg']);
|
|
|
|
$response = $this->actingAs(User::factory()->create())->get('/');
|
|
|
|
$hero = $this->dashboardWidget($response, 'news.hero')['posts'];
|
|
$this->assertCount(1, $hero);
|
|
$this->assertSame($featured->id, $hero[0]['id']);
|
|
$this->assertCount(4, $this->dashboardWidget($response, 'news.latest')['posts']);
|
|
$this->assertCount(1, $this->dashboardWidget($response, 'news.areas')['posts']);
|
|
}
|
|
}
|