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('release')"', $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()]); $article = $this->article('shop-konflikte'); $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']); $this->assertNull(app(ProductOptions::class)->pageUrl($offer)); // Mit der aktiven Fassung hat die Option ihre Produktseite: die Seite des Artikels, ohne dass sie zugeordnet wird. app(OfferService::class)->activate($offer, [['target' => $article, 'rights' => $this->rights()]], ['grant_kind' => 'kauf', 'price_cents' => 3900, 'holder_kind' => 'person']); app(OfferService::class)->setOptionLabel($offer, 'Testoption'); $check = $readiness->forOffer($offer->refresh()); $this->assertTrue($check['bereit']); $this->assertSame(route('shop.article', $article), app(ProductOptions::class)->pageUrl($offer)); $page()->assertSeeText('Alle Voraussetzungen sind erfüllt.')->assertSee('öffentlich unter /shop/'.$article->id); $this->get(route('shop.article', $article))->assertOk()->assertSee('Testoption')->assertSee('39,00'); $this->get('/shop')->assertOk()->assertSee(route('shop.article', $article), false); } 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 { $bundle = Bundle::query()->where('name', 'Starterpaket')->firstOrFail(); $this->get('/shop')->assertOk()->assertSee(route('public.package', $bundle), false)->assertSee('Paket mit 3 Inhalten'); $this->get(route('public.package', $bundle, false))->assertOk() ->assertSee('Starterpaket (zwei Programme und Einführung)') ->assertSee('Starterpaket für neue Trainer') ->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)->setOptionLabel($offer, 'Namensprobe'); $scope = collect(app(ProductOptions::class)->forArticle($article))->firstWhere('name', 'Namensprobe')['scope']; $this->assertSame('Grenzen setzen im Verein', $scope[0]['article']); $this->get(route('shop.article', $article))->assertOk()->assertDontSee('nur-kennung-abnahme'); $this->assertStringContainsString('Grenzen setzen im Verein (nur-kennung-abnahme) · Stand 1', app(PublicationReadiness::class)->articleOptions()[$article->id]); } public function test_a_medium_without_display_title_names_its_article_by_the_working_title(): void { $element = ContentElement::query()->where('working_title', 'Begleitmaterial Grenzen setzen im Verein')->firstOrFail(); $version = ContentElementVersion::query()->where('content_element_id', $element->id)->firstOrFail(); $article = app(ArticleService::class)->create('nur-kennung-medium'); app(ArticleService::class)->publishRelease($article, $version, 'Erster Stand dieses Lizenzartikels.'); $this->assertSame('Begleitmaterial Grenzen setzen im Verein', app(ProductOptions::class)->articleTitle($article->refresh())); $this->assertSame('Begleitmaterial Grenzen setzen im Verein', app(PublicationReadiness::class)->articleName($article)); $this->assertSame('nur-kennung-ohne-inhalt', app(ProductOptions::class)->articleTitle(app(ArticleService::class)->create('nur-kennung-ohne-inhalt')), 'Ohne Namen bleibt die Kennung.'); } private function rights(): RightsProfileVersion { return RightsProfileVersion::query()->orderBy('id')->firstOrFail(); } public function test_a_purchase_with_several_positions_is_refused_and_points_to_the_package(): void { $offer = app(OfferService::class)->create('Mehrere Artikel'); $positions = [ ['target' => $this->article('shop-konflikte'), 'rights' => $this->rights()], ['target' => $this->article('shop-grenzen'), 'rights' => $this->rights()], ]; try { app(OfferService::class)->activate($offer, $positions, ['grant_kind' => 'kauf', 'price_cents' => 3900, 'holder_kind' => 'person']); $this->fail('Ein Kauf mit mehreren Positionen hätte keine Produktseite.'); } catch (DomainRuleException $e) { $this->assertStringContainsString('Paket', $e->getMessage()); } $this->assertSame(0, $offer->versions()->count()); } public function test_a_purchase_without_a_price_cannot_be_activated(): void { $offer = app(OfferService::class)->create('Ohne Preis'); foreach ([null, 0] as $price) { try { app(OfferService::class)->activate($offer, [['target' => $this->article('shop-konflikte'), 'rights' => $this->rights()]], ['grant_kind' => 'kauf', 'price_cents' => $price, 'holder_kind' => 'person']); $this->fail('Ein Kauf ohne Preis ist nicht kaufbar.'); } catch (DomainRuleException $e) { $this->assertStringContainsString('Preis', $e->getMessage()); } } $this->assertSame(0, $offer->versions()->count()); } public function test_grants_at_registration_and_on_demand_stay_possible_but_are_not_in_the_shop(): void { foreach (['bei_registrierung', 'auf_abruf'] as $kind) { $offer = app(OfferService::class)->create('Ohne Shop '.$kind); app(OfferService::class)->activate($offer, [ ['target' => $this->article('shop-konflikte'), 'rights' => $this->rights()], ['target' => $this->article('shop-grenzen'), 'rights' => $this->rights()], ], ['grant_kind' => $kind, 'holder_kind' => 'person']); $this->assertNull(app(OfferService::class)->purchasableVersion($offer->refresh())); $this->assertNull(app(ProductOptions::class)->pageUrl($offer)); } } 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; } }