CI Feature / test (push) Successful in 3m32s
Neuer kind 'exercise', Varianten je Fassung, Verwendung (erforderlich/ergänzend) und Variantenauswahl am einbindenden Mitglied; der Stand schreibt nur gewählte Varianten fest. Änderungsnachweis über structure_hash. Formatierte Anleitung im Mitgliederbereich und PDF (Fußzeile, Metadaten, Ausgabenachweis, keine gespeicherten Kopien); Sperre trifft nur das Medium. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
167 lines
8.7 KiB
PHP
167 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\ArticleService;
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Domain\Catalog\ContentResolver;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\Support\BuildsExercises;
|
|
use Tests\TestCase;
|
|
|
|
class UebungFassungTest extends TestCase
|
|
{
|
|
use BuildsExercises;
|
|
use RefreshDatabase;
|
|
|
|
public function test_an_exercise_version_keeps_its_fields_variants_and_placement(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
$version = $exercise['version']->fresh(['variants', 'members.variant']);
|
|
|
|
$this->assertSame(CompositionKind::Exercise, $version->composition->kind);
|
|
$this->assertSame(['a', 'b'], $version->variants->pluck('key')->all());
|
|
$this->assertSame(20, $version->duration_max);
|
|
$this->assertSame('Keine', $version->prerequisites);
|
|
$this->assertNull($version->members[0]->variant, 'Der Einstieg ist gemeinsam.');
|
|
$this->assertSame('a', $version->members[2]->variant->key);
|
|
$this->assertSame('ergaenzend', $version->members[4]->requirement);
|
|
$this->assertNotNull($version->structure_hash);
|
|
$this->assertSame($version->structure_hash, $version->attestations()->first()->structure_hash);
|
|
}
|
|
|
|
public function test_the_selection_decides_which_media_a_stand_freezes(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
$withFilm = $this->moduleWith('Modul mit Film', $exercise['version'], ['a']);
|
|
$withoutFilm = $this->moduleWith('Modul ohne Film', $exercise['version'], ['b']);
|
|
$articles = app(ArticleService::class);
|
|
$first = $articles->publishRelease($articles->create('mit-film'), $withFilm, 'Filmvariante.');
|
|
$second = $articles->publishRelease($articles->create('ohne-film'), $withoutFilm, 'Variante ohne Film.');
|
|
|
|
$this->assertEqualsCanonicalizing(
|
|
[$exercise['intro']->id, $exercise['textA']->id, $exercise['filmA']->id],
|
|
$first->contents->pluck('content_element_version_id')->all(),
|
|
);
|
|
$this->assertEqualsCanonicalizing(
|
|
[$exercise['intro']->id, $exercise['textB']->id, $exercise['sheetB']->id],
|
|
$second->contents->pluck('content_element_version_id')->all(),
|
|
);
|
|
$this->assertSame(
|
|
['erforderlich', 'ergaenzend'],
|
|
$second->contents->whereIn('content_element_version_id', [$exercise['textB']->id, $exercise['sheetB']->id])->sortBy('position')->pluck('requirement')->map(fn ($r, $i) => $i === 0 ? 'erforderlich' : $r)->values()->all(),
|
|
);
|
|
$this->assertSame('ergaenzend', $second->contents->firstWhere('content_element_version_id', $exercise['sheetB']->id)->requirement);
|
|
$this->assertSame('b', $second->contents->firstWhere('content_element_version_id', $exercise['sheetB']->id)->variant_key);
|
|
$this->assertNull($second->contents->firstWhere('content_element_version_id', $exercise['intro']->id)->variant_key);
|
|
}
|
|
|
|
public function test_without_a_selection_all_variants_are_offered(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
$all = $this->moduleWith('Modul mit allen', $exercise['version']);
|
|
|
|
$this->assertCount(5, app(ContentResolver::class)->expand($all));
|
|
}
|
|
|
|
public function test_the_same_medium_in_the_common_part_and_a_variant_and_directly_in_the_product_is_frozen_each_time(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $this->film('Demonstration');
|
|
$composition = $this->exerciseComposition('Doppelt');
|
|
$exercise = $content->publishComposition($composition, [
|
|
['role' => 'Einstieg', 'target' => $film],
|
|
['role' => 'Film in A', 'target' => $film, 'variant' => 'a'],
|
|
['role' => 'Film in B', 'target' => $film, 'variant' => 'b'],
|
|
], null, null, [], [['key' => 'a', 'name' => 'A'], ['key' => 'b', 'name' => 'B']]);
|
|
$module = $this->moduleWith('Modul', $exercise, ['a'], CompositionKind::Uebung, $film);
|
|
$articles = app(ArticleService::class);
|
|
$release = $articles->publishRelease($articles->create('doppelt'), $module, 'Mehrfach.');
|
|
|
|
$this->assertSame([$film->id, $film->id, $film->id], $release->contents->pluck('content_element_version_id')->all());
|
|
$this->assertSame([null, 'a', null], $release->contents->pluck('variant_key')->all());
|
|
}
|
|
|
|
public function test_the_structure_hash_notices_what_the_media_set_does_not(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $this->film('Gleicher Film');
|
|
$composition = $this->exerciseComposition('Hash');
|
|
$variants = [['key' => 'a', 'name' => 'A']];
|
|
$first = $content->publishComposition($composition, [['role' => 'Film', 'target' => $film, 'variant' => 'a', 'requirement' => 'erforderlich']], null, null, [], $variants);
|
|
$second = $content->publishComposition($composition, [['role' => 'Film', 'target' => $film, 'variant' => 'a', 'requirement' => 'ergaenzend']], null, null, [], $variants);
|
|
$third = $content->publishComposition($composition, [['role' => 'Film', 'target' => $film]], null, null, [], $variants);
|
|
|
|
$this->assertSame($first->resolved_hash, $second->resolved_hash);
|
|
$this->assertSame($first->resolved_hash, $third->resolved_hash);
|
|
$this->assertCount(3, array_unique([$first->structure_hash, $second->structure_hash, $third->structure_hash]));
|
|
}
|
|
|
|
public function test_two_stands_keep_different_versions_of_the_same_exercise(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$exercise = $this->exercise();
|
|
$moduleV1 = $this->moduleWith('Modul eins', $exercise['version'], ['a']);
|
|
$revisedText = $content->publishElementVersion($exercise['textA']->element, 'Variante A, überarbeitet.');
|
|
$secondVersion = $content->publishComposition($exercise['version']->composition, [
|
|
['role' => 'Einstieg', 'target' => $exercise['intro']],
|
|
['role' => 'Durchführung A', 'target' => $revisedText, 'variant' => 'a'],
|
|
['role' => 'Film A', 'target' => $exercise['filmA'], 'variant' => 'a'],
|
|
], null, null, ['learning_goal' => 'Neu gefasst'], [['key' => 'a', 'name' => 'Mit Film']]);
|
|
$moduleV2 = $this->moduleWith('Modul zwei', $secondVersion, ['a']);
|
|
|
|
$articles = app(ArticleService::class);
|
|
$one = $articles->publishRelease($articles->create('eins'), $moduleV1, 'Alte Übung.');
|
|
$two = $articles->publishRelease($articles->create('zwei'), $moduleV2, 'Neue Übung.');
|
|
|
|
$this->assertContains($exercise['textA']->id, $one->contents->pluck('content_element_version_id')->all());
|
|
$this->assertNotContains($revisedText->id, $one->contents->pluck('content_element_version_id')->all());
|
|
$this->assertContains($revisedText->id, $two->contents->pluck('content_element_version_id')->all());
|
|
$this->assertSame('Nein sagen und Abstand halten', $exercise['version']->fresh()->learning_goal);
|
|
$this->assertSame(2, $exercise['version']->composition->versions()->count());
|
|
}
|
|
|
|
public function test_a_published_exercise_version_and_its_variants_stay_unchanged(): void
|
|
{
|
|
$exercise = $this->exercise();
|
|
|
|
$this->expectException(DomainRuleException::class);
|
|
$exercise['version']->variants()->first()->update(['name' => 'Anders']);
|
|
}
|
|
|
|
public function test_invalid_placements_are_refused(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $this->film('Film');
|
|
$composition = $this->exerciseComposition('Prüfung');
|
|
$variants = [['key' => 'a', 'name' => 'A']];
|
|
|
|
foreach ([
|
|
[['role' => 'x', 'target' => $film, 'variant' => 'zzz'], $variants],
|
|
[['role' => 'x', 'target' => $film, 'requirement' => 'vielleicht'], $variants],
|
|
[['role' => 'x', 'target' => $film, 'selection' => ['a']], $variants],
|
|
] as [$member, $declared]) {
|
|
try {
|
|
$content->publishComposition($composition, [$member], null, null, [], $declared);
|
|
$this->fail('Eine ungültige Zuordnung wurde angenommen.');
|
|
} catch (DomainRuleException) {
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
}
|
|
|
|
$exercise = $this->exercise('Andere');
|
|
$module = $this->exerciseComposition('Wirt');
|
|
|
|
foreach ([['zzz'], []] as $selection) {
|
|
try {
|
|
$content->publishComposition($module, [['role' => 'Übung', 'target' => $exercise['version'], 'selection' => $selection]]);
|
|
$this->fail('Eine ungültige Variantenauswahl wurde angenommen.');
|
|
} catch (DomainRuleException) {
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
}
|
|
}
|
|
}
|