Merge remote-tracking branch 'origin/develop' into feature/merkmale-symbol-seite
Deploy Test / test (push) Failing after 5m56s
Deploy Test / deploy (push) Skipped
CI Feature / test (push) Successful in 5m22s

This commit is contained in:
Lars committed 2026-11-26 08:31:23 +01:00
commit fbe4226347
32 files changed
+1640 -43

No files matched your search

+391
View File
@@ -0,0 +1,391 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferRelease;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\RightsProfileVersion;
use App\Domain\Commerce\Checkout;
use App\Domain\Entitlement\Acquisition;
use App\Domain\Entitlement\Grant;
use App\Domain\Entitlement\GrantIssuer;
use App\Domain\Entitlement\GrantStatus;
use App\Domain\Entitlement\NewStands;
use App\Domain\Entitlement\OfferAccess;
use App\Filament\Resources\Offers\Pages\ViewOffer;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\Support\BuildsShop;
use Tests\TestCase;
/**
* Regeln für freie Artikel (ADR-56): Wer ein Angebot „auf Abruf“ übernehmen darf (alle, freigeschaltete Konten, wer einen
* Artikel besitzt), serverseitig beim Abruf geprüft; Freigaben je Angebot und Konto, nie gelöscht; „Neu für dich“.
*/
class OfferClaimRulesTest extends TestCase
{
use BuildsShop;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
$this->seedShop();
}
private function access(): OfferAccess
{
return app(OfferAccess::class);
}
private function rights(): RightsProfileVersion
{
return RightsProfileVersion::query()->whereHas('profile', fn ($query) => $query->where('name', 'Privatlizenz ehrenamtlich'))->firstOrFail();
}
/** Ein freies Angebot auf Abruf mit eigenem Artikel. */
private function freeOffer(string $name = 'Gratis zum Start', string $kind = 'auf_abruf'): Offer
{
$article = app(ArticleService::class)->create('gratis-'.str($name)->slug());
app(ArticleService::class)->publishRelease($article, $this->article('shop-grenzen')->currentRelease->rootCompositionVersion, 'Erster Stand.');
$service = app(OfferService::class);
$offer = $service->create($name);
$service->activate($offer, [['target' => $article->fresh(), 'rights' => $this->rights()]], ['grant_kind' => $kind, 'holder_kind' => 'person']);
return $offer->fresh();
}
private function keeper(): User
{
$keeper = User::factory()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $keeper;
}
private function userWithoutProfile(): User
{
$user = User::factory()->create();
$user->forceFill(['party_id' => null])->save();
return $user->fresh();
}
private function claim(User $user, Offer $offer)
{
return $this->actingAs($user)->post(route('member.offers.claim', $offer));
}
private function taken(User $user): int
{
return Acquisition::query()->where('party_id', $user->party_id)->count();
}
// ---- Regel „alle“ -------------------------------------------------------------------------------------------------
public function test_by_default_every_member_sees_and_claims_a_free_offer_exactly_once(): void
{
$offer = $this->freeOffer();
$tina = $this->tina();
$this->assertSame('alle', $offer->claim_access);
$this->assertTrue($this->access()->mayClaim($tina, $offer));
$this->actingAs($tina)->get(route('member.offers'))->assertOk()->assertSee('Gratis zum Start');
$this->claim($tina, $offer)->assertRedirect(route('member.library'));
$this->claim($tina, $offer)->assertRedirect();
$this->assertSame(1, $this->taken($tina), 'Ein zweiter Abruf legt nichts doppelt an.');
$this->actingAs($tina)->get(route('member.offers'))->assertOk()->assertDontSee('In die Bibliothek');
}
// ---- Regel „nur freigeschaltete Konten“ --------------------------------------------------------------------------
public function test_a_released_only_offer_is_hidden_and_refused_for_everyone_else_on_the_server(): void
{
$offer = $this->freeOffer();
$this->access()->setRule($offer, OfferAccess::RELEASED);
$tina = $this->tina();
$max = $this->max();
$this->access()->release($offer->fresh(), $tina, $this->keeper());
$this->actingAs($tina)->get(route('member.offers'))->assertOk()->assertSee('Gratis zum Start');
$this->actingAs($max)->get(route('member.offers'))->assertOk()->assertDontSee('Gratis zum Start');
$this->claim($max, $offer)->assertRedirect()->assertSessionHasErrors('offer');
$this->assertSame(0, $this->taken($max), 'Ein nicht freigeschaltetes Konto bekommt nichts, auch mit der Adresse.');
$this->claim($tina, $offer)->assertRedirect(route('member.library'));
$this->assertSame(1, $this->taken($tina));
}
public function test_a_release_counts_only_for_its_own_offer_and_account(): void
{
$first = $this->freeOffer('Erstes Angebot');
$second = $this->freeOffer('Zweites Angebot');
$this->access()->setRule($first, OfferAccess::RELEASED);
$this->access()->setRule($second, OfferAccess::RELEASED);
$this->access()->release($first->fresh(), $this->tina(), $this->keeper());
$this->assertTrue($this->access()->mayClaim($this->tina(), $first->fresh()));
$this->assertFalse($this->access()->mayClaim($this->tina(), $second->fresh()));
$this->assertFalse($this->access()->mayClaim($this->max(), $first->fresh()));
}
public function test_a_revoked_or_expired_release_no_longer_allows_the_claim_but_keeps_what_was_taken(): void
{
$offer = $this->freeOffer();
$this->access()->setRule($offer, OfferAccess::RELEASED);
$keeper = $this->keeper();
$tina = $this->tina();
$max = $this->max();
$releaseTina = $this->access()->release($offer->fresh(), $tina, $keeper, now()->addDays(2));
$releaseMax = $this->access()->release($offer->fresh(), $max, $keeper);
$this->claim($max, $offer)->assertRedirect(route('member.library'));
$this->access()->revoke($releaseMax, $keeper, 'Irrtum');
$this->assertSame(1, $this->taken($max), 'Ein bereits übernommenes Angebot bleibt nach dem Entzug.');
$this->assertNotNull(OfferRelease::query()->find($releaseMax->id)->revoked_at, 'Die Freigabe bleibt mit dem Entzug gespeichert.');
$this->travel(3)->days();
$this->assertFalse($this->access()->mayClaim($tina, $offer->fresh()), 'Nach dem Ende der Freigabe ist der Abruf gesperrt.');
$this->claim($tina, $offer)->assertRedirect()->assertSessionHasErrors('offer');
$this->assertSame(0, $this->taken($tina));
$this->assertSame(2, OfferRelease::query()->count(), 'Freigaben werden nie gelöscht.');
$this->assertNotNull($releaseTina->fresh());
}
public function test_releases_are_validated(): void
{
$offer = $this->freeOffer();
$keeper = $this->keeper();
try {
$this->access()->release($offer, $this->tina(), $keeper);
$this->fail('Bei der Regel „alle“ gibt es keine Freigaben.');
} catch (DomainRuleException $exception) {
$this->assertStringContainsString('nur freigeschaltete Konten', $exception->getMessage());
}
$this->access()->setRule($offer, OfferAccess::RELEASED);
$offer = $offer->fresh();
$this->access()->release($offer, $this->tina(), $keeper);
foreach ([
'doppelt' => fn () => $this->access()->release($offer, $this->tina(), $keeper),
'Vergangenheit' => fn () => $this->access()->release($offer, $this->max(), $keeper, now()->subDay()),
'ohne Profil' => fn () => $this->access()->release($offer, $this->userWithoutProfile(), $keeper),
] as $name => $attempt) {
try {
$attempt();
$this->fail('Diese Freigabe muss abgelehnt werden: '.$name);
} catch (DomainRuleException) {
$this->assertTrue(true);
}
}
$this->assertSame(1, OfferRelease::query()->count());
}
// ---- Regel „besitzt einen Artikel“ -------------------------------------------------------------------------------
private function buy(User $user, Offer $offer): void
{
$order = $this->orderOf($user, [$offer]);
app(Checkout::class)->confirmTestPayment($order, 'test-'.$order->id);
}
public function test_an_owner_rule_opens_the_offer_only_for_accounts_with_a_valid_grant_on_the_article(): void
{
$offer = $this->freeOffer();
$article = $this->article('shop-konflikte');
$this->access()->setRule($offer, OfferAccess::OWNERS, $article->id);
$offer = $offer->fresh();
$tina = $this->tina();
$this->assertFalse($this->access()->mayClaim($tina, $offer));
$this->claim($tina, $offer)->assertRedirect()->assertSessionHasErrors('offer');
$this->assertSame(0, $this->taken($tina));
$this->buy($tina, $this->privateKonflikte());
$this->assertTrue($this->access()->mayClaim($tina, $offer));
$this->actingAs($tina)->get(route('member.offers'))->assertOk()->assertSee('Gratis zum Start');
$this->assertFalse($this->access()->mayClaim($this->max(), $offer), 'Der Besitz gilt je Konto.');
Grant::query()->where('license_article_id', $article->id)->update(['status' => GrantStatus::Widerrufen]);
$this->assertFalse($this->access()->mayClaim($tina, $offer), 'Eine widerrufene Berechtigung zählt nicht als Besitz.');
}
public function test_the_rule_itself_is_validated_and_clears_a_stale_article(): void
{
$offer = $this->freeOffer();
$article = $this->article('shop-konflikte');
foreach ([['unbekannt', null], [OfferAccess::OWNERS, null], [OfferAccess::OWNERS, 999999]] as [$access, $articleId]) {
try {
$this->access()->setRule($offer, $access, $articleId);
$this->fail('Diese Regel muss abgelehnt werden.');
} catch (DomainRuleException) {
$this->assertSame('alle', $offer->fresh()->claim_access);
}
}
$article->forceFill(['archived_at' => now()])->save();
try {
$this->access()->setRule($offer, OfferAccess::OWNERS, $article->id);
$this->fail('Ein archivierter Artikel ist keine Voraussetzung.');
} catch (DomainRuleException) {
$this->assertNull($offer->fresh()->claim_requires_article_id);
}
$article->forceFill(['archived_at' => null])->save();
$this->access()->setRule($offer, OfferAccess::OWNERS, $article->id);
$this->assertSame($article->id, $offer->fresh()->claim_requires_article_id);
$this->access()->setRule($offer->fresh(), OfferAccess::ALL, $article->id);
$this->assertNull($offer->fresh()->claim_requires_article_id, 'Eine andere Regel löscht den Artikel.');
}
// ---- Was die Regel nicht betrifft --------------------------------------------------------------------------------
public function test_on_registration_offers_ignore_the_rule_and_stay_listed(): void
{
$offer = $this->freeOffer('Zur Registrierung', 'bei_registrierung');
$this->access()->setRule($offer, OfferAccess::RELEASED);
$max = $this->max();
$this->assertTrue($this->access()->mayClaim($max, $offer->fresh()));
$this->assertTrue($this->access()->claimable($max)->contains('id', $offer->id));
}
public function test_a_purchase_offer_or_an_ended_offer_cannot_be_claimed_for_free(): void
{
$purchase = $this->privateKonflikte();
$tina = $this->tina();
$this->assertFalse($this->access()->mayClaim($tina, $purchase));
$this->claim($tina, $purchase)->assertRedirect()->assertSessionHasErrors('offer');
$offer = $this->freeOffer();
app(OfferService::class)->end($offer);
$this->assertFalse($this->access()->mayClaim($tina, $offer->fresh()));
$this->assertSame(0, $this->taken($tina));
}
public function test_the_issuer_enforces_the_rule_even_without_the_page(): void
{
$offer = $this->freeOffer();
$this->access()->setRule($offer, OfferAccess::RELEASED);
$this->expectException(DomainRuleException::class);
app(GrantIssuer::class)->claim($this->max(), $offer->fresh());
}
// ---- Verwaltung --------------------------------------------------------------------------------------------------
public function test_the_keeper_sets_the_rule_releases_and_revokes_on_the_offer_page(): void
{
$offer = $this->freeOffer();
$tina = $this->tina();
$page = Livewire::actingAs($this->keeper(), 'staff')->test(ViewOffer::class, ['record' => $offer->getKey()]);
$page->assertSee('Wer darf abrufen')->assertSee('Alle angemeldeten Mitglieder');
$page->callAction('claimRule', ['claim_access' => OfferAccess::RELEASED, 'claim_requires_article_id' => null])->assertHasNoActionErrors();
$this->assertSame('konten', $offer->fresh()->claim_access);
$page->assertSee('Freigeschaltete Konten')->callAction('release', ['user_id' => $tina->id, 'valid_until' => null, 'reason' => 'Seminar am 12.11.2026'])->assertHasNoActionErrors();
$release = OfferRelease::query()->firstOrFail();
$this->assertSame($tina->id, $release->user_id);
$this->assertTrue($this->access()->mayClaim($tina, $offer->fresh()));
$page->assertSee('Seminar am 12.11.2026');
$page->callAction('revoke', ['reason' => 'Irrtum'], ['release' => $release->id])->assertHasNoActionErrors();
$this->assertNotNull($release->fresh()->revoked_at);
$this->assertFalse($this->access()->mayClaim($tina, $offer->fresh()));
}
public function test_the_rule_actions_exist_only_for_offers_on_demand_and_only_for_the_keeper(): void
{
$purchase = $this->privateKonflikte();
Livewire::actingAs($this->keeper(), 'staff')->test(ViewOffer::class, ['record' => $purchase->getKey()])
->assertDontSee('Wer darf abrufen')
->assertActionHidden('claimRule');
$offer = $this->freeOffer();
$redakteur = User::factory()->redakteur()->create();
$redakteur->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
Livewire::actingAs($redakteur, 'staff')->test(ViewOffer::class, ['record' => $offer->getKey()])->assertForbidden();
$this->assertSame('alle', $offer->fresh()->claim_access);
}
public function test_a_release_of_another_offer_cannot_be_revoked_through_this_offer(): void
{
$first = $this->freeOffer('Erstes');
$second = $this->freeOffer('Zweites');
$this->access()->setRule($first, OfferAccess::RELEASED);
$this->access()->setRule($second, OfferAccess::RELEASED);
$foreign = $this->access()->release($first->fresh(), $this->tina(), $this->keeper());
try {
Livewire::actingAs($this->keeper(), 'staff')->test(ViewOffer::class, ['record' => $second->getKey()])
->callAction('revoke', ['reason' => 'x'], ['release' => $foreign->id]);
} catch (\Throwable) {
// Die Freigabe eines anderen Angebots wird nicht gefunden.
}
$this->assertNull($foreign->fresh()->revoked_at);
}
// ---- Neu für dich ------------------------------------------------------------------------------------------------
public function test_a_new_stand_of_an_owned_article_is_listed_for_ninety_days_and_only_for_the_owner(): void
{
$tina = $this->tina();
$article = $this->article('shop-konflikte');
$this->buy($tina, $this->privateKonflikte());
$this->assertCount(0, app(NewStands::class)->forUser($tina), 'Ohne neuen Stand gibt es nichts zu zeigen.');
app(ArticleService::class)->publishRelease($article, $article->fresh()->currentRelease->rootCompositionVersion, 'Neuer Stand mit Ergänzungen.');
$list = app(NewStands::class)->forUser($tina);
$this->assertCount(1, $list);
$this->assertSame(2, $list[0]['number']);
$this->assertCount(0, app(NewStands::class)->forUser($this->max()), 'Wer den Artikel nicht besitzt, sieht keinen neuen Stand.');
$this->actingAs($tina)->get(route('member.offers'))->assertOk()->assertSee('Neu für dich')->assertSee('Stand 2')->assertSee(route('member.grant', $list[0]['grant']), false);
$this->travel(91)->days();
$this->assertCount(0, app(NewStands::class)->forUser($tina), 'Nach 90 Tagen verschwindet der Hinweis.');
}
public function test_a_withdrawn_grant_shows_no_new_stand(): void
{
$tina = $this->tina();
$article = $this->article('shop-konflikte');
$this->buy($tina, $this->privateKonflikte());
app(ArticleService::class)->publishRelease($article, $article->fresh()->currentRelease->rootCompositionVersion, 'Neuer Stand.');
Grant::query()->where('license_article_id', $article->id)->update(['status' => GrantStatus::Widerrufen]);
$this->assertCount(0, app(NewStands::class)->forUser($tina));
}
public function test_the_member_offers_page_shows_an_honest_empty_state(): void
{
$this->actingAs($this->max())->get(route('member.offers'))->assertOk()->assertSee('Gerade liegt nichts Neues für dich bereit');
}
public function test_the_article_title_helper_is_the_label_in_the_rule_form(): void
{
$offer = $this->freeOffer();
$this->access()->setRule($offer, OfferAccess::OWNERS, $this->article('shop-konflikte')->id);
Livewire::actingAs($this->keeper(), 'staff')->test(ViewOffer::class, ['record' => $offer->getKey()])
->assertSee('Mitglieder, die einen bestimmten Artikel besitzen')
->assertSee('Konflikte im Training');
$this->assertInstanceOf(LicenseArticle::class, $this->article('shop-konflikte'));
}
}
+223
View File
@@ -0,0 +1,223 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\PillarService;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\RenderContext;
use App\Domain\Cms\Widgets\WidgetErrors;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Domain\Commerce\Shop;
use App\Domain\Commerce\ShopCatalog;
use App\Filament\Resources\Pages\Pages\CreatePage;
use App\Filament\Resources\Pages\Pages\EditPage;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Livewire\Livewire;
use Tests\Support\BuildsShop;
use Tests\TestCase;
/**
* Der Shop im CMS (ADR-55): Die Seite „shop“ der Webpräsenz bestimmt den Aufbau von /shop; das Widget „Shop-Produkte“
* zeigt die Kacheln aus derselben Datenquelle, mit Filter, Reihenfolge und Anzahl, und nichts, solange der Shop nicht
* sichtbar ist.
*/
class ShopCmsTest extends TestCase
{
use BuildsShop;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
$this->seedShop();
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
private function widget(array $data = [], array $settings = []): array
{
return ['type' => 'shop_products', 'v' => 1, 'variant' => 'kacheln', 'settings' => $settings, 'data' => $data];
}
private function publish(string $path, array $sections): Page
{
$page = Page::query()->firstOrCreate(['path' => $path]);
$service = app(PageService::class);
$service->publish($page, $service->saveRevision($page, $sections, null, null, null));
return $page->fresh();
}
private function section(array $widget): array
{
return ['layout' => 'u4', 'style' => [], 'slots' => [$widget]];
}
private function banner(string $text): array
{
return ['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'heading', 'v' => 1, 'variant' => 'standard', 'settings' => [], 'data' => ['heading' => $text], 'refs' => []]]];
}
public function test_the_widget_is_registered_with_an_honest_contract(): void
{
$type = app(WidgetRegistry::class)->get('shop_products');
$this->assertSame('Shop-Produkte', $type->label());
$this->assertContains(4, $type->supportedUnits());
$this->assertNotSame([], $type->schematic());
$this->assertArrayHasKey('kacheln', $type->variants());
}
public function test_the_editor_offers_the_widget_saves_its_choices_and_reopens_the_page(): void
{
$widget = ['type' => 'shop_products', 'data' => ['variant' => 'kacheln', 'data' => ['heading' => 'Alle Produkte', 'pillar' => null, 'kind' => null], 'settings' => ['sort' => 'preis', 'limit' => 'n6', 'search' => 'an']]];
$slots = [(string) Str::uuid() => ['widget' => [(string) Str::uuid() => $widget]]];
Livewire::actingAs($this->editor(), 'staff')
->test(CreatePage::class)
->fillForm(['path' => '/shop', 'seo_title' => 'Shop', 'sections' => [['id' => null, 'layout' => 'u4', 'style' => [], 'slots' => $slots]]])
->call('create')
->assertHasNoFormErrors();
$page = Page::query()->where('path', '/shop')->firstOrFail();
$saved = $page->latestRevision->sections[0]['slots'][0];
$this->assertSame('shop_products', $saved['type']);
$this->assertSame('kacheln', $saved['variant']);
$this->assertSame(['sort' => 'preis', 'limit' => 'n6', 'search' => 'an'], $saved['settings']);
Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->getKey()])->assertOk();
}
public function test_the_widget_lists_the_products_with_tiles_on_any_page(): void
{
$this->publish('/empfehlungen', [$this->section($this->widget(['heading' => 'Unsere Produkte']))]);
$this->get('/empfehlungen')->assertOk()
->assertSee('Unsere Produkte')
->assertSee('Konflikte im Training')
->assertSee('Grenzen setzen im Verein')
->assertSee('class="shop-tile"', false);
}
public function test_the_shop_page_of_the_web_presence_shapes_the_shop_with_banner_and_widget(): void
{
$this->publish('/shop', [$this->banner('Willkommen im Shop'), $this->section($this->widget([], ['search' => 'an']))]);
$this->get(route('shop'))->assertOk()
->assertSee('Willkommen im Shop')
->assertSee('Konflikte im Training')
->assertSee('Shop durchsuchen');
$this->get(route('shop', ['suche' => 'Grenzen']))->assertOk()
->assertSee(route('shop.article', $this->article('shop-grenzen')), false)
->assertDontSee(route('shop.article', $this->article('shop-konflikte')), false);
}
public function test_without_a_cms_page_the_application_default_shop_stays(): void
{
$this->get(route('shop'))->assertOk()->assertSee('Shop durchsuchen')->assertSee('Konflikte im Training');
}
public function test_an_unpublished_shop_page_does_not_replace_the_default(): void
{
Page::query()->create(['path' => '/shop']);
$this->get(route('shop'))->assertOk()->assertSee('Shop durchsuchen');
}
public function test_the_widget_hides_itself_and_the_shop_page_is_gone_while_the_shop_is_not_visible(): void
{
$this->publish('/shop', [$this->banner('Willkommen im Shop'), $this->section($this->widget())]);
$this->publish('/empfehlungen', [$this->banner('Seite'), $this->section($this->widget(['heading' => 'Unsere Produkte']))]);
$this->app['env'] = 'production';
config(['services.payment.driver' => 'stripe', 'services.stripe.secret' => 'sk_live_nur_fuer_tests', 'shop.public' => false, 'shop.live_release' => false]);
$this->assertFalse(Shop::visible());
$this->get('/shop')->assertNotFound();
$this->get('/empfehlungen')->assertOk()->assertDontSee('Unsere Produkte')->assertDontSee('shop-tile');
}
public function test_the_shop_page_is_left_out_of_the_sitemap_while_nobody_can_buy(): void
{
$this->publish('/shop', [$this->section($this->widget())]);
$this->get('/sitemap.xml')->assertOk()->assertSee(url('/shop'), false);
$this->app['env'] = 'production';
config(['services.payment.driver' => 'stripe', 'services.stripe.secret' => 'sk_live_nur_fuer_tests', 'shop.public' => true, 'shop.live_release' => false]);
$this->assertTrue(Shop::visible());
$this->get('/sitemap.xml')->assertOk()->assertDontSee(url('/shop'), false);
}
public function test_the_widget_limit_setting_cuts_the_list(): void
{
$this->publish('/zwei-produkte', [$this->section($this->widget([], ['limit' => 'n3', 'sort' => 'name']))]);
$this->get('/zwei-produkte')->assertOk()->assertSee('3 Produkte');
$widget = app(WidgetRegistry::class)->get('shop_products');
$cards = $widget->resolve(['data' => [], 'settings' => ['limit' => 'n2']], RenderContext::publicPage())['cards'];
$this->assertCount(2, $cards);
}
public function test_the_widget_filters_by_pillar_and_kind_sorts_and_limits(): void
{
$service = app(PillarService::class);
$pillar = $service->create('Grenzen und Wertschätzung');
$service->present($pillar, 'Grenzen und Wertschätzung', 'grenzen-wertschaetzung', null, true, 10);
$service->assign($this->article('shop-grenzen'), [$pillar->id]);
$this->publish('/nur-grenzen', [$this->section($this->widget(['pillar' => $pillar->id]))]);
$this->get('/nur-grenzen')->assertOk()->assertSee('Grenzen setzen im Verein')->assertDontSee('Konflikte im Training');
$names = fn (array $options): array => array_column(app(ShopCatalog::class)->cards('', $options), 'title');
$this->assertSame(['Grenzen setzen im Verein', 'Konflikte im Training', 'Starterpaket'], $names(['sort' => 'name']));
$this->assertSame(['Grenzen setzen im Verein', 'Konflikte im Training', 'Starterpaket'], $names(['sort' => 'preis']), 'Preis aufsteigend: 29, 49, 59 Euro');
$this->assertCount(2, $names(['limit' => 2]));
$this->assertSame([], $names(['pillar' => 999999]));
$kind = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
$this->article('shop-konflikte')->forceFill(['editorial_content_kind_id' => $kind->id])->save();
$this->assertSame(['Konflikte im Training'], $names(['kind' => $kind->id]));
}
public function test_a_very_long_search_term_is_cut_and_never_breaks_the_page(): void
{
$term = str_repeat('Grenzen ', 500);
$this->get(route('shop', ['suche' => $term]))->assertOk();
$this->assertSame([], app(ShopCatalog::class)->cards(str_repeat('x', 5000)));
$this->get(route('shop', ['suche' => '<script>alert(1)</script>']))->assertOk()->assertDontSee('<script>alert(1)</script>', false);
}
public function test_the_widget_cleaning_drops_unknown_pillars_and_kinds_and_reports_them(): void
{
$type = app(WidgetRegistry::class)->get('shop_products');
$errors = new WidgetErrors;
[$data] = $type->clean(['heading' => ' Titel ', 'pillar' => 999999, 'kind' => 999999], [], $errors);
$this->assertSame('Titel', $data['heading']);
$this->assertNull($data['pillar']);
$this->assertNull($data['kind']);
$this->assertNotEmpty($errors->all());
}
public function test_the_member_offers_page_shows_the_newest_products_as_tiles_below_the_free_offers(): void
{
$this->actingAs($this->tina())->get(route('member.offers'))->assertOk()
->assertSee('Im Shop')
->assertSee('class="shop-tile"', false)
->assertSee('Konflikte im Training')
->assertSee(route('shop'), false);
}
}