ver. 0.292: ShopProduct + ShopPaymentMethod + ShopPromotion + ShopStatuses + ShopTransport frontend migration to Domain

Full migration of front\factory\ — entire directory removed (all 20 classes migrated).
ProductRepository +20 frontend methods, PromotionRepository +5 applyType methods,
TransportRepository +4 cached methods, PaymentMethodRepository +cached frontend methods.
Fix: broken transports_list() in ajax.php replaced with forPaymentMethod().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-17 21:55:16 +01:00
parent 827b903e1e
commit 89d9e61bec
48 changed files with 1780 additions and 975 deletions

View File

@@ -331,4 +331,93 @@ class TransportRepositoryTest extends TestCase
$this->assertSame(1, $rows[1]['default']);
$this->assertSame(50, $rows[1]['max_wp']);
}
// =========================================================================
// Frontend methods (migrated from front\factory\ShopTransport)
// =========================================================================
/**
* Test transportCostCached — zwraca koszt transportu
*/
public function testTransportCostCachedReturnsCost(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->willReturn('15.99');
$repository = new TransportRepository($mockDb);
$this->assertSame(15.99, $repository->transportCostCached(1));
}
/**
* Test findActiveByIdCached — zwraca transport
*/
public function testFindActiveByIdCachedReturnsTransport(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->willReturn([
'id' => '3', 'name' => 'DPD', 'status' => '1',
'cost' => '15.99', 'max_wp' => null, 'default' => '0',
'delivery_free' => '1', 'apilo_carrier_account_id' => null, 'o' => '2',
]);
$repository = new TransportRepository($mockDb);
$result = $repository->findActiveByIdCached(3);
$this->assertIsArray($result);
$this->assertSame(3, $result['id']);
$this->assertSame(15.99, $result['cost']);
}
/**
* Test findActiveByIdCached — null dla nieistniejącego
*/
public function testFindActiveByIdCachedReturnsNullForInvalid(): void
{
$mockDb = $this->createMock(\medoo::class);
$repository = new TransportRepository($mockDb);
$this->assertNull($repository->findActiveByIdCached(0));
}
/**
* Test forPaymentMethod — zwraca transporty powiązane z płatnością
*/
public function testForPaymentMethodReturnsTransports(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('select')
->willReturnCallback(function ($table, $columns, $where) {
if ($table === 'pp_shop_transport_payment_methods') {
return [1, 3];
}
if ($table === 'pp_shop_transports') {
return [
['id' => '1', 'name' => 'A', 'status' => '1', 'cost' => '5', 'max_wp' => null, 'default' => '0', 'delivery_free' => '0', 'apilo_carrier_account_id' => null, 'o' => '1'],
];
}
return [];
});
$repository = new TransportRepository($mockDb);
$result = $repository->forPaymentMethod(2);
$this->assertIsArray($result);
$this->assertCount(1, $result);
$this->assertSame(1, $result[0]['id']);
}
/**
* Test forPaymentMethod — pusta tablica dla nieprawidłowego ID
*/
public function testForPaymentMethodReturnsEmptyForInvalidId(): void
{
$mockDb = $this->createMock(\medoo::class);
$repository = new TransportRepository($mockDb);
$this->assertEquals([], $repository->forPaymentMethod(0));
}
}