diff --git a/Command/Web/IndexController.php b/Command/Web/IndexController.php index ac47b98..ba1dcb9 100644 --- a/Command/Web/IndexController.php +++ b/Command/Web/IndexController.php @@ -19,9 +19,10 @@ public function handle() $request = $this->getRequest(); if ($this->getApp()->config->site_index !== null) { + $indexTpl = $this->getApp()->config->site_index_tpl ?? 'content/single.html.twig'; $content = $content_provider->fetch($this->getApp()->config->site_index); if ($content) { - $response = new Response($twig->render('content/single.html.twig', [ + $response = new Response($twig->render($indexTpl, [ 'content' => $content ])); diff --git a/tests/Feature/CommandTest.php b/tests/Feature/CommandTest.php index b8f3b75..d76a738 100644 --- a/tests/Feature/CommandTest.php +++ b/tests/Feature/CommandTest.php @@ -5,6 +5,10 @@ $app->runCommand(['minicli', 'web', 'index']); })->expectOutputRegex("/template listing/"); +test('Custom Index page is correctly loaded', function () { + $app = getLibrarianIndex("posts/test0"); + $app->runCommand(['minicli', 'web', 'index']); +})->expectOutputRegex("/custom index/"); test('Content page posts/test0 is correctly loaded', function () { $app = getLibrarianContent('test0'); diff --git a/tests/Pest.php b/tests/Pest.php index 582c5b3..5ad76eb 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -47,9 +47,9 @@ | */ -function getLibrarianIndex(): App +function getLibrarianIndex(string $custom = null): App { - $app = new App([ + $config = [ 'app_path' => [ __DIR__ . '/../Command' ], @@ -57,8 +57,14 @@ function getLibrarianIndex(): App 'cache_path' => __DIR__ . '/Resources/cache', 'templates_path' => __DIR__ . '/Resources/templates', 'debug' => true - ]); + ]; + + if ($custom) { + $config['site_index'] = $custom; + $config['site_index_tpl'] = "content/custom_index.html.twig"; + } + $app = new App($config); $router = Mockery::mock(RouterServiceProvider::class); $request = Mockery::mock(Request::class); $request->shouldReceive('getParams'); diff --git a/tests/Resources/templates/content/custom_index.html.twig b/tests/Resources/templates/content/custom_index.html.twig new file mode 100644 index 0000000..fc2a680 --- /dev/null +++ b/tests/Resources/templates/content/custom_index.html.twig @@ -0,0 +1 @@ +custom index \ No newline at end of file