CI Feature / test (push) Successful in 2m34s
Eigener Eintrag Übungen unter Inhalte (Bestand, Anlegen, gemeinsamer Aufbau mit Varianten, Verwendung und Variantenauswahl im Modul und Programm), Verwendungsnachweis über verschachtelte und ältere Stände, Auswirkungsbericht einer Mediensperre, gesperrte Bestandteile verhindern die Angebotsaktivierung, Vorschaubilder gesperrter Medien werden nicht mehr ausgeliefert, Rückfalltest gegen die Daten des neuen Stands. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
155 lines
8.0 KiB
PHP
155 lines
8.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\ArticleRelease;
|
|
use App\Domain\Catalog\ArticleService;
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use App\Domain\Catalog\ExerciseUsage;
|
|
use App\Domain\Catalog\OfferService;
|
|
use App\Domain\Entitlement\GrantIssuer;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\Support\BuildsExercises;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Parallele Fassungen und gezielte Mediensperre: Der Verwendungsnachweis steigt bis zu den Ständen auf (auch älteren und
|
|
* verschachtelten), die Sperre wirkt bei der Ausgabe, und der Auswirkungsbericht benennt Variante und Verwendung.
|
|
*/
|
|
class UebungSperreTest extends TestCase
|
|
{
|
|
use BuildsExercises;
|
|
use RefreshDatabase;
|
|
|
|
public function test_the_usage_reaches_nested_and_older_stands(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
$inner = $this->moduleWith('Modul innen', $exercise['version'], ['a']);
|
|
$outer = $this->moduleWith('Programm außen', $inner, null, CompositionKind::Kurs);
|
|
$articles = app(ArticleService::class);
|
|
$article = $articles->create('programm-aussen');
|
|
$first = $articles->publishRelease($article, $outer, 'Erster Stand.');
|
|
$second = $articles->publishRelease($article->fresh(), $outer, 'Zweiter Stand.');
|
|
$direct = $articles->publishRelease($articles->create('modul-innen'), $inner, 'Modul allein.');
|
|
|
|
$usage = app(ExerciseUsage::class)->forComposition($exercise['version']->composition);
|
|
|
|
$this->assertCount(1, $usage);
|
|
$this->assertSame(['Modul innen', 'Programm außen'], array_map(fn (array $host): string => $host['composition']->designation, $usage[0]['hosts']));
|
|
$this->assertSame([['a'], null], array_map(fn (array $host) => $host['selection'], $usage[0]['hosts']));
|
|
|
|
$stands = collect($usage[0]['releases']);
|
|
$this->assertEqualsCanonicalizing([$first->id, $second->id, $direct->id], $stands->map(fn (array $row): int => $row['release']->id)->all());
|
|
$this->assertSame('1-1', $stands->first(fn (array $row): bool => $row['release']->id === $first->id)['path'], 'Zwei Ebenen tief.');
|
|
$this->assertSame('1', $stands->first(fn (array $row): bool => $row['release']->id === $direct->id)['path']);
|
|
$this->assertSame('abgeloest_verfuegbar', $first->fresh()->status->value);
|
|
}
|
|
|
|
public function test_the_impact_of_a_block_names_stand_variant_and_usage(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
$withFilm = $this->moduleWith('Mit Film', $exercise['version'], ['a']);
|
|
$withoutFilm = $this->moduleWith('Ohne Film', $exercise['version'], ['b']);
|
|
$articles = app(ArticleService::class);
|
|
$articles->publishRelease($articles->create('mit-film'), $withFilm, 'Film.');
|
|
$articles->publishRelease($articles->create('ohne-film'), $withoutFilm, 'Ohne Film.');
|
|
|
|
$film = app(ExerciseUsage::class)->blockImpact($exercise['filmA']);
|
|
$this->assertCount(1, $film);
|
|
$this->assertSame('mit-film', $film[0]['article']->code);
|
|
$this->assertSame('a', $film[0]['variant']);
|
|
$this->assertStringContainsString('nicht mehr vollständig durchführbar', $film[0]['effect']);
|
|
|
|
$sheet = app(ExerciseUsage::class)->blockImpact($exercise['sheetB']);
|
|
$this->assertSame('ergaenzend', $sheet[0]['requirement']);
|
|
$this->assertStringContainsString('Nur dieses ergänzende Medium entfällt', $sheet[0]['effect']);
|
|
$this->assertSame([], app(ExerciseUsage::class)->blockImpact($this->film('Unbenutzt')));
|
|
}
|
|
|
|
public function test_a_block_changes_neither_the_frozen_stand_nor_the_usage(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
$module = $this->moduleWith('Modul', $exercise['version'], ['a']);
|
|
$articles = app(ArticleService::class);
|
|
$release = $articles->publishRelease($articles->create('modul'), $module, 'Modul.');
|
|
$before = $release->contents->pluck('content_element_version_id')->all();
|
|
|
|
app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.');
|
|
|
|
$this->assertSame($before, $release->fresh()->contents->pluck('content_element_version_id')->all());
|
|
$this->assertSame('veroeffentlicht', $release->fresh()->status->value);
|
|
$this->assertCount(1, app(ExerciseUsage::class)->blockImpact($exercise['filmA']));
|
|
}
|
|
|
|
public function test_an_offer_with_a_blocked_part_is_not_activated_and_names_it(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
$module = $this->moduleWith('Modul', $exercise['version'], ['a']);
|
|
$articles = app(ArticleService::class);
|
|
$article = $articles->create('modul-angebot');
|
|
$articles->publishRelease($article, $module, 'Modul.');
|
|
app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.');
|
|
|
|
$offers = app(OfferService::class);
|
|
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen'], 'text' => ['ansehen']]);
|
|
|
|
$this->expectException(DomainRuleException::class);
|
|
$this->expectExceptionMessage('gesperrte Bestandteile');
|
|
$offers->activate($offers->create('Angebot'), [['target' => $article->fresh(), 'rights' => $rights]], [
|
|
'grant_kind' => 'auf_abruf',
|
|
'composition_version_id' => $module->id,
|
|
]);
|
|
}
|
|
|
|
public function test_the_preview_picture_of_a_blocked_medium_is_not_served_any_more(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
$element = $exercise['filmA']->element;
|
|
$element->thumbnail_path = 'vorschau/film-a.jpg';
|
|
$element->save();
|
|
$module = $this->moduleWith('Modul', $exercise['version'], ['a']);
|
|
$articles = app(ArticleService::class);
|
|
$article = $articles->create('modul-bild');
|
|
$articles->publishRelease($article, $module, 'Modul.');
|
|
$offers = app(OfferService::class);
|
|
$offer = $offers->create('Bild');
|
|
$offers->activate($offer, [['target' => $article->fresh(), 'rights' => $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']])]], ['grant_kind' => 'auf_abruf']);
|
|
$member = User::factory()->create();
|
|
app(GrantIssuer::class)->claim($member, $offer);
|
|
|
|
$url = route('member.thumbnail', ['kind' => 'element', 'subject' => $element->id]);
|
|
// Erlaubt, aber die Datei fehlt in diesem Test.
|
|
$this->actingAs($member)->get($url)->assertNotFound();
|
|
|
|
app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.');
|
|
|
|
$this->actingAs($member)->get($url)->assertForbidden();
|
|
}
|
|
|
|
public function test_two_versions_of_an_exercise_run_in_parallel_stands(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$exercise = $this->exercise();
|
|
$first = $this->moduleWith('Modul alt', $exercise['version'], ['a']);
|
|
$revised = $content->publishElementVersion($exercise['textA']->element, 'Neuer Wortlaut.');
|
|
$second = $content->publishComposition($exercise['version']->composition, [
|
|
['role' => 'Durchführung A', 'target' => $revised, 'variant' => 'a'],
|
|
['role' => 'Film A', 'target' => $exercise['filmA'], 'variant' => 'a'],
|
|
], null, null, [], [['key' => 'a', 'name' => 'Mit Film']]);
|
|
$newer = $this->moduleWith('Modul neu', $second, ['a']);
|
|
$articles = app(ArticleService::class);
|
|
$articles->publishRelease($articles->create('alt'), $first, 'Alt.');
|
|
$articles->publishRelease($articles->create('neu'), $newer, 'Neu.');
|
|
|
|
$usage = app(ExerciseUsage::class)->forComposition($exercise['version']->composition);
|
|
|
|
$this->assertCount(2, $usage);
|
|
$this->assertSame(['alt'], collect($usage[0]['releases'])->map(fn (array $row) => $row['article']->code)->all());
|
|
$this->assertSame(['neu'], collect($usage[1]['releases'])->map(fn (array $row) => $row['article']->code)->all());
|
|
$this->assertInstanceOf(ArticleRelease::class, $usage[0]['releases'][0]['release']);
|
|
}
|
|
}
|