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:
@@ -107,4 +107,111 @@ class LayoutsRepositoryTest extends TestCase
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertSame('Default', $rows[0]['name']);
|
||||
}
|
||||
|
||||
// ── Frontend methods tests ──────────────────────────────────
|
||||
|
||||
public function testCategoryDefaultLayoutIdReturnsId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_layouts', 'id', ['categories_default' => 1])
|
||||
->willReturn(7);
|
||||
|
||||
$repo = new LayoutsRepository($mockDb);
|
||||
$this->assertSame(7, $repo->categoryDefaultLayoutId());
|
||||
}
|
||||
|
||||
public function testCategoryDefaultLayoutIdReturnsNullWhenNone(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn(null);
|
||||
|
||||
$repo = new LayoutsRepository($mockDb);
|
||||
$this->assertNull($repo->categoryDefaultLayoutId());
|
||||
}
|
||||
|
||||
public function testGetDefaultLayoutReturnsLayoutFromDb(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_layouts', '*', ['status' => 1])
|
||||
->willReturn(['id' => 3, 'name' => 'Main', 'html' => '<h1>Test</h1>']);
|
||||
|
||||
$repo = new LayoutsRepository($mockDb);
|
||||
$layout = $repo->getDefaultLayout();
|
||||
|
||||
$this->assertSame(3, $layout['id']);
|
||||
$this->assertSame('Main', $layout['name']);
|
||||
}
|
||||
|
||||
public function testGetDefaultLayoutReturnsNullWhenNoLayout(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn(null);
|
||||
|
||||
$repo = new LayoutsRepository($mockDb);
|
||||
$this->assertNull($repo->getDefaultLayout());
|
||||
}
|
||||
|
||||
public function testGetArticleLayoutReturnsLayoutFromDb(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
'pp_layouts',
|
||||
['[><]pp_articles' => ['id' => 'layout_id']],
|
||||
'*',
|
||||
['pp_articles.id' => 10]
|
||||
)
|
||||
->willReturn(['id' => 2, 'name' => 'Article Layout', 'html' => '<div>art</div>']);
|
||||
|
||||
$repo = new LayoutsRepository($mockDb);
|
||||
$layout = $repo->getArticleLayout(10);
|
||||
|
||||
$this->assertSame(2, $layout['id']);
|
||||
}
|
||||
|
||||
public function testGetArticleLayoutReturnsNullWhenNoLayout(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn(null);
|
||||
|
||||
$repo = new LayoutsRepository($mockDb);
|
||||
$this->assertNull($repo->getArticleLayout(999));
|
||||
}
|
||||
|
||||
public function testGetActiveLayoutFallsBackToDefault(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('get')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
null,
|
||||
['id' => 1, 'name' => 'Default', 'html' => '<body>']
|
||||
);
|
||||
|
||||
$repo = new LayoutsRepository($mockDb);
|
||||
$layout = $repo->getActiveLayout(99);
|
||||
|
||||
$this->assertSame(1, $layout['id']);
|
||||
$this->assertSame('Default', $layout['name']);
|
||||
}
|
||||
|
||||
public function testGetActiveLayoutReturnsNullWhenNothingFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(null);
|
||||
|
||||
$repo = new LayoutsRepository($mockDb);
|
||||
$this->assertNull($repo->getActiveLayout(99));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user