makeShopEnv()); function makeMixedOrder(bool $withAddon = true): ShoppingOrder { $order = ShoppingOrder::create([ 'shopping_user_id' => 1, 'auth_user_id' => 1, 'country_id' => 1, 'user_shop_id' => 0, 'payment_for' => 6, 'shipping' => 0, 'shipping_net' => 0, 'subtotal_ws' => 100, 'tax' => 0, 'total_shipping' => 100, 'is_abo' => true, ]); $aboProduct = makeProduct(['12'], 50, 0); $order->shopping_order_items()->create([ 'product_id' => $aboProduct->id, 'is_abo_addon' => false, 'qty' => 1, 'price' => 50, 'price_net' => 50, 'tax_rate' => 0, 'tax' => 0, 'price_vk_net' => 50, 'discount' => 0, 'points' => 0, ]); if ($withAddon) { $addonProduct = makeProduct(['2'], 30, 0); $order->shopping_order_items()->create([ 'product_id' => $addonProduct->id, 'is_abo_addon' => true, 'qty' => 1, 'price' => 30, 'price_net' => 30, 'tax_rate' => 0, 'tax' => 0, 'price_vk_net' => 30, 'discount' => 0, 'points' => 0, ]); } return $order->fresh('shopping_order_items.product'); } describe('Rechnung-PDF Gruppierung', function () { it('zeigt bei gemischter Bestellung beide Block-Überschriften, Abo vor Einmal', function () { $order = makeMixedOrder(); $html = view('pdf.invoice-detail', ['shopping_order' => $order])->render(); expect($html)->toContain(__('pdf.abo_items_heading')) ->and($html)->toContain(__('pdf.abo_addon_items_heading')); $aboPos = strpos($html, __('pdf.abo_items_heading')); $addonPos = strpos($html, __('pdf.abo_addon_items_heading')); expect($aboPos)->toBeLessThan($addonPos); }); it('zeigt KEINE Block-Überschriften bei reiner Bestellung ohne Einmal-Artikel', function () { $order = makeMixedOrder(withAddon: false); $html = view('pdf.invoice-detail', ['shopping_order' => $order])->render(); expect($html)->not->toContain(__('pdf.abo_addon_items_heading')) ->and($html)->not->toContain(__('pdf.abo_items_heading')); }); }); describe('Lieferschein-PDF Gruppierung', function () { it('zeigt bei gemischter Bestellung beide Block-Überschriften, Abo vor Einmal', function () { $order = makeMixedOrder(); $html = view('pdf.delivery-detail', ['shopping_order' => $order])->render(); expect($html)->toContain(__('pdf.abo_items_heading')) ->and($html)->toContain(__('pdf.abo_addon_items_heading')); $aboPos = strpos($html, __('pdf.abo_items_heading')); $addonPos = strpos($html, __('pdf.abo_addon_items_heading')); expect($aboPos)->toBeLessThan($addonPos); }); it('zeigt KEINE Block-Überschriften bei reiner Bestellung ohne Einmal-Artikel', function () { $order = makeMixedOrder(withAddon: false); $html = view('pdf.delivery-detail', ['shopping_order' => $order])->render(); expect($html)->not->toContain(__('pdf.abo_addon_items_heading')) ->and($html)->not->toContain(__('pdf.abo_items_heading')); }); });