admin = User::factory()->admin()->create(); $png = UploadedFile::fake()->image('x.png', 40, 30)->getContent(); Http::fake([ 'intranet.example.org/wp-content/uploads/*' => Http::response($png, 200, ['Content-Type' => 'image/png']), '*' => Http::response('nicht da', 404), ]); } private function analyze(): WpImport { Storage::disk('local')->put('wp-import/export.xml', file_get_contents(base_path('tests/Fixtures/wordpress-export.xml'))); return tap(app(Analyzer::class)->analyze(Storage::disk('local')->path('wp-import/export.xml'), $this->admin), fn ($i) => $i->update(['file' => 'wp-import/export.xml'])); } private function runImport(WpImport $import, array $options = []): WpImport { $importer = app(Importer::class); $importer->start($import, array_merge(['download_images' => true, 'fallback_author' => $this->admin->id], $options)); for ($i = 0; $i < 20 && ! $importer->step($import->fresh()); $i++); return $import->fresh(); } public function test_export_is_analyzed(): void { $import = $this->analyze(); $this->assertSame('Altes Intranet', $import->site_title); $this->assertSame('intranet.example.org', $import->source()); $this->assertSame(['post' => 4, 'page' => 2, 'attachment' => 1, 'category' => 2, 'author' => 2, 'other' => 1, 'drafts' => 1], $import->stats['found']); } public function test_posts_categories_authors_and_images_are_imported(): void { $redaktion = User::factory()->create(['email' => 'redaktion@firma.de']); $existing = NewsCategory::factory()->create(['name' => 'MAV-Info', 'slug' => 'mav-info']); $import = $this->runImport($this->analyze()); $this->assertSame('done', $import->status); $this->assertSame(2, NewsPost::query()->count(), 'Entwurf und privater Beitrag bleiben draußen.'); $this->assertSame(2, NewsCategory::query()->count(), 'Vorhandene Kategorie wird genutzt, fehlende angelegt.'); $fest = NewsPost::query()->where('slug', 'sommerfest')->sole(); $this->assertSame('Sommerfest 2024 – Rückblick', $fest->title); $this->assertSame('Aus den Bereichen & Häusern', $fest->category->name); $this->assertSame($redaktion->id, $fest->author_id); $this->assertTrue($fest->isPublished()); $this->assertSame('2024-06-21 16:30:00', $fest->published_at->utc()->format('Y-m-d H:i:s')); $this->assertNotNull($fest->cover_path); Storage::disk('uploads')->assertExists($fest->cover_path); $this->assertStringContainsString('
Das Sommerfest war ein voller Erfolg.
', $fest->body);
$this->assertStringContainsString('Das Buffet im Innenhof', $fest->body);
$this->assertStringNotContainsString('intranet.example.org', $fest->body, 'Bilder liegen jetzt im Portal.');
$this->assertStringNotContainsString('srcset', $fest->body);
$this->assertStringNotContainsString('contact-form-7', $fest->body);
$this->assertStringNotContainsString('