ver. 0.286: Layouts, Menu, Pages frontend migration to Domain
- Add 6 frontend methods to LayoutsRepository (Redis cache, 3-level fallback) - Add 6 frontend methods to PagesRepository (Redis cache, recursive pages) - Create front\Views\Menu (clean VIEW replacing front\view\Menu) - Delete front\factory\Layouts, Menu, Pages + front\view\Menu + dead submenu.php - Fix null $lang_id TypeError in check_url_params() (remove string type hint + ?? '') - Optimize Helpers::htacces() from 3 layout calls to 1 - Tests: 470 OK, 1484 assertions (+16 new) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -63,4 +63,111 @@ class PagesRepositoryTest extends TestCase
|
||||
|
||||
$this->assertSame('/en/about-us', $url);
|
||||
}
|
||||
|
||||
// ── Frontend methods tests ──────────────────────────────────
|
||||
|
||||
public function testFrontPageDetailsReturnsPageWithLanguage(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('get')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['id' => 5, 'menu_id' => 1, 'status' => 1, 'page_type' => 0],
|
||||
['page_id' => 5, 'lang_id' => 'pl', 'title' => 'O nas', 'seo_link' => 'o-nas']
|
||||
);
|
||||
|
||||
$repo = new PagesRepository($mockDb);
|
||||
$page = $repo->frontPageDetails(5, 'pl');
|
||||
|
||||
$this->assertSame(5, $page['id']);
|
||||
$this->assertSame('O nas', $page['language']['title']);
|
||||
}
|
||||
|
||||
public function testFrontPageDetailsReturnsNullWhenNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(null);
|
||||
|
||||
$repo = new PagesRepository($mockDb);
|
||||
$this->assertNull($repo->frontPageDetails(999, 'pl'));
|
||||
}
|
||||
|
||||
public function testFrontMainPageIdReturnsStartPage(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_pages', 'id', ['AND' => ['status' => 1, 'start' => 1]])
|
||||
->willReturn(3);
|
||||
|
||||
$repo = new PagesRepository($mockDb);
|
||||
$this->assertSame(3, $repo->frontMainPageId());
|
||||
}
|
||||
|
||||
public function testFrontMainPageIdFallsBackToFirstActive(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('get')
|
||||
->willReturnOnConsecutiveCalls(null, 7);
|
||||
|
||||
$repo = new PagesRepository($mockDb);
|
||||
$this->assertSame(7, $repo->frontMainPageId());
|
||||
}
|
||||
|
||||
public function testFrontPageSortReturnsValue(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_pages', 'sort_type', ['id' => 5])
|
||||
->willReturn(2);
|
||||
|
||||
$repo = new PagesRepository($mockDb);
|
||||
$this->assertSame(2, $repo->frontPageSort(5));
|
||||
}
|
||||
|
||||
public function testFrontMenuDetailsReturnsMenuWithPages(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_menus', '*', ['id' => 1])
|
||||
->willReturn(['id' => 1, 'name' => 'Main']);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->willReturn([]);
|
||||
|
||||
$repo = new PagesRepository($mockDb);
|
||||
$menu = $repo->frontMenuDetails(1, 'pl');
|
||||
|
||||
$this->assertSame(1, $menu['id']);
|
||||
$this->assertSame('Main', $menu['name']);
|
||||
$this->assertSame([], $menu['pages']);
|
||||
}
|
||||
|
||||
public function testFrontMenuDetailsReturnsNullForInvalidMenu(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn(null);
|
||||
|
||||
$repo = new PagesRepository($mockDb);
|
||||
$this->assertNull($repo->frontMenuDetails(999, 'pl'));
|
||||
}
|
||||
|
||||
public function testFrontMenuPagesReturnsEmptyForNoPages(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->willReturn([]);
|
||||
|
||||
$repo = new PagesRepository($mockDb);
|
||||
$pages = $repo->frontMenuPages(1, 'pl');
|
||||
|
||||
$this->assertSame([], $pages);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user