ver. 0.304: Configurable payment method order amount limits

Replace hardcoded PayPo condition (id=6, 40-1000 PLN) with generic
min/max order amount columns on pp_shop_payment_methods. Admin form
fields added, frontend basket checkout filters dynamically. Cache
invalidation on save. 4 new tests (734 total, 2080 assertions).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 15:26:51 +01:00
parent 3a3c2adb47
commit 9de4afec9a
10 changed files with 171 additions and 7 deletions

View File

@@ -78,6 +78,8 @@ class PaymentMethodRepositoryTest extends TestCase
$this->assertSame('test', $updateRow['description']);
$this->assertSame(1, $updateRow['status']);
$this->assertSame(22, $updateRow['apilo_payment_type_id']);
$this->assertNull($updateRow['min_order_amount']);
$this->assertNull($updateRow['max_order_amount']);
$this->assertSame(['id' => 3], $updateWhere);
}
@@ -113,6 +115,102 @@ class PaymentMethodRepositoryTest extends TestCase
$this->assertNull($repository->save(0, ['status' => 1]));
}
public function testSavePersistsMinMaxOrderAmount(): void
{
$mockDb = $this->createMock(\medoo::class);
$updateRow = null;
$mockDb->expects($this->once())
->method('update')
->willReturnCallback(function ($table, $row) use (&$updateRow) {
$updateRow = $row;
return true;
});
$repository = new PaymentMethodRepository($mockDb);
$repository->save(5, [
'description' => 'test',
'status' => 1,
'apilo_payment_type_id' => '',
'min_order_amount' => '40.00',
'max_order_amount' => '1000.00',
]);
$this->assertSame(40.0, $updateRow['min_order_amount']);
$this->assertSame(1000.0, $updateRow['max_order_amount']);
}
public function testSaveConvertsEmptyMinMaxToNull(): void
{
$mockDb = $this->createMock(\medoo::class);
$updateRow = null;
$mockDb->expects($this->once())
->method('update')
->willReturnCallback(function ($table, $row) use (&$updateRow) {
$updateRow = $row;
return true;
});
$repository = new PaymentMethodRepository($mockDb);
$repository->save(6, [
'description' => 'test',
'status' => 1,
'apilo_payment_type_id' => '',
'min_order_amount' => '',
'max_order_amount' => '',
]);
$this->assertNull($updateRow['min_order_amount']);
$this->assertNull($updateRow['max_order_amount']);
}
public function testFindNormalizesMinMaxOrderAmount(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with('pp_shop_payment_methods', '*', ['id' => 6])
->willReturn([
'id' => '6',
'name' => 'PayPo',
'description' => '',
'status' => '1',
'apilo_payment_type_id' => null,
'min_order_amount' => '40.00',
'max_order_amount' => '1000.00',
]);
$repository = new PaymentMethodRepository($mockDb);
$result = $repository->find(6);
$this->assertSame(40.0, $result['min_order_amount']);
$this->assertSame(1000.0, $result['max_order_amount']);
}
public function testFindNormalizesNullMinMaxOrderAmount(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with('pp_shop_payment_methods', '*', ['id' => 7])
->willReturn([
'id' => '7',
'name' => 'Przelew',
'description' => '',
'status' => '1',
'apilo_payment_type_id' => null,
'min_order_amount' => null,
'max_order_amount' => null,
]);
$repository = new PaymentMethodRepository($mockDb);
$result = $repository->find(7);
$this->assertNull($result['min_order_amount']);
$this->assertNull($result['max_order_amount']);
}
public function testListForAdminWhitelistsSortAndDirection(): void
{
$mockDb = $this->createMock(\medoo::class);