Der geöffnete Redaktionsmanager steht in der Adresse (redaktion=1). Zurück und Vor im Browser wechseln innerhalb derselben Komponente; offene Eingaben beider Seiten bleiben erhalten. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
359 lines
15 KiB
PHP
359 lines
15 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\EditorialTextVariant;
|
|
use App\Domain\Catalog\PresentationAssignment;
|
|
use App\Domain\Catalog\PresentationMedia;
|
|
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
|
use App\Filament\Resources\Exercises\Pages\EditExercise;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class VerwaltungArbeitsplatzTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
|
}
|
|
|
|
public function test_redaktion_return_keeps_open_composition_inputs_and_saves_only_editorial_text(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
|
|
$version = $content->publishComposition(
|
|
$content->createComposition('Rueckweg', CompositionKind::Uebung),
|
|
[['role' => 'Unterlage', 'target' => $sheet]],
|
|
);
|
|
$editor = $this->editor();
|
|
|
|
Livewire::actingAs($editor, 'staff')
|
|
->test(EditExercise::class, ['record' => $version->composition_id])
|
|
->call('openPart', 0)
|
|
->set('roleDraft', 'Einstieg')
|
|
->set('learningGoal', 'Grenze erkennen')
|
|
->call('openRedaktion')
|
|
->assertSet('redaktionOpen', true)
|
|
->assertSet('partOpen', false)
|
|
->assertSee('Redaktion speichern')
|
|
->assertSee('Zurück zum Aufbau')
|
|
->assertSee('Präsentationsmedien')
|
|
->assertDontSee('In Mitgliederbibliothek anzeigen')
|
|
->assertDontSee('Vorschau für Trainer')
|
|
->assertSet('roleDraft', 'Einstieg')
|
|
->assertSet('learningGoal', 'Grenze erkennen')
|
|
->set('teaser', 'Kurzer Teaser im Manager')
|
|
->assertSee('Änderungen nicht gespeichert')
|
|
->call('closeRedaktion')
|
|
->assertSet('redaktionOpen', false)
|
|
->assertSee('Die Redaktion hat ungespeicherte Änderungen.')
|
|
->assertSet('teaser', 'Kurzer Teaser im Manager')
|
|
->assertSet('roleDraft', 'Einstieg')
|
|
->assertSet('learningGoal', 'Grenze erkennen')
|
|
->call('saveRedaktion')
|
|
->assertSee('Aufbau, Lernziel, Zeit und Fassungen bleiben unverändert.')
|
|
->assertSet('learningGoal', 'Grenze erkennen');
|
|
|
|
$composition = $version->composition->fresh();
|
|
$this->assertSame('Kurzer Teaser im Manager', $composition->teaser);
|
|
$this->assertSame(1, $composition->versions()->count());
|
|
$this->assertNull($composition->versions()->first()->learning_goal);
|
|
$this->assertSame('Unterlage', $composition->versions()->first()->members()->first()->role);
|
|
}
|
|
|
|
public function test_didactic_dialog_and_draft_discard_do_not_touch_open_redaktion_inputs(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
|
|
$version = $content->publishComposition(
|
|
$content->createComposition('Verdeckt', CompositionKind::Uebung),
|
|
[['role' => 'Unterlage', 'target' => $sheet]],
|
|
);
|
|
|
|
$page = Livewire::actingAs($this->editor(), 'staff')
|
|
->test(EditExercise::class, ['record' => $version->composition_id])
|
|
->call('openRedaktion')
|
|
->set('teaser', 'Noch nicht gespeichert')
|
|
->call('closeRedaktion')
|
|
->call('openModule')
|
|
->set('durationMinutes', '20')
|
|
->call('saveModule')
|
|
->assertSet('teaser', 'Noch nicht gespeichert');
|
|
|
|
$this->assertNull($version->composition->fresh()->teaser);
|
|
|
|
$page->call('discardDraft')
|
|
->assertSet('teaser', 'Noch nicht gespeichert');
|
|
|
|
$this->assertNull($version->composition->fresh()->teaser);
|
|
}
|
|
|
|
public function test_media_redaktion_return_keeps_the_open_version_text(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Lara im Park');
|
|
$content->publishElementVersion($film, 'Filmfassung');
|
|
$editor = $this->editor();
|
|
|
|
Livewire::actingAs($editor, 'staff')
|
|
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->set('bereich', 'inhalt')
|
|
->set('bodyDraft', 'Offener Lehrtext')
|
|
->set('thumbnailAlt', 'Offener Alternativtext')
|
|
->call('openRedaktion')
|
|
->assertSee('Zurück zur Medienbearbeitung')
|
|
->set('teaser', 'Neuer Teaser')
|
|
->call('closeRedaktion')
|
|
->assertSet('redaktionOpen', false)
|
|
->assertSet('bereich', 'inhalt')
|
|
->assertSet('bodyDraft', 'Offener Lehrtext')
|
|
->assertSet('thumbnailAlt', 'Offener Alternativtext')
|
|
->assertSet('teaser', 'Neuer Teaser')
|
|
->call('openRedaktion')
|
|
->assertSet('teaser', 'Neuer Teaser')
|
|
->call('saveRedaktion')
|
|
->call('closeRedaktion')
|
|
->assertSet('thumbnailAlt', 'Offener Alternativtext');
|
|
|
|
$film->refresh();
|
|
$this->assertSame('Neuer Teaser', $film->teaser);
|
|
$this->assertNull($film->thumbnail_alt);
|
|
}
|
|
|
|
public function test_the_redaktion_state_lives_in_the_address_for_browser_back(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Lara im Park');
|
|
$content->publishElementVersion($film, 'Filmfassung');
|
|
|
|
Livewire::actingAs($this->editor(), 'staff')
|
|
->withQueryParams(['redaktion' => '1'])
|
|
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->assertSet('redaktionOpen', true)
|
|
->assertSee('Zurück zur Medienbearbeitung')
|
|
->set('teaser', 'Offen beim Zurückblättern')
|
|
->set('redaktionOpen', false)
|
|
->assertDontSee('Zurück zur Medienbearbeitung')
|
|
->assertSee('Redaktion mit ungespeicherten Änderungen')
|
|
->assertSet('teaser', 'Offen beim Zurückblättern');
|
|
|
|
$this->assertNull($film->fresh()->teaser);
|
|
}
|
|
|
|
public function test_website_release_does_not_save_open_redaktion_inputs(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$image = $content->createElement('bild', 'bild', 'Szenenbild');
|
|
$editor = $this->editor();
|
|
|
|
Livewire::actingAs($editor, 'staff')
|
|
->test(ViewContentElement::class, ['record' => $image->getKey()])
|
|
->call('openRedaktion')
|
|
->set('websiteCredit', 'Offene Quellenzeile')
|
|
->set('teaser', 'Offener Teaser')
|
|
->call('closeRedaktion')
|
|
->set('bereich', 'website')
|
|
->call('releaseForWebsite')
|
|
->assertSet('websiteCredit', 'Offene Quellenzeile')
|
|
->assertSet('teaser', 'Offener Teaser');
|
|
|
|
$image->refresh();
|
|
$this->assertNull($image->website_credit);
|
|
$this->assertNull($image->teaser);
|
|
}
|
|
|
|
public function test_presentation_changes_are_staged_until_redaktion_is_saved(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Lara im Park');
|
|
$content->publishElementVersion($film, 'Filmfassung');
|
|
$first = $this->picture('Galerie eins');
|
|
$second = $this->picture('Galerie zwei');
|
|
|
|
$page = Livewire::actingAs($this->editor(), 'staff')
|
|
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->call('openRedaktion', 'medien')
|
|
->call('openPresentationPicker', 'galerie')
|
|
->call('markPicker', 'medium:'.$first->id, true)
|
|
->call('markPicker', 'medium:'.$second->id, true)
|
|
->set('pickerQuery', 'etwas ganz anderes')
|
|
->assertSet('pickerMarked', ['medium:'.$first->id => 'Galerie eins', 'medium:'.$second->id => 'Galerie zwei'])
|
|
->assertSee('2 Medien übernehmen')
|
|
->call('confirmPicker')
|
|
->assertSet('pickerOpen', false)
|
|
->assertSee('Neu zugeordnet')
|
|
->assertSee('Änderungen nicht gespeichert');
|
|
|
|
$this->assertSame(0, PresentationAssignment::query()->where('subject_id', $film->id)->count());
|
|
|
|
$page->call('saveRedaktion')->assertSee('Alle Änderungen gespeichert');
|
|
|
|
$this->assertSame([$first->id, $second->id], $this->order($film, 'galerie'));
|
|
}
|
|
|
|
public function test_cancelling_the_picker_keeps_the_existing_assignment(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Lara im Park');
|
|
$content->publishElementVersion($film, 'Filmfassung');
|
|
$cover = $this->picture('Titel alt');
|
|
$other = $this->picture('Titel neu');
|
|
app(PresentationMedia::class)->assign($film, 'titelbild', $cover->id, null);
|
|
$key = 'a'.PresentationAssignment::query()->value('id');
|
|
|
|
Livewire::actingAs($this->editor(), 'staff')
|
|
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->call('openRedaktion', 'medien')
|
|
->call('beginExchange', $key)
|
|
->call('markPicker', 'medium:'.$other->id, true)
|
|
->call('closePicker')
|
|
->assertSee('Die vorhandene Zuordnung bleibt unverändert.')
|
|
->assertSee('Alle Änderungen gespeichert');
|
|
|
|
$this->assertSame([$cover->id], $this->order($film, 'titelbild'));
|
|
}
|
|
|
|
public function test_exchange_keeps_the_position_and_reordering_stays_within_its_role(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Lara im Park');
|
|
$content->publishElementVersion($film, 'Filmfassung');
|
|
$one = $this->picture('Bild eins');
|
|
$two = $this->picture('Bild zwei');
|
|
$three = $this->picture('Bild drei');
|
|
$replacement = $this->picture('Bild neu');
|
|
$cover = $this->picture('Titel');
|
|
$media = app(PresentationMedia::class);
|
|
$media->assign($film, 'titelbild', $cover->id, null);
|
|
foreach ([$one, $two, $three] as $image) {
|
|
$media->assign($film, 'galerie', $image->id, null);
|
|
}
|
|
$keyOf = fn (ContentElement $image): string => 'a'.PresentationAssignment::query()->where('content_element_id', $image->id)->value('id');
|
|
|
|
Livewire::actingAs($this->editor(), 'staff')
|
|
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->call('openRedaktion', 'medien')
|
|
->call('beginExchange', $keyOf($two))
|
|
->call('markPicker', 'medium:'.$replacement->id, true)
|
|
->assertSee('Austauschen')
|
|
->call('confirmPicker')
|
|
->assertSee('ersetzt die bisherige Zuordnung an derselben Stelle')
|
|
->call('movePresentation', $keyOf($three), -1)
|
|
->call('movePresentation', $keyOf($one), -1)
|
|
->call('saveRedaktion');
|
|
|
|
$this->assertSame([$one->id, $three->id, $replacement->id], $this->order($film, 'galerie'));
|
|
$this->assertSame([$cover->id], $this->order($film, 'titelbild'));
|
|
$this->assertNotNull($two->fresh(), 'Entfernen einer Zuordnung löscht das Medium nicht.');
|
|
}
|
|
|
|
public function test_removing_an_assignment_keeps_the_medium_and_its_website_release(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Lara im Park');
|
|
$content->publishElementVersion($film, 'Filmfassung');
|
|
$image = $this->picture('Freigegebenes Bild');
|
|
$image->website_released_at = now();
|
|
$image->save();
|
|
app(PresentationMedia::class)->assign($film, 'titelbild', $image->id, null);
|
|
$key = 'a'.PresentationAssignment::query()->value('id');
|
|
|
|
Livewire::actingAs($this->editor(), 'staff')
|
|
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->call('openRedaktion', 'medien')
|
|
->call('removePresentation', $key)
|
|
->assertSee('Änderungen nicht gespeichert')
|
|
->call('saveRedaktion');
|
|
|
|
$this->assertSame(0, PresentationAssignment::query()->where('subject_id', $film->id)->count());
|
|
$this->assertNotNull($image->fresh());
|
|
$this->assertNotNull($image->fresh()->website_released_at);
|
|
}
|
|
|
|
public function test_discarding_the_redaktion_restores_saved_values_only(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Lara im Park');
|
|
$film->teaser = 'Gespeichert';
|
|
$film->save();
|
|
$content->publishElementVersion($film, 'Filmfassung');
|
|
|
|
Livewire::actingAs($this->editor(), 'staff')
|
|
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->set('bodyDraft', 'Offener Lehrtext')
|
|
->call('openRedaktion')
|
|
->set('teaser', 'Verworfen')
|
|
->set('variantBody', 'Nur für die Kachel')
|
|
->call('saveVariant')
|
|
->call('discardRedaktion')
|
|
->assertSet('teaser', 'Gespeichert')
|
|
->assertSet('bodyDraft', 'Offener Lehrtext')
|
|
->assertSee('Alle Änderungen gespeichert');
|
|
|
|
$this->assertSame(0, EditorialTextVariant::query()->count());
|
|
}
|
|
|
|
public function test_a_missing_working_title_is_shown_at_the_field_and_nothing_is_saved(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Lara im Park');
|
|
$content->publishElementVersion($film, 'Filmfassung');
|
|
|
|
Livewire::actingAs($this->editor(), 'staff')
|
|
->test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->call('openRedaktion', 'medien')
|
|
->set('workingTitle', '')
|
|
->set('teaser', 'Bleibt offen')
|
|
->call('saveRedaktion')
|
|
->assertSet('redaktionTab', 'texte')
|
|
->assertSet('redaktionFehlerFeld', 'workingTitle')
|
|
->assertSee('Der Arbeitstitel fehlt.')
|
|
->assertSet('teaser', 'Bleibt offen');
|
|
|
|
$this->assertNull($film->fresh()->teaser);
|
|
$this->assertSame('Lara im Park', $film->fresh()->working_title);
|
|
}
|
|
|
|
private function picture(string $title): ContentElement
|
|
{
|
|
$image = app(ContentService::class)->createElement('bild', 'bild', $title);
|
|
$image->thumbnail_path = 'vorschau/'.md5($title).'.jpg';
|
|
$image->save();
|
|
|
|
return $image;
|
|
}
|
|
|
|
/**
|
|
* @return list<int>
|
|
*/
|
|
private function order(ContentElement $subject, string $role): array
|
|
{
|
|
return PresentationAssignment::query()
|
|
->where('subject_type', $subject->getMorphClass())
|
|
->where('subject_id', $subject->id)
|
|
->whereHas('role', fn ($query) => $query->where('slug', $role))
|
|
->orderBy('position')
|
|
->pluck('content_element_id')
|
|
->map(fn ($id): int => (int) $id)
|
|
->all();
|
|
}
|
|
|
|
private function editor(): User
|
|
{
|
|
$editor = User::factory()->redakteur()->create();
|
|
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
|
|
|
return $editor;
|
|
}
|
|
}
|