presseportale/tests/Feature/Admin/AdminFooterCodeManagementTest.php
Kevin Adametz 0a3e52d603 19-05-2026 Rebrand Pressekonto, Hub-Flux UI und Legacy-Media-Migration
Umbenennung presseportale → pressekonto in Domains, Themes und Dokumentation.
Design-Tokens, Portal-Shell, Customer-Dashboard, Auth- und Admin-PM-Views.
Artisan-Befehl migrate:legacy-media mit Tests und Hub-Flux-Entwicklungsdocs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-19 16:36:13 +00:00

162 lines
5.3 KiB
PHP

<?php
use App\Enums\Portal;
use App\Models\Category;
use App\Models\FooterCode;
use App\Models\User;
use Database\Seeders\RolesAndPermissionsSeeder;
use Livewire\Volt\Volt as LivewireVolt;
use Tests\TestCase;
beforeEach(function (): void {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
$admin = User::factory()->create(['is_active' => true]);
$admin->assignRole('admin');
$this->actingAs($admin);
});
test('admin can render footer-codes index', function () {
/** @var TestCase $this */
$this->get(route('admin.footer-codes.index'))
->assertSuccessful()
->assertSee('Footer-Codes');
});
test('admin can render footer-code create page', function () {
/** @var TestCase $this */
$this->get(route('admin.footer-codes.create'))
->assertSuccessful()
->assertSee('Footer-Code anlegen');
});
test('admin can create a category-bound footer code', function () {
$category = Category::factory()->create();
$category->translations()->createMany([
['locale' => 'de', 'name' => 'Wirtschaft', 'slug' => 'wirtschaft'],
['locale' => 'en', 'name' => 'Business', 'slug' => 'business'],
]);
LivewireVolt::test('admin.footer-codes.create')
->set('title', 'Wirtschafts-Disclaimer')
->set('content', '<p>Powered by Pressekonto</p>')
->set('portal', Portal::Both->value)
->set('language', 'de')
->set('priority', 10)
->set('isGlobal', false)
->set('categoryIds', [$category->id])
->call('save')
->assertHasNoErrors()
->assertRedirect(route('admin.footer-codes.index'));
$code = FooterCode::query()->latest('id')->firstOrFail();
expect($code->title)->toBe('Wirtschafts-Disclaimer');
expect($code->is_global)->toBeFalse();
expect($code->is_active)->toBeTrue();
expect($code->categories->pluck('id')->all())->toBe([$category->id]);
});
test('global footer code ignores category assignment', function () {
$category = Category::factory()->create();
$category->translations()->createMany([
['locale' => 'de', 'name' => 'Tech', 'slug' => 'tech'],
['locale' => 'en', 'name' => 'Tech', 'slug' => 'tech-en'],
]);
LivewireVolt::test('admin.footer-codes.create')
->set('title', 'Globaler Disclaimer')
->set('content', '<p>Hinweis</p>')
->set('isGlobal', true)
->set('categoryIds', [$category->id])
->call('save')
->assertHasNoErrors();
$code = FooterCode::query()->latest('id')->firstOrFail();
expect($code->is_global)->toBeTrue();
expect($code->categories()->count())->toBe(0);
});
test('footer code create requires title and content', function () {
LivewireVolt::test('admin.footer-codes.create')
->set('title', '')
->set('content', '')
->call('save')
->assertHasErrors(['title', 'content']);
});
test('admin can edit and reassign categories of a footer code', function () {
$code = FooterCode::factory()->create([
'title' => 'Alt',
'is_global' => false,
]);
$oldCategory = Category::factory()->create();
$oldCategory->translations()->createMany([
['locale' => 'de', 'name' => 'Alt', 'slug' => 'alt-cat'],
['locale' => 'en', 'name' => 'Old', 'slug' => 'old-cat'],
]);
$code->categories()->sync([$oldCategory->id]);
$newCategory = Category::factory()->create();
$newCategory->translations()->createMany([
['locale' => 'de', 'name' => 'Neu', 'slug' => 'neu-cat'],
['locale' => 'en', 'name' => 'New', 'slug' => 'new-cat'],
]);
LivewireVolt::test('admin.footer-codes.edit', ['id' => $code->id])
->set('title', 'Neu')
->set('content', $code->content)
->set('categoryIds', [$newCategory->id])
->call('save')
->assertHasNoErrors();
$code->refresh();
expect($code->title)->toBe('Neu');
expect($code->categories->pluck('id')->all())->toBe([$newCategory->id]);
});
test('toggling global removes category links on save', function () {
$code = FooterCode::factory()->create(['is_global' => false]);
$category = Category::factory()->create();
$category->translations()->createMany([
['locale' => 'de', 'name' => 'X', 'slug' => 'x-cat'],
['locale' => 'en', 'name' => 'X', 'slug' => 'x-cat-en'],
]);
$code->categories()->sync([$category->id]);
LivewireVolt::test('admin.footer-codes.edit', ['id' => $code->id])
->set('content', $code->content)
->set('isGlobal', true)
->call('save')
->assertHasNoErrors();
$code->refresh();
expect($code->is_global)->toBeTrue();
expect($code->categories()->count())->toBe(0);
});
test('admin can soft-delete a footer code', function () {
$code = FooterCode::factory()->create();
LivewireVolt::test('admin.footer-codes.edit', ['id' => $code->id])
->call('delete')
->assertRedirect(route('admin.footer-codes.index'));
expect(FooterCode::query()->find($code->id))->toBeNull();
expect(FooterCode::withTrashed()->find($code->id))->not->toBeNull();
});
test('admin can toggle footer code activation from index', function () {
$code = FooterCode::factory()->create(['is_active' => true]);
LivewireVolt::test('admin.footer-codes.index')
->call('toggleActive', $code->id);
expect($code->fresh()->is_active)->toBeFalse();
});