149 lines
4.8 KiB
PHP
149 lines
4.8 KiB
PHP
<?php
|
|
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Models\AdminPreset;
|
|
use App\Models\PressRelease;
|
|
use App\Models\User;
|
|
use Database\Seeders\RolesAndPermissionsSeeder;
|
|
use Livewire\Volt\Volt as LivewireVolt;
|
|
use Tests\TestCase;
|
|
|
|
test('published press releases are tombstoned instead of soft deleted', function () {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
|
|
$admin = User::factory()->create(['is_active' => true]);
|
|
$admin->assignRole('admin');
|
|
$this->actingAs($admin);
|
|
|
|
$replacementText = 'Diese Meldung wurde redaktionell entfernt.';
|
|
|
|
AdminPreset::factory()->create([
|
|
'key' => AdminPreset::PRESS_RELEASE_DELETED_PUBLISHED_TEXT,
|
|
'area' => 'press_releases',
|
|
'type' => 'text',
|
|
'label' => 'Ersatztext',
|
|
'value' => $replacementText,
|
|
]);
|
|
|
|
$pressRelease = PressRelease::factory()
|
|
->published()
|
|
->create(['text' => 'Alter veröffentlichter Inhalt.']);
|
|
|
|
LivewireVolt::test('admin.press-releases.edit', ['id' => $pressRelease->id])
|
|
->call('deletePressRelease')
|
|
->assertRedirect(route('admin.press-releases.index'));
|
|
|
|
$pressRelease->refresh();
|
|
|
|
expect($pressRelease->deleted_at)->toBeNull()
|
|
->and($pressRelease->status)->toBe(PressReleaseStatus::Archived)
|
|
->and($pressRelease->text)->toBe($replacementText)
|
|
->and($pressRelease->no_export)->toBeTrue();
|
|
});
|
|
|
|
test('unpublished press releases are soft deleted by admin delete action', function () {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
|
|
$admin = User::factory()->create(['is_active' => true]);
|
|
$admin->assignRole('admin');
|
|
$this->actingAs($admin);
|
|
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
]);
|
|
|
|
LivewireVolt::test('admin.press-releases.edit', ['id' => $pressRelease->id])
|
|
->call('deletePressRelease')
|
|
->assertRedirect(route('admin.press-releases.index'));
|
|
|
|
$this->assertSoftDeleted($pressRelease);
|
|
});
|
|
|
|
test('edit page renders status selector and confirmation modal', function () {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
|
|
$admin = User::factory()->create(['is_active' => true]);
|
|
$admin->assignRole('admin');
|
|
$this->actingAs($admin);
|
|
|
|
$pressRelease = PressRelease::factory()
|
|
->inReview()
|
|
->create();
|
|
|
|
LivewireVolt::test('admin.press-releases.edit', ['id' => $pressRelease->id])
|
|
->assertSee('Neuer Status')
|
|
->assertSee('Status wechseln')
|
|
->assertSee('Status wirklich wechseln?')
|
|
->assertSee('Pressemitteilung löschen?');
|
|
});
|
|
|
|
test('admin can change archived press release back to another status', function () {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
|
|
$admin = User::factory()->create(['is_active' => true]);
|
|
$admin->assignRole('admin');
|
|
$this->actingAs($admin);
|
|
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'status' => PressReleaseStatus::Archived->value,
|
|
]);
|
|
|
|
LivewireVolt::test('admin.press-releases.edit', ['id' => $pressRelease->id])
|
|
->set('targetStatus', PressReleaseStatus::Draft->value)
|
|
->call('changeStatus')
|
|
->assertHasNoErrors();
|
|
|
|
$pressRelease->refresh();
|
|
|
|
expect($pressRelease->status)->toBe(PressReleaseStatus::Draft);
|
|
});
|
|
|
|
test('press release index renders confirmation modals for status actions', function () {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
|
|
$admin = User::factory()->create(['is_active' => true]);
|
|
$admin->assignRole('admin');
|
|
$this->actingAs($admin);
|
|
|
|
PressRelease::factory()
|
|
->inReview()
|
|
->create(['title' => 'PM in Prüfung']);
|
|
|
|
PressRelease::factory()
|
|
->published()
|
|
->create(['title' => 'Veröffentlichte PM']);
|
|
|
|
LivewireVolt::test('admin.press-releases.index')
|
|
->assertSee('Pressemitteilung veröffentlichen?')
|
|
->assertSee('Pressemitteilung ablehnen?')
|
|
->assertSee('Pressemitteilung archivieren?');
|
|
});
|
|
|
|
test('show page renders confirmation modals for status actions', function () {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
|
|
$admin = User::factory()->create(['is_active' => true]);
|
|
$admin->assignRole('admin');
|
|
$this->actingAs($admin);
|
|
|
|
$reviewPressRelease = PressRelease::factory()
|
|
->inReview()
|
|
->create();
|
|
|
|
LivewireVolt::test('admin.press-releases.show', ['id' => $reviewPressRelease->id])
|
|
->assertSee('Pressemitteilung veröffentlichen?')
|
|
->assertSee('Pressemitteilung ablehnen?');
|
|
|
|
$publishedPressRelease = PressRelease::factory()
|
|
->published()
|
|
->create();
|
|
|
|
LivewireVolt::test('admin.press-releases.show', ['id' => $publishedPressRelease->id])
|
|
->assertSee('Pressemitteilung archivieren?');
|
|
});
|