ver. 0.293: Code review fixes — 6 repositories, 16 fixes
- ArticleRepository: SQL injection fix (addslashes→parameterized), DRY refactor topArticles/newsListArticles
- AttributeRepository: dead class_exists('\S') blocking cache/temp clear
- CategoryRepository: dead class_exists('\S') blocking SEO link generation (critical)
- BannerRepository: parameterize $today in SQL + null guard on query()
- BasketCalculator: null guard checkProductQuantityInStock + optional DI params
- PromotionRepository: null guard on $basket (production fatal)
- OrderRepository/ShopBasketController/ajax.php: explicit DI in BasketCalculator callers
614 tests, 1821 assertions (+4 new)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -691,15 +691,16 @@ class ArticleRepositoryTest extends TestCase
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('get')
|
||||
->with('pp_articles', '*', ['id' => 5])
|
||||
->willReturn(['id' => 5, 'status' => 1, 'show_title' => 1]);
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['id' => 5, 'status' => 1, 'show_title' => 1],
|
||||
['lang_id' => 'pl', 'title' => 'Testowy', 'copy_from' => null]
|
||||
);
|
||||
|
||||
$mockDb->expects($this->exactly(4))
|
||||
$mockDb->expects($this->exactly(3))
|
||||
->method('select')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[['lang_id' => 'pl', 'title' => 'Testowy', 'copy_from' => null]],
|
||||
[['id' => 10, 'src' => '/img/a.jpg']],
|
||||
[['id' => 20, 'src' => '/files/a.pdf']],
|
||||
[1, 2]
|
||||
@@ -732,20 +733,17 @@ class ArticleRepositoryTest extends TestCase
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->method('get')
|
||||
->willReturn(['id' => 7, 'status' => 1]);
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['id' => 7, 'status' => 1],
|
||||
['lang_id' => 'en', 'title' => 'English', 'copy_from' => 'pl'],
|
||||
['lang_id' => 'pl', 'title' => 'Polski']
|
||||
);
|
||||
|
||||
$mockDb->expects($this->exactly(5))
|
||||
$mockDb->expects($this->exactly(3))
|
||||
->method('select')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
// First call: langs with copy_from
|
||||
[['lang_id' => 'en', 'title' => 'English', 'copy_from' => 'pl']],
|
||||
// Second call: copy_from fallback
|
||||
[['lang_id' => 'pl', 'title' => 'Polski']],
|
||||
// images
|
||||
[],
|
||||
// files
|
||||
[],
|
||||
// pages
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -917,11 +915,13 @@ class ArticleRepositoryTest extends TestCase
|
||||
});
|
||||
|
||||
$mockDb->method('get')
|
||||
->willReturn(['id' => 5, 'status' => 1]);
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['id' => 5, 'status' => 1],
|
||||
['lang_id' => 'pl', 'title' => 'Popular', 'copy_from' => null]
|
||||
);
|
||||
|
||||
$mockDb->method('select')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[['lang_id' => 'pl', 'title' => 'Popular', 'copy_from' => null]],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
@@ -952,11 +952,13 @@ class ArticleRepositoryTest extends TestCase
|
||||
});
|
||||
|
||||
$mockDb->method('get')
|
||||
->willReturn(['id' => 8, 'status' => 1]);
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['id' => 8, 'status' => 1],
|
||||
['lang_id' => 'pl', 'title' => 'Newest', 'copy_from' => null]
|
||||
);
|
||||
|
||||
$mockDb->method('select')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[['lang_id' => 'pl', 'title' => 'Newest', 'copy_from' => null]],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
|
||||
@@ -64,4 +64,25 @@ class BasketCalculatorTest extends TestCase
|
||||
$this->assertSame('3 produkty', BasketCalculator::countProductsText('3'));
|
||||
$this->assertSame('0 produktów', BasketCalculator::countProductsText('abc'));
|
||||
}
|
||||
|
||||
public function testCheckProductQuantityInStockReturnsFalseOnNullBasket(): void
|
||||
{
|
||||
$this->assertFalse(BasketCalculator::checkProductQuantityInStock(null));
|
||||
}
|
||||
|
||||
public function testCheckProductQuantityInStockReturnsFalseOnEmptyBasket(): void
|
||||
{
|
||||
$this->assertFalse(BasketCalculator::checkProductQuantityInStock([]));
|
||||
}
|
||||
|
||||
public function testValidateBasketReturnsEmptyArrayOnNull(): void
|
||||
{
|
||||
$this->assertSame([], BasketCalculator::validateBasket(null));
|
||||
}
|
||||
|
||||
public function testValidateBasketReturnsBasketArrayAsIs(): void
|
||||
{
|
||||
$basket = [['product-id' => 1, 'quantity' => 2]];
|
||||
$this->assertSame($basket, BasketCalculator::validateBasket($basket));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user