Files
laraundfelix/tests/Feature/PillarUnificationTest.php
T
LarsandClaude Sonnet 5.5 7c48a6480c
CI Feature / test (push) Successful in 1m34s
Deploy Test / test (push) Successful in 1m29s
Deploy Test / deploy (push) Successful in 29s
Vereinheitliche die fachlichen Säulen auf die zentrale Säulenverwaltung
Module, Programme und Lizenzartikel verwenden wie Medien und Seiten die Tabelle
pillars; die Kopie „Fachliche Säule“ in den redaktionellen Dimensionen wird nirgends
mehr angeboten, geändert oder gefiltert und bleibt nur als Verlauf erhalten.

- Migration (nur Ergänzungen): composition_pillar und license_article_pillar mit
  restrictOnDelete, pillar_id an den alten Dimensionswerten als dokumentierte
  Abbildung, einmalige wiederholbare Übernahme (LegacyPillarAdoption).
- Übernahme nur über die gespeicherte Kennung pfeiler-<Nummer> und nur direkte
  Zuordnungen; mehrdeutige, abgeleitete und verwaiste Fälle werden gemeldet, nicht
  geraten. Medien bleiben bei ihrer Zuordnung. Alte Zeilen bleiben unverändert.
  Befehl: php artisan luf:saeulen-uebernehmen [--dry-run].
- Editoren von Modul, Programm und Lizenzartikel wählen Säulen aus der Säulenverwaltung;
  PillarService::assign gilt für alle Objektarten, Löschschutz zählt alle Objektarten.
- Filter: Module und Programme, Aufbau-Picker und Mitgliederbibliothek nach der
  Säulenzuordnung; alte Adressen mit einem Säulenwert der Einordnung folgen der Säule.
- Abgeleitete Säulen (aus enthaltenen Medien) bleiben getrennt von direkten.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 10:11:42 +01:00

