Files
laraundfelix/tests/Feature/EditorialEditorTest.php
T
LarsandCursor 053a361801
Deploy Test / test (push) Successful in 22s
Deploy Test / deploy (push) Successful in 23s
Mache Auswahl, Aufbau und Entwurf im Redaktionseditor bedienbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 16:40:50 +01:00

310 lines
14 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentService;
use App\Filament\Pages\EditorialDesk;
use App\Filament\Resources\Courses\CourseResource;
use App\Filament\Resources\Courses\Pages\EditCourse;
use App\Filament\Resources\Exercises\ExerciseResource;
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 EditorialEditorTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
public function test_the_desk_finds_a_program_and_a_module_by_name(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$module = $content->publishComposition(
$content->createComposition('Modul Abstand', CompositionKind::Uebung),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[['role' => 'Modul', 'target' => $module]],
);
$editor = $this->editor();
Livewire::actingAs($editor, 'staff')
->test(EditorialDesk::class)
->assertSee('Programm Abstand')
->assertSee('Modul Abstand')
->set('query', 'Programm')
->assertSee('Programm Abstand')
->assertDontSee('Modul Abstand')
->set('query', 'kein-treffer')
->assertSee('Nichts gefunden');
}
public function test_display_data_does_not_create_a_version_and_a_module_works_without_a_film(): void
{
$editor = $this->editor();
$module = app(ContentService::class)->createComposition('Ohne Film', CompositionKind::Uebung);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->assertSee('Ein Film ist nicht nötig')
->set('displayTitle', 'Sichtbar ohne Film')
->set('summary', 'Nur eine Beschreibung')
->call('saveDisplay')
->assertSet('feedback', 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.')
->set('learningGoal', 'Den Abstand erklären')
->call('publishRevision')
->assertSet('feedback', 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern.')
->set('newTextTitle', 'Hinweis ohne Film')
->set('newTextBody', 'Zuerst den Abstand ansprechen.')
->call('addText')
->call('publishRevision');
$module->refresh();
$this->assertSame('Sichtbar ohne Film', $module->display_title);
$this->assertSame(1, $module->versions()->count());
$this->assertSame('Den Abstand erklären', $module->versions()->first()->learning_goal);
$this->assertSame(1, $module->versions()->first()->members()->count());
}
public function test_reordering_reuses_a_medium_and_keeps_the_released_version(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion(
$content->createElement('text', 'text', 'Trainerunterlage Abstand'),
'Im Kurs zuerst den Abstand ansprechen.',
);
$film = $content->publishElementVersion(
$content->createElement('film', 'film', 'Lara im Park'),
'Film',
);
$firstModule = $content->publishComposition(
$content->createComposition('Modul Abstand', CompositionKind::Uebung),
[
['role' => 'Unterlage', 'target' => $sheet],
['role' => 'Film', 'target' => $film],
],
null,
null,
['learning_goal' => 'Abstand halten', 'duration_minutes' => 15],
);
$secondModule = $content->publishComposition(
$content->createComposition('Modul Hilfe', CompositionKind::Uebung),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$programVersion = $content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[
['role' => 'Modul', 'target' => $firstModule],
['role' => 'Modul', 'target' => $secondModule],
],
);
$editor = $this->editor();
app(CompositionDisplayRelease::class)->release($programVersion, $editor);
app(CompositionDisplayRelease::class)->release($firstModule, $editor);
$component = Livewire::actingAs($editor, 'staff')
->test(EditCourse::class, ['record' => $programVersion->composition_id])
->assertSee('Modul Abstand')
->assertSee('Modul Hilfe');
$members = $component->get('members');
$component->set('members', array_reverse($members))
->call('publishRevision')
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
$versions = $programVersion->composition->versions()->with('members')->orderBy('number')->get();
$this->assertCount(2, $versions);
$this->assertSame($firstModule->id, $versions[0]->members[0]->nested_composition_version_id);
$this->assertSame($secondModule->id, $versions[1]->members[0]->nested_composition_version_id);
$this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[0]));
$this->assertFalse(app(CompositionDisplayRelease::class)->isReleased($versions[1]));
$this->assertSame($sheet->id, $firstModule->members()->first()->content_element_version_id);
$this->assertSame('Im Kurs zuerst den Abstand ansprechen.', $sheet->fresh()->body);
Livewire::actingAs($editor, 'staff')
->test(EditCourse::class, ['record' => $programVersion->composition_id])
->call('releaseDisplay');
$this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[0]->fresh()));
$this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[1]->fresh()));
$this->assertSame(1, $film->element->versions()->count());
$this->actingAs($editor, 'staff')
->get(route('editorial.preview', ['composition' => $programVersion->composition, 'version' => $versions[1]]))
->assertOk()
->assertSee('Vorschau für die Redaktion')
->assertSee('Modul Hilfe')
->assertSee('Lara im Park')
->assertSee('Trainerunterlage Abstand');
}
public function test_a_new_module_returns_into_the_program(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$program = $content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$editor = $this->editor();
$programUrl = CourseResource::getUrl('edit', ['record' => $program->composition]);
$created = Livewire::actingAs($editor, 'staff')
->test(EditCourse::class, ['record' => $program->composition_id])
->set('newModuleName', 'UX-Prüfung Modul')
->call('startModule');
$module = Composition::query()->where('designation', 'UX-Prüfung Modul')->firstOrFail();
$this->assertSame(CompositionKind::Uebung, $module->kind);
$this->actingAs($editor, 'staff')
->get(ExerciseResource::getUrl('edit', ['record' => $module]).'?zurueck='.urlencode('http://example.test/verwaltung/kurse/1'))
->assertOk()
->assertSee('Zurück und einbinden');
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->set('returnUrl', $programUrl)
->set('newTextTitle', 'UX-Prüfung Text')
->set('newTextBody', 'Nur für die Bedienprüfung.')
->call('addText')
->call('returnAndInclude')
->assertRedirect();
$version = $module->versions()->firstOrFail();
$this->actingAs($editor, 'staff')
->get($programUrl.'?uebernehmen=composition:'.$version->id)
->assertOk()
->assertSee('UX-Prüfung Modul')
->assertSee('ist in den Aufbau übernommen');
$this->assertSame(1, $program->composition->versions()->count());
$this->assertSame($sheet->id, $program->fresh()->members()->first()->content_element_version_id);
}
public function test_a_role_change_stays_on_the_selected_part_when_the_order_changes(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Lara im Park'), 'Film');
$program = $content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[
['role' => 'Unterlage', 'target' => $sheet],
['role' => 'Film', 'target' => $film],
],
);
Livewire::actingAs($this->editor(), 'staff')
->test(EditCourse::class, ['record' => $program->composition_id])
->call('selectPart', 1)
->set('roleDraft', 'Film zum Einstieg')
->assertSet('members.0.role', 'Unterlage')
->assertSet('members.1.role', 'Film zum Einstieg')
->call('movePart', 1, -1)
->call('publishRevision')
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
$versions = $program->composition->versions()->with('members')->orderBy('number')->get();
$this->assertCount(2, $versions);
$this->assertSame('Unterlage', $versions[0]->members[0]->role);
$this->assertSame('Film', $versions[0]->members[1]->role);
$this->assertSame('Film zum Einstieg', $versions[1]->members[0]->role);
$this->assertSame($film->id, $versions[1]->members[0]->content_element_version_id);
$this->assertSame('Unterlage', $versions[1]->members[1]->role);
$this->assertSame($sheet->id, $versions[1]->members[1]->content_element_version_id);
}
public function test_saving_a_draft_ten_times_creates_one_version_only_when_released(): void
{
$editor = $this->editor();
$module = app(ContentService::class)->createComposition('Entwurf Modul', CompositionKind::Uebung);
$component = Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->set('newTextTitle', 'Hinweis')
->set('newTextBody', 'Erst der Entwurf.')
->call('addText');
for ($i = 1; $i <= 10; $i++) {
$component->set('learningGoal', 'Durchgang '.$i)->call('saveDraft');
}
$module->refresh();
$this->assertSame(0, $module->versions()->count());
$this->assertSame('Durchgang 10', $module->working_draft['learning_goal']);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->assertSet('learningGoal', 'Durchgang 10')
->call('publishRevision')
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
$module->refresh();
$this->assertSame(1, $module->versions()->count());
$this->assertSame('Durchgang 10', $module->versions()->first()->learning_goal);
$this->assertNull($module->working_draft);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->set('learningGoal', 'Nur Entwurf')
->call('saveDraft');
$module->refresh();
$this->assertSame(1, $module->versions()->count());
$this->assertSame('Durchgang 10', $module->versions()->first()->fresh()->learning_goal);
$this->assertSame('Nur Entwurf', $module->working_draft['learning_goal']);
}
public function test_the_picker_finds_a_film_by_title(): void
{
$content = app(ContentService::class);
$content->publishElementVersion($content->createElement('film', 'film', 'Lara im Park'), 'Film');
$module = $content->createComposition('Picker Modul', CompositionKind::Uebung);
Livewire::actingAs($this->editor(), 'staff')
->test(EditExercise::class, ['record' => $module->id])
->call('openPicker')
->set('pickerQuery', 'Lara')
->assertSee('Lara im Park')
->assertSee('Neuen Text erstellen');
}
public function test_guests_cannot_open_the_trainer_preview(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$version = $content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$this->get(route('editorial.preview', ['composition' => $version->composition, 'version' => $version]))
->assertRedirect();
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
}