ver. 0.289: ShopCategory + ShopClient frontend migration to Domain + Views + Controllers
ShopCategory: 9 frontend methods in CategoryRepository, front\Views\ShopCategory (3 methods), deleted factory + view, updated 6 callers, +17 tests. ShopClient: 13 frontend methods in ClientRepository, front\Views\ShopClient (8 methods), front\Controllers\ShopClientController (15 methods + buildEmailBody helper), deleted factory + view + controls, updated 7 callers, +36 tests. Security fix: removed hardcoded password bypass 'Legia1916'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -205,4 +205,262 @@ class CategoryRepositoryTest extends TestCase
|
||||
|
||||
$this->assertSame('Kategoria testowa', $repository->categoryTitle(10));
|
||||
}
|
||||
|
||||
// ===== Frontend methods tests =====
|
||||
|
||||
public function testGetCategorySortReturnsZeroForInvalidId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('get');
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame(0, $repository->getCategorySort(0));
|
||||
$this->assertSame(0, $repository->getCategorySort(-1));
|
||||
}
|
||||
|
||||
public function testGetCategorySortReturnsSortType(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')
|
||||
->with('pp_shop_categories', 'sort_type', ['id' => 5])
|
||||
->willReturn('3');
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame(3, $repository->getCategorySort(5));
|
||||
}
|
||||
|
||||
public function testCategoryNameReturnsEmptyForInvalidInput(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('get');
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame('', $repository->categoryName(0, 'pl'));
|
||||
$this->assertSame('', $repository->categoryName(5, ''));
|
||||
}
|
||||
|
||||
public function testCategoryNameReturnsTitle(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')
|
||||
->with('pp_shop_categories_langs', 'title', [
|
||||
'AND' => [
|
||||
'category_id' => 10,
|
||||
'lang_id' => 'pl',
|
||||
],
|
||||
])
|
||||
->willReturn('Elektronika');
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame('Elektronika', $repository->categoryName(10, 'pl'));
|
||||
}
|
||||
|
||||
public function testCategoryNameReturnsEmptyWhenNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(null);
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame('', $repository->categoryName(10, 'pl'));
|
||||
}
|
||||
|
||||
public function testFrontCategoryDetailsReturnsEmptyForInvalidId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('get');
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame([], $repository->frontCategoryDetails(0, 'pl'));
|
||||
$this->assertSame([], $repository->frontCategoryDetails(-1, 'en'));
|
||||
}
|
||||
|
||||
public function testFrontCategoryDetailsReturnsCategoryWithLanguage(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$callIndex = 0;
|
||||
$mockDb->method('get')
|
||||
->willReturnCallback(function ($table) use (&$callIndex) {
|
||||
$callIndex++;
|
||||
if ($table === 'pp_shop_categories') {
|
||||
return [
|
||||
'id' => 7,
|
||||
'status' => 1,
|
||||
'sort_type' => 2,
|
||||
'parent_id' => null,
|
||||
];
|
||||
}
|
||||
if ($table === 'pp_shop_categories_langs') {
|
||||
return [
|
||||
'category_id' => 7,
|
||||
'lang_id' => 'pl',
|
||||
'title' => 'Odzież',
|
||||
'seo_link' => 'odziez',
|
||||
];
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
$result = $repository->frontCategoryDetails(7, 'pl');
|
||||
|
||||
$this->assertSame(7, $result['id']);
|
||||
$this->assertSame('Odzież', $result['language']['title']);
|
||||
$this->assertSame('odziez', $result['language']['seo_link']);
|
||||
}
|
||||
|
||||
public function testFrontCategoryDetailsReturnsEmptyWhenCategoryNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(null);
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame([], $repository->frontCategoryDetails(999, 'pl'));
|
||||
}
|
||||
|
||||
public function testCategoriesTreeReturnsEmptyWhenNoCategories(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('select')->willReturn([]);
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame([], $repository->categoriesTree('pl'));
|
||||
}
|
||||
|
||||
public function testCategoryProductsCountReturnsZeroForInvalidInput(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('query');
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame(0, $repository->categoryProductsCount(0, 'pl'));
|
||||
$this->assertSame(0, $repository->categoryProductsCount(5, ''));
|
||||
}
|
||||
|
||||
public function testCategoryProductsCountReturnsCount(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->method('fetchAll')->willReturn([[15]]);
|
||||
|
||||
$mockDb->method('query')->willReturn($stmt);
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame(15, $repository->categoryProductsCount(3, 'pl'));
|
||||
}
|
||||
|
||||
public function testProductsIdReturnsEmptyForInvalidInput(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('query');
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame([], $repository->productsId(0, 0, 'pl', 12, 0));
|
||||
$this->assertSame([], $repository->productsId(5, 0, '', 12, 0));
|
||||
}
|
||||
|
||||
public function testProductsIdReturnsProductIds(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->method('fetchAll')->willReturn([
|
||||
['id' => 101],
|
||||
['id' => 102],
|
||||
['id' => 103],
|
||||
]);
|
||||
|
||||
$mockDb->method('query')->willReturn($stmt);
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
$result = $repository->productsId(5, 1, 'pl', 12, 0);
|
||||
|
||||
$this->assertSame([101, 102, 103], $result);
|
||||
}
|
||||
|
||||
public function testBlogCategoryProductsReturnsEmptyForInvalidInput(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('query');
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
$this->assertSame([], $repository->blogCategoryProducts(0, 'pl', 5));
|
||||
$this->assertSame([], $repository->blogCategoryProducts(5, '', 5));
|
||||
$this->assertSame([], $repository->blogCategoryProducts(5, 'pl', 0));
|
||||
}
|
||||
|
||||
public function testBlogCategoryProductsReturnsIds(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->method('fetchAll')->willReturn([
|
||||
['id' => 201],
|
||||
['id' => 202],
|
||||
]);
|
||||
|
||||
$mockDb->method('query')->willReturn($stmt);
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
$result = $repository->blogCategoryProducts(3, 'pl', 5);
|
||||
|
||||
$this->assertSame([201, 202], $result);
|
||||
}
|
||||
|
||||
public function testPaginatedCategoryProductsReturnsEmptyWhenNoProducts(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->method('fetchAll')->willReturn([[0]]);
|
||||
|
||||
$mockDb->method('query')->willReturn($stmt);
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
$result = $repository->paginatedCategoryProducts(5, 0, 'pl', 1);
|
||||
|
||||
$this->assertSame([], $result['products']);
|
||||
$this->assertSame(0, $result['ls']);
|
||||
}
|
||||
|
||||
public function testPaginatedCategoryProductsClampsPage(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$countStmt = $this->createMock(\PDOStatement::class);
|
||||
$countStmt->method('fetchAll')->willReturn([[25]]);
|
||||
|
||||
$productsStmt = $this->createMock(\PDOStatement::class);
|
||||
$productsStmt->method('fetchAll')->willReturn([
|
||||
['id' => 301],
|
||||
['id' => 302],
|
||||
]);
|
||||
|
||||
$callIndex = 0;
|
||||
$mockDb->method('query')
|
||||
->willReturnCallback(function () use (&$callIndex, $countStmt, $productsStmt) {
|
||||
$callIndex++;
|
||||
return $callIndex === 1 ? $countStmt : $productsStmt;
|
||||
});
|
||||
|
||||
$repository = new CategoryRepository($mockDb);
|
||||
|
||||
// 25 products / 12 per page = 3 pages; page 99 should clamp to 3
|
||||
$result = $repository->paginatedCategoryProducts(5, 0, 'pl', 99);
|
||||
$this->assertSame(3, $result['ls']);
|
||||
$this->assertSame([301, 302], $result['products']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user