463 lines
27 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\EditorialVocabulary;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\LegacyPillarAdoption;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarService;
use App\Domain\Cms\Page;
use App\Domain\Entitlement\GrantIssuer;
use App\Filament\Pages\RedaktionelleStammdaten;
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
use App\Filament\Resources\Courses\Pages\EditCourse;
use App\Filament\Resources\Exercises\Pages\EditExercise;
use App\Filament\Resources\Exercises\Pages\ListExercises;
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
use App\Filament\Resources\Pillars\Pages\ListPillars;
use App\Filament\Support\CatalogReading;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Fachliche Säulen aus einer Quelle: Die zentrale Säulenverwaltung (`pillars`) gilt für Medien, Module, Programme,
* Lizenzartikel und Seiten. Die frühere Kopie als Dimension „Fachliche Säule“ bleibt nur als Verlauf erhalten und wird
* verlustfrei und wiederholbar übernommen.
*/
class PillarUnificationTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
protected function tearDown(): void
{
Carbon::setTestNow();
parent::tearDown();
}
public function test_a_central_pillar_is_chosen_for_modules_programs_and_license_articles_without_publishing_anything(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs);
$article = app(ArticleService::class)->create('artikel-abstand');
$pillar = app(PillarService::class)->create('Meine Grenzen');
$editor = $this->editor();
$keeper = $this->keeper();
Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Fachliche Säulen')->assertSee('Meine Grenzen')
->set('pillarIds', [(string) $pillar->id])->call('saveDisplay')->assertSet('feedbackError', false);
Livewire::actingAs($editor, 'staff')->test(EditCourse::class, ['record' => $program->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Meine Grenzen')
->set('pillarIds', [(string) $pillar->id])->call('saveDisplay');
Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Meine Grenzen')
->set('pillarIds', [(string) $pillar->id])->call('saveLicenseEditorial');
$this->assertSame([$pillar->id], $module->fresh()->pillars->pluck('id')->all());
$this->assertSame([$pillar->id], $program->fresh()->pillars->pluck('id')->all());
$this->assertSame([$pillar->id], $article->fresh()->pillars->pluck('id')->all());
$this->assertNull($pillar->fresh()->published_at, 'Anlegen und Zuordnen veröffentlicht keine Themenseite.');
}
public function test_renaming_a_pillar_shows_the_new_name_everywhere_and_keeps_every_assignment(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$article = app(ArticleService::class)->create('artikel-abstand');
$film = $content->createElement('film', 'film', 'Lara im Park');
$pillar = app(PillarService::class)->create('Nähe');
foreach ([$module, $article, $film] as $subject) {
app(PillarService::class)->assign($subject, [$pillar->id]);
}
$editor = $this->editor();
$keeper = $this->keeper();
app(PillarService::class)->present($pillar, 'Nähe und Distanz', $pillar->slug, null, false, 0);
Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Nähe und Distanz')->assertSet('pillarIds', [(string) $pillar->id]);
Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->call('openRedaktion', 'einordnung')->assertSee('Nähe und Distanz')->assertSet('pillarIds', [(string) $pillar->id]);
Livewire::actingAs($editor, 'staff')->test(ListExercises::class)->assertOk();
Livewire::withQueryParams(['saeule' => (string) $pillar->id])->actingAs($editor, 'staff')
->test(ListContentElements::class)->assertSee('Lara im Park');
Livewire::actingAs($editor, 'staff')->test(ListPillars::class)->assertSee('Nähe und Distanz')->assertSee('1 Medium, 1 Modul oder Programm, 1 Lizenzartikel');
$this->assertSame($pillar->id, $module->pillars()->value('pillars.id'));
$this->assertSame($pillar->id, $article->pillars()->value('pillars.id'));
$this->assertSame($pillar->id, $film->pillars()->value('pillars.id'));
}
public function test_saving_other_details_keeps_the_pillar_assignments(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$article = app(ArticleService::class)->create('artikel-abstand');
$first = app(PillarService::class)->create('Eins');
$second = app(PillarService::class)->create('Zwei');
app(PillarService::class)->assign($module, [$first->id, $second->id]);
app(PillarService::class)->assign($article, [$second->id]);
$editor = $this->editor();
$keeper = $this->keeper();
Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])
->set('teaser', 'Nur der Teaser ändert sich.')->call('saveDisplay');
Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->call('openRedaktion')->set('summary', 'Nur die Beschreibung ändert sich.')->call('saveLicenseEditorial');
$this->assertEqualsCanonicalizing([$first->id, $second->id], $module->fresh()->pillars->pluck('id')->all());
$this->assertSame([$second->id], $article->fresh()->pillars->pluck('id')->all());
$this->assertSame('Nur der Teaser ändert sich.', $module->fresh()->teaser);
// Gezieltes Abwählen entfernt genau diese Säule.
Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])
->set('pillarIds', [(string) $second->id])->call('saveDisplay');
$this->assertSame([$second->id], $module->fresh()->pillars->pluck('id')->all());
}
public function test_the_adoption_carries_every_direct_assignment_over_and_is_repeatable(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs);
$article = app(ArticleService::class)->create('artikel-abstand');
$film = $content->createElement('film', 'film', 'Lara im Park');
$nahe = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']);
$mut = Pillar::query()->create(['name' => 'Mut', 'slug' => 'mut']);
$nahe->refresh();
$nearValue = $this->legacyValue($nahe, 'Nähe');
$courageValue = $this->legacyValue($mut, 'Mut (alter Name)');
$identity = app(IdentityDimension::class);
$identity->assign($module, $nearValue);
$identity->assign($module, $courageValue);
$identity->assign($program, $nearValue);
$identity->assign($article, $courageValue);
$identity->assign($film, $nearValue);
// Medien: maßgeblich ist die Medienzuordnung, die Spiegelzeile wird nicht zurückgemischt.
app(PillarService::class)->assign($film, [$mut->id]);
$legacyBefore = IdentityDimensionValue::query()->count();
$report = (new LegacyPillarAdoption)->run();
$this->assertEqualsCanonicalizing([$nahe->id, $mut->id], $module->pillars()->pluck('pillars.id')->all());
$this->assertSame([$nahe->id], $program->pillars()->pluck('pillars.id')->all());
$this->assertSame([$mut->id], $article->pillars()->pluck('pillars.id')->all());
$this->assertSame([$mut->id], $film->pillars()->pluck('pillars.id')->all(), 'Die Medienzuordnung bleibt maßgeblich.');
$this->assertSame(['composition' => 3, 'license_article' => 1], $report['copied']);
$this->assertSame([], $report['unresolved']);
$this->assertSame($nahe->id, $nearValue->fresh()->pillar_id);
$this->assertSame($mut->id, $courageValue->fresh()->pillar_id);
$this->assertSame($legacyBefore, IdentityDimensionValue::query()->count(), 'Alte Zeilen bleiben unverändert erhalten.');
$this->assertSame(1, $report['mirror']['element_rows'], 'Eine gespiegelte Medienzeile wird nur gezählt.');
$this->assertSame(1, $report['mirror']['missing_in_pivot']);
$this->assertTrue(collect($report['mapping'])->contains(fn (array $row): bool => $row['wert_id'] === $courageValue->id && str_contains((string) $row['hinweis'], 'Bezeichnung weicht ab')));
$again = (new LegacyPillarAdoption)->run();
$this->assertSame(['composition' => 0, 'license_article' => 0], $again['copied']);
$this->assertSame(['composition' => 3, 'license_article' => 1], $again['already']);
$this->assertSame(4, DB::table('composition_pillar')->count() + DB::table('license_article_pillar')->count());
$dry = (new LegacyPillarAdoption)->run(dryRun: true);
$this->assertSame(4, $dry['before']['composition'] + $dry['before']['license_article']);
}
public function test_ambiguous_old_values_are_reported_and_never_assigned_by_guessing(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs);
$article = app(ArticleService::class)->create('artikel-abstand');
$film = $content->createElement('film', 'film', 'Lara im Park');
$nahe = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']);
$good = $this->legacyValue($nahe, 'Nähe');
// Gleicher Name, aber ohne Kennung zur Säule: ähnlich klingend ist kein Nachweis.
$sameName = $this->legacyValue($nahe, 'Nähe', slug: 'naehe-kopie');
// Kennung verweist auf eine Säule, die es nicht mehr gibt.
$gone = $this->legacyValue($nahe, 'Verschwunden', slug: 'pfeiler-9999');
$identity = app(IdentityDimension::class);
$identity->assign($module, $good);
$identity->assign($module, $sameName);
$identity->assign($program, $gone);
$identity->assign($article, $good, 'abgeleitet');
$identity->assign($film, $sameName);
DB::table('identity_dimension_values')->insert([
'subject_type' => $module->getMorphClass(), 'subject_id' => 99999, 'editorial_dimension_value_id' => $good->id,
'origin' => 'direkt', 'created_at' => now(), 'updated_at' => now(),
]);
$report = (new LegacyPillarAdoption)->run();
$this->assertSame([$nahe->id], $module->pillars()->pluck('pillars.id')->all(), 'Nur der belastbare Wert wird übernommen.');
$this->assertSame([], $program->pillars()->pluck('pillars.id')->all());
$this->assertSame([], $article->pillars()->pluck('pillars.id')->all(), 'Eine abgeleitete Zuordnung wird nicht zur direkten.');
$this->assertNull($sameName->fresh()->pillar_id);
$this->assertNull($gone->fresh()->pillar_id);
$reasons = collect($report['unresolved'])->pluck('grund')->implode(' | ');
$this->assertStringContainsString('keine belastbare Verknüpfung', $reasons);
$this->assertStringContainsString('existiert nicht mehr', $reasons);
$this->assertStringContainsString('abgeleitete Zuordnung', $reasons);
$this->assertStringContainsString('Objekt nicht mehr vorhanden', $reasons);
$this->assertStringContainsString('Wert ohne belastbare Säule', $reasons);
$lines = implode("\n", LegacyPillarAdoption::lines($report));
$this->assertStringContainsString('Ungeklärt, bitte entscheiden', $lines);
$this->assertStringContainsString('naehe-kopie', $lines);
$this->assertSame(1, DB::table('identity_dimension_values')->where('origin', 'abgeleitet')->count(), 'Nichts wurde gelöscht.');
$this->artisan('luf:saeulen-uebernehmen', ['--dry-run' => true])->assertFailed();
}
public function test_a_pillar_younger_than_the_old_value_is_not_a_reliable_reference(): void
{
Carbon::setTestNow('2026-11-16 08:00:00');
$value = $this->legacyValue(Pillar::query()->create(['name' => 'Alt', 'slug' => 'alt']), 'Alt', slug: 'pfeiler-2');
Carbon::setTestNow('2026-11-20 08:00:00');
Pillar::query()->create(['id' => 2, 'name' => 'Später angelegt', 'slug' => 'spaeter']);
$report = (new LegacyPillarAdoption)->run();
$this->assertNull($value->fresh()->pillar_id);
$this->assertStringContainsString('jünger', (string) ($report['unresolved'][0]['grund'] ?? ''));
}
public function test_direct_and_derived_pillars_keep_their_own_meaning(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']);
$module = $content->createComposition('Modul Hof', CompositionKind::Uebung);
$content->publishComposition($module, [['role' => 'Film', 'target' => $film]]);
$fromMedia = app(PillarService::class)->create('Aus dem Medium');
$direct = app(PillarService::class)->create('Direkt am Modul');
app(PillarService::class)->assign($film->element, [$fromMedia->id]);
app(PillarService::class)->assign($module, [$direct->id]);
$derived = app(CatalogReading::class)->memberPillars($module);
$this->assertSame(['Hofszene — Aus dem Medium'], array_map(fn (string $line): string => str_replace('Film: ', '', $line), $derived));
$this->assertSame([$direct->id], $module->pillars()->pluck('pillars.id')->all(), 'Die Säule des Mediums wird nicht zur direkten Zuordnung des Moduls.');
$editor = $this->editor();
Livewire::withQueryParams(['saeule' => (string) $fromMedia->id])->actingAs($editor, 'staff')
->test(ListExercises::class)->assertDontSee('Modul Hof');
Livewire::withQueryParams(['saeule' => (string) $direct->id])->actingAs($editor, 'staff')
->test(ListExercises::class)->assertSee('Modul Hof');
}
public function test_filters_find_exactly_the_assigned_objects_and_old_addresses_follow_the_pillar(): void
{
$content = app(ContentService::class);
$withPillar = $content->createComposition('Mit Säule', CompositionKind::Uebung);
$content->createComposition('Ohne Säule', CompositionKind::Uebung);
$pillar = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']);
$value = $this->legacyValue($pillar, 'Nähe');
app(PillarService::class)->assign($withPillar, [$pillar->id]);
(new LegacyPillarAdoption)->run();
$editor = $this->editor();
Livewire::withQueryParams(['saeule' => (string) $pillar->id])->actingAs($editor, 'staff')->test(ListExercises::class)
->assertSee('Mit Säule')->assertDontSee('Ohne Säule');
// Alte Adresse mit dem früheren Säulenwert der Einordnung.
Livewire::withQueryParams(['pillar' => (string) $value->id])->actingAs($editor, 'staff')->test(ListExercises::class)
->assertSet('saeule', (string) $pillar->id)->assertSet('pillar', '')->assertSee('Mit Säule')->assertDontSee('Ohne Säule');
Livewire::withQueryParams(['einordnung' => (string) $value->id])->actingAs($editor, 'staff')->test(ListContentElements::class)
->assertSet('saeule', (string) $pillar->id)->assertSet('einordnung', '');
// Der Picker im Aufbau filtert Medien und Module nach der Säule.
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Film mit Säule'), 'Film');
$content->publishElementVersion($content->createElement('film', 'film', 'Film ohne Säule'), 'Film');
app(PillarService::class)->assign($film->element, [$pillar->id]);
$picker = Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $withPillar->getKey()])
->call('openPicker');
$this->assertSame($pillar->name, $picker->instance()->pickerSaeulen()[(string) $pillar->id]);
$ids = fn (array $items): array => array_column($items, 'title');
$picker->set('pickerKind', 'film');
$this->assertContains('Film ohne Säule', $ids($picker->instance()->pickerResult()['items']), 'Ohne Filter erscheinen beide.');
$picker->set('pickerSaeule', (string) $pillar->id);
$this->assertSame(['Film mit Säule'], array_values(array_filter($ids($picker->instance()->pickerResult()['items']), fn ($t) => str_starts_with((string) $t, 'Film '))));
}
public function test_a_used_pillar_cannot_be_deleted_by_the_service_or_the_database(): void
{
$content = app(ContentService::class);
$service = app(PillarService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$article = app(ArticleService::class)->create('artikel-abstand');
$byModule = $service->create('Durch Modul');
$byArticle = $service->create('Durch Artikel');
$service->assign($module, [$byModule->id]);
$service->assign($article, [$byArticle->id]);
foreach ([$byModule, $byArticle] as $pillar) {
try {
$service->delete($pillar);
$this->fail('Eine verwendete Säule darf nicht gelöscht werden.');
} catch (DomainRuleException $exception) {
$this->assertStringContainsString('zugeordneten Objekten', $exception->getMessage());
}
}
$this->assertStringContainsString('1 Modul oder Programm', $service->usageText($service->usage($byModule)));
$this->assertStringContainsString('1 Lizenzartikel', $service->usageText($service->usage($byArticle)));
// Auch ein Zugriff an der Anwendung vorbei scheitert in der Datenbank.
$this->expectException(QueryException::class);
DB::table('pillars')->where('id', $byModule->id)->delete();
}
public function test_pillar_assignment_follows_the_editorial_permissions(): void
{
$content = app(ContentService::class);
$module = $content->createComposition('Modul Abstand', CompositionKind::Uebung);
$article = app(ArticleService::class)->create('artikel-abstand');
$pillar = app(PillarService::class)->create('Nähe');
$moderator = User::factory()->systemverwalter()->create();
$moderator->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
Livewire::actingAs($moderator, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])->assertForbidden();
Livewire::actingAs($moderator, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])->assertForbidden();
Livewire::actingAs($moderator, 'staff')->test(ListPillars::class)->assertForbidden();
$this->assertSame([], $module->pillars()->pluck('pillars.id')->all());
$this->assertNotNull($pillar->fresh());
}
public function test_the_stammdaten_workplace_points_to_the_pillar_management_and_offers_no_pillar_copy(): void
{
Livewire::actingAs($this->editor(), 'staff')->test(RedaktionelleStammdaten::class)
->assertSee('Fachliche Säulen')
->assertSee(route('filament.verwaltung.resources.saeulen.index', [], false), false);
$this->assertArrayNotHasKey(EditorialDimension::PILLAR_SLUG, (new RedaktionelleStammdaten)->gruppen());
foreach ([Composition::class, LicenseArticle::class] as $class) {
$this->assertNotContains(EditorialDimension::PILLAR_SLUG, EditorialDimension::forSubject(new $class)->pluck('slug')->all());
}
$vocabulary = app(EditorialVocabulary::class);
$this->legacyValue(Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']), 'Nähe');
$this->assertNotContains('Fachliche Säule', array_column($vocabulary->dimensionFilterGroups(), 'label'));
$this->assertNotContains('Fachliche Säule', $vocabulary->memberFilterDimensions()->pluck('label')->all());
}
public function test_the_member_library_filters_by_direct_pillars_and_lists_only_used_ones(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']);
$withPillar = $content->publishComposition($content->createComposition('Schulweg mit Säule'), [['role' => 'Film', 'target' => $film]]);
$without = $content->publishComposition($content->createComposition('Schulweg ohne Säule'), [['role' => 'Film', 'target' => $film]]);
$pillar = app(PillarService::class)->create('Sicher unterwegs');
$unused = app(PillarService::class)->create('Noch ohne Zuordnung');
app(PillarService::class)->assign($withPillar->composition, [$pillar->id]);
$articles = app(ArticleService::class);
$offers = app(OfferService::class);
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]);
$offer = $offers->create('Zugang');
$items = [];
foreach ([[$withPillar, 'mit'], [$without, 'ohne']] as [$version, $code]) {
$article = $articles->create($code);
$articles->publishRelease($article, $version, 'Text');
$items[] = ['target' => $article->fresh(), 'rights' => $rights];
}
$offers->activate($offer, $items, ['grant_kind' => 'auf_abruf']);
$member = User::factory()->create();
app(GrantIssuer::class)->claim($member, $offer);
foreach ([$withPillar, $without] as $version) {
app(CompositionDisplayRelease::class)->release($version, $member);
}
$this->actingAs($member)->get(route('member.library'))
->assertOk()->assertSee('Schulweg mit Säule')->assertSee('Schulweg ohne Säule')
->assertSee('Fachliche Säulen')->assertSee('Sicher unterwegs')->assertDontSee('Noch ohne Zuordnung');
$this->actingAs($member)->get(route('member.library', ['saeule' => [$pillar->id]]))
->assertOk()->assertSee('Schulweg mit Säule')->assertDontSee('Schulweg ohne Säule');
$this->assertNotNull($unused->fresh());
}
public function test_published_pages_and_saved_versions_stay_unchanged_by_the_adoption(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']);
$module = $content->createComposition('Modul Hof', CompositionKind::Uebung);
$version = $content->publishComposition($module, [['role' => 'Film', 'target' => $film]]);
$pillar = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe', 'published_at' => null]);
$theme = Pillar::query()->create(['name' => 'Veröffentlicht', 'slug' => 'oeffentlich', 'published_at' => now()]);
$page = Page::query()->where('path', '/praevention')->firstOrFail();
app(PillarService::class)->assignPages($page, [$theme->id]);
app(IdentityDimension::class)->assign($module, $this->legacyValue($pillar, 'Nähe'));
$before = [
'seite' => $this->page('/praevention'),
'thema' => $this->page('/themen/oeffentlich'),
'fassungen' => DB::table('composition_versions')->orderBy('id')->get()->toJson(),
'revisionen' => DB::table('page_revisions')->orderBy('id')->get()->toJson(),
'themen' => DB::table('pillars')->orderBy('id')->get(['id', 'name', 'slug', 'published_at'])->toJson(),
'freigaben' => DB::table('article_releases')->count(),
];
(new LegacyPillarAdoption)->run();
$this->assertSame($before['seite'], $this->page('/praevention'));
$this->assertSame($before['thema'], $this->page('/themen/oeffentlich'));
$this->assertSame($before['fassungen'], DB::table('composition_versions')->orderBy('id')->get()->toJson());
$this->assertSame($before['revisionen'], DB::table('page_revisions')->orderBy('id')->get()->toJson());
$this->assertSame($before['themen'], DB::table('pillars')->orderBy('id')->get(['id', 'name', 'slug', 'published_at'])->toJson(), 'Die Übernahme veröffentlicht nichts.');
$this->assertSame($before['freigaben'], DB::table('article_releases')->count());
$this->assertSame([$pillar->id], $module->pillars()->pluck('pillars.id')->all());
$this->assertNotNull($version);
}
private function legacyValue(Pillar $pillar, string $label, ?string $slug = null): EditorialDimensionValue
{
$dimension = EditorialDimension::query()->where('slug', EditorialDimension::PILLAR_SLUG)->firstOrFail();
return EditorialDimensionValue::query()->create([
'editorial_dimension_id' => $dimension->id,
'slug' => $slug ?? 'pfeiler-'.$pillar->id,
'label' => $label,
]);
}
private function keeper(): User
{
$keeper = User::factory()->redakteur()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $keeper;
}
/** Seiten ohne Vorladehinweise der Schriften, die ein zweiter Aufruf im selben Test weglässt. */
private function page(string $path): string
{
return preg_replace('/<link rel="preload"[^>]*>\s*/', '', (string) $this->get($path)->getContent());
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
}