Files
laraundfelix/tests/Feature/ShopVerwaltungAbnahmeTest.php
T
StommerandClaude Sonnet 5.5 4520dba2f0
Deploy Test / test (push) Successful in 1m36s
Deploy Test / deploy (push) Successful in 27s
Benenne Artikel im Shop und in den Listen nach ihrem Inhalt statt nach der Kennung
Die Produktseite zeigte im Leistungsumfang die Kennung, obwohl die Redaktion den Namen
aus dem Inhalt übernimmt. ProductOptions und PublicationReadiness lösen den Namen jetzt
wie die Redaktion auf: eigener Name, sonst Name des Inhalts, zuletzt Kennung.

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

246 lines
13 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\BundleService;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\RightsProfileVersion;
use App\Domain\Commerce\ProductOptions;
use App\Filament\Resources\Bundles\Pages\ViewBundle;
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
use App\Filament\Resources\Offers\Pages\ViewOffer;
use App\Filament\Support\PublicationReadiness;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\Support\BuildsShop;
use Tests\TestCase;
/**
* Etappe 1, Nachbesserung der Shop-Verwaltung: Aus „Name angelegt“ führt die Oberfläche bis zum kaufbaren Angebot.
* Geprüft werden die gemeinsame Anzeige der Voraussetzungen (Artikel, Paket, Angebot), der verständliche Dialog für den
* ersten Artikelstand, die gekennzeichnete Auswahl und die Absicherung gegen Artikel ohne Inhalt.
*/
class ShopVerwaltungAbnahmeTest extends TestCase
{
use BuildsShop;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seedShop();
}
public function test_an_article_without_stand_names_the_next_step_and_offers_the_content_as_main_action(): void
{
$article = app(ArticleService::class)->create('neu-ohne-stand');
$component = Livewire::actingAs($this->keeper(), 'staff')
->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->assertSee('Bis zur Veröffentlichung')
->assertSeeText('Nächster Schritt:')
->assertSee('Inhalt festlegen')
->assertSee('Der Artikel lizenziert noch nichts');
$this->assertStringContainsString('wire:click="mountAction(&#039;release&#039;)"', $component->html());
$this->assertStringContainsString('vw-btn is-primary', (string) preg_replace('/\s+/', ' ', explode('Weitere Aktionen', $component->html())[0]), 'Der Einstieg steht als Hauptaktion im Kopf, nicht nur im Menü.');
}
public function test_the_first_stand_dialog_is_plain_prefilled_and_publishes(): void
{
$article = app(ArticleService::class)->create('neu-erster-stand');
$root = 'composition:'.$this->article('shop-grenzen')->currentRelease->root_composition_version_id;
$component = Livewire::actingAs($this->keeper(), 'staff')
->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->mountAction('release');
$action = $component->instance()->getMountedAction();
$this->assertSame('Inhalt festlegen: ersten Stand veröffentlichen', $action->getModalHeading());
$this->assertSame('Stand veröffentlichen', $action->getModalSubmitActionLabel());
$page = $component->instance();
$schema = (new \ReflectionMethod($page, 'getMountedActionSchema'))->invoke($page);
$labels = collect($schema->getFlatComponents())
->map(fn ($field): ?string => method_exists($field, 'getLabel') ? (string) $field->getLabel() : null)
->filter()
->values()
->all();
$this->assertContains('Freigegebener Inhalt', $labels);
$this->assertNotContains('Wurzel', $labels);
$this->assertSame('Erster Stand dieses Lizenzartikels.', $component->get('mountedActions.0.data.classification'));
$component->fillForm(['root' => $root])->callMountedAction()->assertHasNoActionErrors();
$article->refresh();
$this->assertNotNull($article->current_release_id);
$this->assertSame('Erster Stand dieses Lizenzartikels.', $article->currentRelease->classification_note);
$this->assertTrue(app(PublicationReadiness::class)->forArticle($article)['schritte'][0]['stand'] === 'erledigt');
}
public function test_a_later_stand_still_asks_for_the_classification(): void
{
$article = $this->article('shop-grenzen');
$component = Livewire::actingAs($this->keeper(), 'staff')
->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->mountAction('release');
$this->assertSame('Neuen Stand veröffentlichen', $component->instance()->getMountedAction()->getModalHeading());
$component->fillForm(['root' => 'composition:'.$article->currentRelease->root_composition_version_id, 'classification' => ''])
->callMountedAction()
->assertHasActionErrors(['classification' => 'required']);
}
public function test_pickers_name_articles_with_title_and_stand_and_mark_those_without_content(): void
{
app(ArticleService::class)->create('leer-ohne-stand');
$options = app(PublicationReadiness::class)->articleOptions();
$leer = collect($options)->first(fn (string $label): bool => str_contains($label, 'leer-ohne-stand'));
$this->assertSame('leer-ohne-stand · noch ohne Stand, nicht verwendbar', $leer);
$this->assertStringContainsString('· Stand 1', (string) collect($options)->first(fn (string $label): bool => str_contains($label, 'shop-konflikte')));
$this->assertStringContainsString('shop-konflikte', implode(' ', app(PublicationReadiness::class)->bundleVersionOptions()));
}
public function test_an_offer_for_an_article_without_stand_cannot_be_activated(): void
{
$article = app(ArticleService::class)->create('angebot-ohne-stand');
$offer = app(OfferService::class)->create('Angebot ohne Inhalt');
Livewire::actingAs($this->keeper(), 'staff')
->test(ViewOffer::class, ['record' => $offer->getKey()])
->mountAction('activate')
->fillForm([
'holder_kind' => 'person',
'grant_kind' => 'kauf',
'price_euro' => '19,00',
'lines' => [['kind' => 'article', 'article_id' => $article->id, 'rights_id' => $this->rights()->id]],
])
->callMountedAction()
->assertNotified('Der Lizenzartikel „angebot-ohne-stand“ (angebot-ohne-stand) hat noch keinen veröffentlichten Stand und vergibt keine Inhalte. Lege zuerst am Artikel mit „Inhalt festlegen“ den Inhalt fest, bevor du das Angebot aktivierst.');
$this->assertSame(0, $offer->versions()->count(), 'Es entsteht keine Angebotsfassung.');
}
public function test_an_offer_for_a_bundle_with_an_article_without_stand_cannot_be_activated(): void
{
$article = app(ArticleService::class)->create('paket-ohne-stand');
$bundle = app(BundleService::class)->create('Paket mit leerem Artikel');
$version = app(BundleService::class)->publish($bundle, [$article, $this->article('shop-konflikte')]);
$offer = app(OfferService::class)->create('Paketangebot ohne Inhalt');
Livewire::actingAs($this->keeper(), 'staff')
->test(ViewOffer::class, ['record' => $offer->getKey()])
->mountAction('activate')
->fillForm([
'holder_kind' => 'person',
'grant_kind' => 'kauf',
'price_euro' => '19,00',
'lines' => [['kind' => 'bundle', 'bundle_version_id' => $version->id, 'rights_id' => $this->rights()->id]],
])
->callMountedAction();
$this->assertSame(0, $offer->versions()->count());
$check = app(PublicationReadiness::class)->forBundle($bundle->refresh());
$this->assertFalse($check['bereit']);
$this->assertSame('Jeder enthaltene Artikel hat einen Inhalt', $check['naechster']['titel']);
$this->assertStringContainsString('paket-ohne-stand', $check['naechster']['text']);
}
public function test_the_offer_page_walks_from_empty_to_findable_in_the_shop(): void
{
$offer = app(OfferService::class)->create('Neues Angebot');
$readiness = app(PublicationReadiness::class);
$page = fn () => Livewire::actingAs($this->keeper(), 'staff')->test(ViewOffer::class, ['record' => $offer->getKey()]);
$page()->assertSee('Bis zur Veröffentlichung')->assertSeeText('Nächster Schritt: Artikel oder Paket, Rechte, Preis und Vergabe festlegen');
$this->assertFalse($readiness->forOffer($offer->refresh())['bereit']);
// Aktiv, aber ohne Produktseite: nicht im Shop.
app(OfferService::class)->activate($offer, [['target' => $this->article('shop-konflikte'), 'rights' => $this->rights()]], ['grant_kind' => 'kauf', 'price_cents' => 3900, 'holder_kind' => 'person']);
$page()->assertSeeText('Nächster Schritt: Produktseite zuordnen');
$this->assertSame('Produktseite zuordnen', $readiness->forOffer($offer->refresh())['naechster']['titel']);
// Zugeordnet, aber Programm ohne Anzeigefreigabe: nicht auffindbar.
$hidden = $this->hiddenProgram();
app(OfferService::class)->assignProduct($offer, $hidden->id, 'Testoption');
$check = $readiness->forOffer($offer->refresh());
$this->assertSame('Produktseite öffentlich', $check['naechster']['titel']);
$this->get('/shop')->assertOk()->assertDontSee('Testoption');
// Öffentliche Produktseite: bereit und im Shop.
app(OfferService::class)->assignProduct($offer, $this->program('Konflikte im Training')->id, 'Testoption');
$check = $readiness->forOffer($offer->refresh());
$this->assertTrue($check['bereit']);
$page()->assertSeeText('Alle Voraussetzungen sind erfüllt.');
$this->get(route('public.program', $this->program('Konflikte im Training'), false))->assertOk()->assertSee('Testoption')->assertSee('39,00');
}
public function test_the_bundle_page_shows_the_steps_and_the_offer_for_the_bundle(): void
{
$bundle = app(BundleService::class)->create('Frisches Paket');
Livewire::actingAs($this->keeper(), 'staff')
->test(ViewBundle::class, ['record' => $bundle->getKey()])
->assertSee('Bis zur Veröffentlichung')
->assertSeeText('Nächster Schritt: Bestandteile festlegen');
app(BundleService::class)->publish($bundle, [$this->article('shop-konflikte'), $this->article('shop-grenzen')]);
$check = app(PublicationReadiness::class)->forBundle($bundle->refresh());
$this->assertTrue($check['bereit'], 'Pflichtschritte erfüllt; das Angebot ist eine Empfehlung.');
$this->assertSame('offen', $check['schritte'][2]['stand']);
$this->assertFalse($check['schritte'][2]['pflicht']);
}
public function test_the_bundle_offer_lists_the_scope_and_is_found_in_the_shop(): void
{
$starter = $this->program('Starterpaket für neue Trainer');
$this->get('/shop')->assertOk()->assertSee('Starterpaket für neue Trainer');
$this->get(route('public.program', $starter, false))->assertOk()->assertSee('Starterpaket (zwei Programme und Einführung)')->assertSee('59,00');
}
public function test_the_scope_names_an_article_by_its_content_and_not_by_its_code(): void
{
$root = $this->article('shop-grenzen')->currentRelease->rootCompositionVersion;
$article = app(ArticleService::class)->create('nur-kennung-abnahme');
app(ArticleService::class)->publishRelease($article, $root, 'Erster Stand dieses Lizenzartikels.');
$offer = app(OfferService::class)->create('Namensprobe');
app(OfferService::class)->activate($offer, [['target' => $article->refresh(), 'rights' => $this->rights()]], ['grant_kind' => 'kauf', 'price_cents' => 1500, 'holder_kind' => 'person']);
app(OfferService::class)->assignProduct($offer, $this->program('Grenzen setzen im Verein')->id, 'Namensprobe');
$scope = collect(app(ProductOptions::class)->forComposition($this->program('Grenzen setzen im Verein')))->firstWhere('name', 'Namensprobe')['scope'];
$this->assertSame('Grenzen setzen im Verein', $scope[0]['article']);
$this->get(route('public.program', $this->program('Grenzen setzen im Verein'), false))->assertOk()->assertDontSee('nur-kennung-abnahme');
$this->assertStringContainsString('Grenzen setzen im Verein (nur-kennung-abnahme) · Stand 1', app(PublicationReadiness::class)->articleOptions()[$article->id]);
}
private function rights(): RightsProfileVersion
{
return RightsProfileVersion::query()->orderBy('id')->firstOrFail();
}
private function hiddenProgram(): Composition
{
$composition = app(ContentService::class)->createComposition('Unveröffentlichtes Programm');
$composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', 'programm')->value('id');
$composition->save();
return $composition;
}
private function keeper(): User
{
$keeper = User::factory()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $keeper;
}
}