Skip to content

Commit 5eb8f4d

Browse files
committed
Add test case: Test Blade templates to ensure they render correctly
1 parent 189165c commit 5eb8f4d

File tree

5 files changed

+182
-0
lines changed

5 files changed

+182
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace SolutionForest\InspireCms\Tests\Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
class FieldFactory extends Factory
8+
{
9+
public function definition()
10+
{
11+
$slug = $this->faker->unique()->slug(1);
12+
$title = str($slug)->replace('-', ' ')->ucfirst()->toString();
13+
return [
14+
'name' => $slug,
15+
'label' => $title,
16+
'type' => 'text', // Default type, can be overridden
17+
'sort' => 0,
18+
'mandatory' => false,
19+
'config' => [],
20+
];
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace SolutionForest\InspireCms\Tests\Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
class FieldGroupFactory extends Factory
8+
{
9+
public function definition()
10+
{
11+
$slug = $this->faker->unique()->slug(1);
12+
$title = str($slug)->replace('-', ' ')->ucfirst()->toString();
13+
return [
14+
'title' => $title,
15+
'name' => $slug,
16+
'active' => true,
17+
'sort' => 0,
18+
];
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace SolutionForest\InspireCms\Tests\Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
class TemplateFactory extends Factory
8+
{
9+
public function definition()
10+
{
11+
return [
12+
'slug' => $this->faker->unique()->slug(1),
13+
];
14+
}
15+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
use SolutionForest\InspireCms\Facades\ContentStatusManifest;
4+
use SolutionForest\InspireCms\Helpers\TemplateHelper;
5+
use SolutionForest\InspireCms\Tests\Models\Content;
6+
use SolutionForest\InspireCms\Tests\Models\DocumentType;
7+
use SolutionForest\InspireCms\Tests\Models\Field;
8+
use SolutionForest\InspireCms\Tests\Models\FieldGroup;
9+
use SolutionForest\InspireCms\Tests\Models\KeyValue;
10+
use SolutionForest\InspireCms\Tests\Models\Language;
11+
use SolutionForest\InspireCms\Tests\Models\Template;
12+
use SolutionForest\InspireCms\Tests\TestCase;
13+
14+
uses(TestCase::class);
15+
16+
beforeEach(function () {
17+
// Add routes
18+
\SolutionForest\InspireCms\Facades\InspireCms::routes();
19+
20+
// Ensure the default language is set
21+
$defaultLangCode = 'en';
22+
Language::updateOrCreate(
23+
['code' => $defaultLangCode],
24+
['is_default' => true,]
25+
);
26+
// Ensure the theme is set up correctly
27+
$this->theme = 'default'; // Set the theme to default
28+
KeyValue::updateOrCreate(
29+
['key' => TemplateHelper::getCurrentThemeKey()],
30+
['value' => $this->theme]
31+
);
32+
});
33+
34+
describe('Page Template', function () {
35+
36+
it('renders_page_template_correctly', function () {
37+
38+
$theme = $this->theme;
39+
40+
$sampleTemplateContent = <<<EOL
41+
<div class="page-template">
42+
<h1>@property('hero', 'title')</h1>
43+
<p>{{ \$content->getTitle() }}</p>
44+
</div>
45+
EOL;
46+
47+
// Create a test content record
48+
$content = Content::factory()
49+
->for(
50+
DocumentType::factory()
51+
->hasAttached(
52+
Template::factory()
53+
->create([
54+
'slug' => 'page', // Ensure the template is named 'page'
55+
'content' => [
56+
$theme => $sampleTemplateContent,
57+
]
58+
]),
59+
['is_default' => true] // Set as default template
60+
)
61+
->has(
62+
FieldGroup::factory()
63+
->has(
64+
Field::factory([
65+
'name' => 'title',
66+
'label' => 'Hero Title',
67+
'type' => 'text',
68+
]),
69+
'fields'
70+
)
71+
->state([
72+
'title' => 'Hero',
73+
'name' => 'hero',
74+
]),
75+
'fieldGroups'
76+
)
77+
->create([
78+
'title' => 'Page Document Type',
79+
'slug' => 'page-document-type',
80+
'category' => 'web', // Ensure it's a web type document
81+
])
82+
83+
)
84+
->create([
85+
'title' => 'Test Page',
86+
'slug' => 'test-page',
87+
]);
88+
$content->refresh();
89+
90+
// Create publish version
91+
$status = ContentStatusManifest::getOption('publish');
92+
$content->status = $status->getValue();
93+
$publishTime = now();
94+
$content->propertyData = json_encode([
95+
'hero' => [
96+
'title' => 'Test Hero Title',
97+
],
98+
]);
99+
$content->setPublishableData([
100+
'published_at' => $publishTime,
101+
]);
102+
$content->setPublishableState($status->getName());
103+
$content->save();
104+
105+
$content->refresh();
106+
107+
// Visit the page
108+
109+
$response = $this->get($content->getUrl());
110+
111+
// Assert response and content
112+
113+
$response->assertStatus(200);
114+
115+
$response->assertSee('Test Hero Title');
116+
117+
$response->assertSee('Test Page');
118+
});
119+
120+
})->group('page-template', 'feature');

tests/src/TestCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ protected function getPackageProviders($app)
6262
\Spatie\Permission\PermissionServiceProvider::class,
6363

6464
FilamentFieldGroupServiceProvider::class,
65+
66+
\Staudenmeir\LaravelAdjacencyList\IdeHelperServiceProvider::class,
67+
\Kirschbaum\PowerJoins\PowerJoinsServiceProvider::class,
68+
6569
\Kalnoy\Nestedset\NestedSetServiceProvider::class,
6670

6771
\Pboivin\FilamentPeek\FilamentPeekServiceProvider::class,
@@ -169,6 +173,7 @@ protected function defineDatabaseMigrations()
169173

170174
// plugin migrations
171175
$this->loadMigrationsFrom([
176+
__DIR__ . '/../../vendor/solution-forest/filament-field-group/database/migrations',
172177
__DIR__ . '/../../vendor/solution-forest/inspirecms-support/database/migrations',
173178
// __DIR__ . '/../../vendor/spatie/laravel-permission/database/migrations',
174179
// __DIR__ . '/../../vendor/spatie/laravel-medialibrary/database/migrations',

0 commit comments

Comments
 (0)