Binde den Shop ins CMS ein: Seite shop, Widget Shop-Produkte, Kacheln auf der Mitgliederseite
CI Feature / test (push) Successful in 5m29s

- Eine veroeffentlichte CMS-Seite mit dem Pfad /shop bestimmt den Aufbau von /shop, sonst gilt die Standardseite
- Widget shop_products mit Filter (Saeule, Materialart), Reihenfolge, Anzahl und Suchfeld; leer, solange der Shop nicht sichtbar ist
- ShopCatalog mit Filter, Sortierung und Limit; Suchbegriff auf 100 Zeichen gekuerzt
- Sitemap ohne /shop, solange nicht gekauft werden kann
- Mitgliederseite Angebote zeigt die neuesten Produkte als Kacheln
- ADR-55, Widget-Register

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-26 08:12:45 +01:00
1 parent 1af462e1d6
commit 61c65595e1
14 files changed
+569 -12

No files matched your search

+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);
}
}