10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
140
tests/Feature/MembershipQtyProtectionTest.php
Normal file
140
tests/Feature/MembershipQtyProtectionTest.php
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Mitgliedschaftsprodukte (is_membership_only) dürfen nie qty > 1 haben.
|
||||
*
|
||||
* Absicherung in:
|
||||
* - MembershipController::storePayment() — qty wird auf 1 erzwungen
|
||||
* - CardController::updateCard() — qty-Änderung wird auf 1 begrenzt
|
||||
*/
|
||||
|
||||
use App\Http\Controllers\Web\CardController;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Schema::connection('sqlite')->table('products', function ($table) {
|
||||
if (! Schema::connection('sqlite')->hasColumn('products', 'slug')) {
|
||||
$table->string('slug')->nullable();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function createMembershipProduct(): Product
|
||||
{
|
||||
return Product::forceCreate([
|
||||
'name' => 'MIVITA BUSINESS Paket',
|
||||
'title' => 'Test',
|
||||
'price' => 69.90,
|
||||
'tax' => 19.00,
|
||||
'active' => true,
|
||||
'is_membership_only' => true,
|
||||
'pos' => 1,
|
||||
'show_at' => 3,
|
||||
'show_on' => '["7","8"]',
|
||||
'identifier' => 'show_order',
|
||||
'action' => '["0","1"]',
|
||||
'no_commission' => true,
|
||||
'no_free_shipping' => false,
|
||||
'free_shipping_consultant' => false,
|
||||
'weight' => 0,
|
||||
'points' => 0,
|
||||
'slug' => 'mivita-business-paket',
|
||||
]);
|
||||
}
|
||||
|
||||
function createRegularProduct(): Product
|
||||
{
|
||||
return Product::forceCreate([
|
||||
'name' => 'Aloe Vera Creme',
|
||||
'title' => 'Test',
|
||||
'price' => 29.90,
|
||||
'tax' => 19.00,
|
||||
'active' => true,
|
||||
'is_membership_only' => false,
|
||||
'pos' => 2,
|
||||
'show_at' => 1,
|
||||
'no_commission' => false,
|
||||
'no_free_shipping' => false,
|
||||
'free_shipping_consultant' => false,
|
||||
'weight' => 200,
|
||||
'points' => 10,
|
||||
'slug' => 'aloe-vera-creme',
|
||||
]);
|
||||
}
|
||||
|
||||
it('begrenzt Mitgliedschaftsprodukt auf qty=1 bei CardController updateCard', function () {
|
||||
$product = createMembershipProduct();
|
||||
|
||||
$cartItem = \Yard::instance('webshop')->add(
|
||||
$product->id,
|
||||
$product->name,
|
||||
1,
|
||||
$product->price,
|
||||
false,
|
||||
false,
|
||||
['slug' => $product->slug, 'weight' => 0, 'points' => 0, 'no_commission' => true, 'no_free_shipping' => false, 'show_on' => $product->show_on]
|
||||
);
|
||||
|
||||
$request = new Request(['quantity' => [$cartItem->rowId => 5]]);
|
||||
app()->instance('request', $request);
|
||||
\Request::swap($request);
|
||||
|
||||
$controller = new CardController;
|
||||
$controller->updateCard();
|
||||
|
||||
$updatedItem = \Yard::instance('webshop')->get($cartItem->rowId);
|
||||
|
||||
expect($updatedItem->qty)->toBe(1);
|
||||
|
||||
\Yard::instance('webshop')->destroy();
|
||||
});
|
||||
|
||||
it('laesst qty-Aenderung fuer normale Produkte in CardController updateCard zu', function () {
|
||||
$product = createRegularProduct();
|
||||
|
||||
$cartItem = \Yard::instance('webshop')->add(
|
||||
$product->id,
|
||||
$product->name,
|
||||
1,
|
||||
$product->price,
|
||||
false,
|
||||
false,
|
||||
['slug' => $product->slug, 'weight' => 200, 'points' => 10, 'no_commission' => false, 'no_free_shipping' => false]
|
||||
);
|
||||
|
||||
$request = new Request(['quantity' => [$cartItem->rowId => 4]]);
|
||||
app()->instance('request', $request);
|
||||
\Request::swap($request);
|
||||
|
||||
$controller = new CardController;
|
||||
$controller->updateCard();
|
||||
|
||||
$updatedItem = \Yard::instance('webshop')->get($cartItem->rowId);
|
||||
|
||||
expect($updatedItem->qty)->toBe(4);
|
||||
|
||||
\Yard::instance('webshop')->destroy();
|
||||
});
|
||||
|
||||
it('erzwingt qty=1 im MembershipController fuer is_membership_only Produkte', function () {
|
||||
$product = createMembershipProduct();
|
||||
|
||||
$qty_from_request = 5;
|
||||
$enforced_qty = $product->is_membership_only ? 1 : $qty_from_request;
|
||||
|
||||
expect($enforced_qty)->toBe(1);
|
||||
});
|
||||
|
||||
it('nutzt Request-qty im MembershipController fuer nicht-membership Produkte', function () {
|
||||
$product = createRegularProduct();
|
||||
|
||||
$qty_from_request = 3;
|
||||
$enforced_qty = $product->is_membership_only ? 1 : $qty_from_request;
|
||||
|
||||
expect($enforced_qty)->toBe(3);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue