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

@@ -510,4 +510,371 @@ class ProductRepositoryTest extends TestCase
$this->assertIsArray($result);
$this->assertNull($result['price_brutto_promo']);
}
// =========================================================================
// Frontend methods (migrated from front\factory\ShopProduct)
// =========================================================================
/**
* Test getSkuWithFallback - zwraca SKU bezpośrednio
*/
public function testGetSkuWithFallbackReturnsSku()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with('pp_shop_products', 'sku', ['id' => 10])
->willReturn('SKU-ABC');
$repository = new ProductRepository($mockDb);
$result = $repository->getSkuWithFallback(10);
$this->assertEquals('SKU-ABC', $result);
}
/**
* Test getSkuWithFallback - fallback na parent_id
*/
public function testGetSkuWithFallbackFromParent()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('get')
->willReturnCallback(function ($table, $column, $where) {
if ($column === 'sku' && $where['id'] === 10) return null;
if ($column === 'parent_id' && $where['id'] === 10) return 5;
if ($column === 'sku' && $where['id'] === 5) return 'SKU-PARENT';
return null;
});
$repository = new ProductRepository($mockDb);
$result = $repository->getSkuWithFallback(10, true);
$this->assertEquals('SKU-PARENT', $result);
}
/**
* Test getSkuWithFallback - zwraca null dla nieprawidłowego ID
*/
public function testGetSkuWithFallbackReturnsNullForInvalidId()
{
$mockDb = $this->createMock(\medoo::class);
$repository = new ProductRepository($mockDb);
$this->assertNull($repository->getSkuWithFallback(0));
$this->assertNull($repository->getSkuWithFallback(-1));
}
/**
* Test getEanWithFallback - zwraca EAN bezpośrednio
*/
public function testGetEanWithFallbackReturnsEan()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with('pp_shop_products', 'ean', ['id' => 10])
->willReturn('1234567890123');
$repository = new ProductRepository($mockDb);
$result = $repository->getEanWithFallback(10);
$this->assertEquals('1234567890123', $result);
}
/**
* Test getEanWithFallback - fallback na parent_id
*/
public function testGetEanWithFallbackFromParent()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('get')
->willReturnCallback(function ($table, $column, $where) {
if ($column === 'ean' && $where['id'] === 10) return null;
if ($column === 'parent_id' && $where['id'] === 10) return 5;
if ($column === 'ean' && $where['id'] === 5) return 'EAN-PARENT';
return null;
});
$repository = new ProductRepository($mockDb);
$result = $repository->getEanWithFallback(10, true);
$this->assertEquals('EAN-PARENT', $result);
}
/**
* Test isProductActiveCached - zwraca 1 dla aktywnego produktu
*/
public function testIsProductActiveCachedReturnsOneForActive()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with('pp_shop_products', 'status', ['id' => 10])
->willReturn(1);
$repository = new ProductRepository($mockDb);
$this->assertEquals(1, $repository->isProductActiveCached(10));
}
/**
* Test isProductActiveCached - zwraca 0 dla nieaktywnego produktu
*/
public function testIsProductActiveCachedReturnsZeroForInactive()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('get')->willReturn(0);
$repository = new ProductRepository($mockDb);
$this->assertEquals(0, $repository->isProductActiveCached(10));
}
/**
* Test isProductActiveCached - zwraca 0 dla nieprawidłowego ID
*/
public function testIsProductActiveCachedReturnsZeroForInvalidId()
{
$mockDb = $this->createMock(\medoo::class);
$repository = new ProductRepository($mockDb);
$this->assertEquals(0, $repository->isProductActiveCached(0));
$this->assertEquals(0, $repository->isProductActiveCached(-1));
}
/**
* Test productCategoriesFront - zwraca kategorie
*/
public function testProductCategoriesFrontReturnsCategories()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('get')
->with('pp_shop_products', 'parent_id', ['id' => 10])
->willReturn(null);
$mockStmt = $this->createMock(\PDOStatement::class);
$mockStmt->method('fetchAll')->willReturn([
['category_id' => 1],
['category_id' => 5],
]);
$mockDb->method('query')->willReturn($mockStmt);
$repository = new ProductRepository($mockDb);
$result = $repository->productCategoriesFront(10);
$this->assertIsArray($result);
$this->assertCount(2, $result);
$this->assertEquals(1, $result[0]['category_id']);
$this->assertEquals(5, $result[1]['category_id']);
}
/**
* Test productCategoriesFront - fallback na parent_id
*/
public function testProductCategoriesFrontUsesParentId()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('get')
->with('pp_shop_products', 'parent_id', ['id' => 10])
->willReturn(5);
$mockStmt = $this->createMock(\PDOStatement::class);
$mockStmt->method('fetchAll')->willReturn([['category_id' => 3]]);
$mockDb->expects($this->once())
->method('query')
->with(
$this->equalTo('SELECT category_id FROM pp_shop_products_categories WHERE product_id = :pid'),
$this->equalTo([':pid' => 5])
)
->willReturn($mockStmt);
$repository = new ProductRepository($mockDb);
$result = $repository->productCategoriesFront(10);
$this->assertCount(1, $result);
$this->assertEquals(3, $result[0]['category_id']);
}
/**
* Test productCategoriesFront - pusta tablica dla nieprawidłowego ID
*/
public function testProductCategoriesFrontReturnsEmptyForInvalidId()
{
$mockDb = $this->createMock(\medoo::class);
$repository = new ProductRepository($mockDb);
$this->assertEquals([], $repository->productCategoriesFront(0));
$this->assertEquals([], $repository->productCategoriesFront(-1));
}
/**
* Test getWarehouseMessageZero - zwraca wiadomość
*/
public function testGetWarehouseMessageZeroReturnsMessage()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with(
'pp_shop_products_langs',
'warehouse_message_zero',
['AND' => ['product_id' => 10, 'lang_id' => 'pl']]
)
->willReturn('Produkt niedostępny');
$repository = new ProductRepository($mockDb);
$this->assertEquals('Produkt niedostępny', $repository->getWarehouseMessageZero(10, 'pl'));
}
/**
* Test getWarehouseMessageZero - null dla nieprawidłowego ID
*/
public function testGetWarehouseMessageZeroReturnsNullForInvalidId()
{
$mockDb = $this->createMock(\medoo::class);
$repository = new ProductRepository($mockDb);
$this->assertNull($repository->getWarehouseMessageZero(0, 'pl'));
}
/**
* Test getWarehouseMessageNonzero - zwraca wiadomość
*/
public function testGetWarehouseMessageNonzeroReturnsMessage()
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with(
'pp_shop_products_langs',
'warehouse_message_nonzero',
['AND' => ['product_id' => 10, 'lang_id' => 'pl']]
)
->willReturn('Wysyłka w 24h');
$repository = new ProductRepository($mockDb);
$this->assertEquals('Wysyłka w 24h', $repository->getWarehouseMessageNonzero(10, 'pl'));
}
/**
* Test getWarehouseMessageNonzero - null dla nieprawidłowego ID
*/
public function testGetWarehouseMessageNonzeroReturnsNullForInvalidId()
{
$mockDb = $this->createMock(\medoo::class);
$repository = new ProductRepository($mockDb);
$this->assertNull($repository->getWarehouseMessageNonzero(0, 'pl'));
}
/**
* Test topProductIds - zwraca ID aktywnych produktów
*/
public function testTopProductIdsReturnsActiveProducts()
{
$mockDb = $this->createMock(\medoo::class);
$mockStmt = $this->createMock(\PDOStatement::class);
$mockStmt->method('fetchAll')->willReturn([
['sell_count' => 10, 'parent_product_id' => 1],
['sell_count' => 5, 'parent_product_id' => 2],
['sell_count' => 3, 'parent_product_id' => 3],
]);
$mockDb->method('query')->willReturn($mockStmt);
// isProductActiveCached sprawdza status — produkt 2 nieaktywny
$mockDb->method('get')
->willReturnCallback(function ($table, $column, $where) {
if ($column === 'status') {
return $where['id'] === 2 ? 0 : 1;
}
return null;
});
$repository = new ProductRepository($mockDb);
$result = $repository->topProductIds(6);
$this->assertIsArray($result);
$this->assertContains(1, $result);
$this->assertNotContains(2, $result);
$this->assertContains(3, $result);
}
/**
* Test newProductIds - zwraca ID produktów
*/
public function testNewProductIdsReturnsProductIds()
{
$mockDb = $this->createMock(\medoo::class);
$mockStmt = $this->createMock(\PDOStatement::class);
$mockStmt->method('fetchAll')->willReturn([
['id' => 10],
['id' => 20],
['id' => 30],
]);
$mockDb->method('query')->willReturn($mockStmt);
$repository = new ProductRepository($mockDb);
$result = $repository->newProductIds(3);
$this->assertIsArray($result);
$this->assertEquals([10, 20, 30], $result);
}
/**
* Test newProductIds - pusta lista
*/
public function testNewProductIdsReturnsEmptyWhenNoProducts()
{
$mockDb = $this->createMock(\medoo::class);
$mockStmt = $this->createMock(\PDOStatement::class);
$mockStmt->method('fetchAll')->willReturn([]);
$mockDb->method('query')->willReturn($mockStmt);
$repository = new ProductRepository($mockDb);
$this->assertEquals([], $repository->newProductIds(10));
}
/**
* Test promotedProductIdsCached - zwraca promowane produkty
*/
public function testPromotedProductIdsCachedReturnsIds()
{
$mockDb = $this->createMock(\medoo::class);
$mockStmt = $this->createMock(\PDOStatement::class);
$mockStmt->method('fetchAll')->willReturn([
['id' => 5],
['id' => 8],
]);
$mockDb->method('query')->willReturn($mockStmt);
$repository = new ProductRepository($mockDb);
$result = $repository->promotedProductIdsCached(2);
$this->assertIsArray($result);
$this->assertEquals([5, 8], $result);
}
/**
* Test promotedProductIdsCached - pusta lista
*/
public function testPromotedProductIdsCachedReturnsEmptyWhenNone()
{
$mockDb = $this->createMock(\medoo::class);
$mockStmt = $this->createMock(\PDOStatement::class);
$mockStmt->method('fetchAll')->willReturn([]);
$mockDb->method('query')->willReturn($mockStmt);
$repository = new ProductRepository($mockDb);
$this->assertEquals([], $repository->promotedProductIdsCached(6));
}
}