Skip to content

Commit 6d12a3e

Browse files
committed
Improved tests coverage, support to nested content types
1 parent 74f95a6 commit 6d12a3e

File tree

9 files changed

+71
-24
lines changed

9 files changed

+71
-24
lines changed

Command/Web/ContentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function handle(): void
3636
}
3737

3838
$start = ($page * $limit) - $limit;
39-
$contentType = $content_provider->getContentType($request->getRoute());
39+
$contentType = $content_provider->getContentType($request->getPath());
4040
$content_list = $content_provider->fetchFrom($contentType, $start, $limit);
4141
$response = new Response($twig->render('content/listing.html.twig', [
4242
'content_list' => $content_list,

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
}
1212
},
1313
"require": {
14-
"minicli/minicli": "^4.0",
15-
"librarianphp/librarian-core": "^4.0"
14+
"minicli/minicli": "^4.2.0",
15+
"librarianphp/librarian-core": "^4.5.0"
1616
},
1717
"require-dev": {
1818
"pestphp/pest": "^3.2",

composer.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/CommandTest.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
<?php
22

33
it('loads index page', function () {
4-
$app = getLibrarianIndex();
4+
$app = getLibrarian('/');
55
$app->runCommand(['minicli', 'web', 'index']);
66
})->expectOutputRegex('/template listing/');
77

88
it('loads custom index page', function () {
9-
$app = getLibrarianIndex('posts/test0');
9+
$app = getLibrarian('/', [], ['site_index' => 'posts/test0']);
10+
$app->runCommand(['minicli', 'web', 'index']);
11+
})->expectOutputRegex('/Devo Produzir Conteúdo em Português ou Inglês?/');
12+
13+
it('loads custom index template', function () {
14+
$app = getLibrarian('/', [], ['site_index' => 'posts/test0', 'site_index_tpl' => 'content/custom_index.html.twig']);
1015
$app->runCommand(['minicli', 'web', 'index']);
1116
})->expectOutputRegex('/custom index/');
1217

13-
it('loads ', function () {
14-
$app = getLibrarianContent('test0');
18+
it('loads single post', function () {
19+
$app = getLibrarian('/posts/test1');
20+
$app->runCommand(['minicli', 'web', 'content']);
21+
})->expectOutputRegex('/Testing Markdown Front Matter/');
22+
23+
it('loads nested content', function () {
24+
$app = getLibrarian('/docs/en/test0');
25+
$app->runCommand(['minicli', 'web', 'content']);
26+
})->expectOutputRegex('/Testing Sub-Level En/');
27+
28+
it('loads article list from base content type', function () {
29+
$app = getLibrarian('/posts');
1530
$app->runCommand(['minicli', 'web', 'content']);
16-
})->expectOutputRegex('/template single/');
31+
})->expectOutputRegex('/template listing Blog posts/');
1732

18-
test('Content page posts/test1 is correctly loaded', function () {
19-
$app = getLibrarianContent('test1');
33+
it('loads article list from nested content type', function () {
34+
$app = getLibrarian('/docs/en');
2035
$app->runCommand(['minicli', 'web', 'content']);
21-
})->expectOutputRegex('/template single/');
36+
})->expectOutputRegex('/template listing English Docs/');
2237

23-
test('Content page posts/test2 is correctly loaded', function () {
24-
$app = getLibrarianContent('test2');
38+
it('loads article list from parent content type', function () {
39+
$app = getLibrarian('/docs/');
2540
$app->runCommand(['minicli', 'web', 'content']);
26-
})->expectOutputRegex('/template single/');
41+
})->expectOutputRegex('/template listing Docs/');

tests/Pest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,28 @@
4343
|
4444
*/
4545

46-
function getLibrarian(Request $request): App {}
46+
function getLibrarian(string $requestUri, array $params = [], array $appConfig = []): App
47+
{
48+
$config = array_merge([
49+
'debug' => true,
50+
'templates_path' => __DIR__.'/Resources/templates',
51+
'data_path' => __DIR__.'/Resources/data',
52+
'cache_path' => sys_get_temp_dir(),
53+
], $appConfig);
54+
55+
$request = new Request($params, $requestUri);
56+
$router = Mockery::mock(RouterServiceProvider::class);
57+
$router->shouldReceive('load');
58+
$router->shouldReceive('getRequest')->andReturn($request);
59+
60+
$app = new App($config);
61+
$app->addService('content', new ContentServiceProvider);
62+
$app->addService('twig', new TwigServiceProvider);
63+
$app->addService('librarian', new LibrarianServiceProvider);
64+
$app->addService('router', $router);
65+
66+
return $app;
67+
}
4768

4869
function getLibrarianIndex(?string $custom = null): App
4970
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Portuguese Docs
3+
description: Portuguese Docs section
4+
index: 100
5+
---

tests/Resources/data/posts/_index

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Blog posts
3+
description: Blog section
4+
index: 100
5+
---
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
template listing
1+
template listing {{ content_type.title }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
template single
1+
template single {{ content.frontMatterGet('title') }}

0 commit comments

Comments
 (0)