Skip to content

Commit 4174694

Browse files
committed
Merge branch 'feature/test_cases' into 1.x
* feature/test_cases: Fix styling group test cases config Fix styling Add test case: Test Blade templates to ensure they render correctly
2 parents 6aa0005 + bc29dce commit 4174694

File tree

13 files changed

+490
-330
lines changed

13 files changed

+490
-330
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
14+
return [
15+
'name' => $slug,
16+
'label' => $title,
17+
'type' => 'text', // Default type, can be overridden
18+
'sort' => 0,
19+
'mandatory' => false,
20+
'config' => [],
21+
];
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
14+
return [
15+
'title' => $title,
16+
'name' => $slug,
17+
'active' => true,
18+
'sort' => 0,
19+
];
20+
}
21+
}
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+
}

tests/src/Feature/Livewire/DocumentTypePaginatorTest.php

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,37 @@
88

99
uses(TestCase::class);
1010
// uses(RefreshDatabase::class);
11+
pest()->group('feature', 'livewire');
1112

12-
describe('document type paginator', function () {
13+
it('can paginate document types', function () {
14+
DocumentType::factory(['show_at_root' => true])
15+
->count(30)
16+
->create();
1317

14-
it('can paginate document types', function () {
15-
DocumentType::factory(['show_at_root' => true])
16-
->count(30)
17-
->create();
18+
Livewire::test(DocumentTypePaginator::class)
19+
->assertSee('Next');
20+
});
1821

19-
Livewire::test(DocumentTypePaginator::class)
20-
->assertSee('Next');
21-
});
22+
it('can search document types', function () {
23+
DocumentType::factory()->create(['title' => 'Test Document Type', 'show_at_root' => true]);
24+
DocumentType::factory()->create(['title' => 'Another Type', 'show_at_root' => true]);
2225

23-
it('can search document types', function () {
24-
DocumentType::factory()->create(['title' => 'Test Document Type', 'show_at_root' => true]);
25-
DocumentType::factory()->create(['title' => 'Another Type', 'show_at_root' => true]);
26+
Livewire::test(DocumentTypePaginator::class)
27+
->set('search', 'Test')
28+
->assertSee('Test Document Type')
29+
->assertDontSee('Another Type');
30+
});
2631

27-
Livewire::test(DocumentTypePaginator::class)
28-
->set('search', 'Test')
29-
->assertSee('Test Document Type')
30-
->assertDontSee('Another Type');
31-
});
32+
it('resets page when search is updated', function () {
3233

33-
it('resets page when search is updated', function () {
34+
DocumentType::factory(['show_at_root' => true])
35+
->count(30)
36+
->create();
3437

35-
DocumentType::factory(['show_at_root' => true])
36-
->count(30)
37-
->create();
38+
$pageName = DocumentTypePaginator::PAGE_NAME;
3839

39-
$pageName = DocumentTypePaginator::PAGE_NAME;
40-
41-
Livewire::test(DocumentTypePaginator::class)
42-
->set('paginators', [$pageName => 2])
43-
->set('search', 'Test')
44-
->assertSet('paginators', [$pageName => 1]);
45-
});
46-
47-
})->group('feature', 'livewire');
40+
Livewire::test(DocumentTypePaginator::class)
41+
->set('paginators', [$pageName => 2])
42+
->set('search', 'Test')
43+
->assertSet('paginators', [$pageName => 1]);
44+
});
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
pest()->group('feature');
16+
17+
beforeEach(function () {
18+
// Add routes
19+
\SolutionForest\InspireCms\Facades\InspireCms::routes();
20+
21+
// Ensure the default language is set
22+
$defaultLangCode = 'en';
23+
Language::updateOrCreate(
24+
['code' => $defaultLangCode],
25+
['is_default' => true]
26+
);
27+
// Ensure the theme is set up correctly
28+
$this->theme = 'default'; // Set the theme to default
29+
KeyValue::updateOrCreate(
30+
['key' => TemplateHelper::getCurrentThemeKey()],
31+
['value' => $this->theme]
32+
);
33+
});
34+
35+
it('renders_page_template_correctly', function () {
36+
37+
$theme = $this->theme;
38+
39+
$sampleTemplateContent = <<<'EOL'
40+
<div class="page-template">
41+
<h1>@property('hero', 'title')</h1>
42+
<p>{{ $content->getTitle() }}</p>
43+
</div>
44+
EOL;
45+
46+
// Create a test content record
47+
$content = Content::factory()
48+
->for(
49+
DocumentType::factory()
50+
->hasAttached(
51+
Template::factory()
52+
->create([
53+
'slug' => 'page', // Ensure the template is named 'page'
54+
'content' => [
55+
$theme => $sampleTemplateContent,
56+
],
57+
]),
58+
['is_default' => true] // Set as default template
59+
)
60+
->has(
61+
FieldGroup::factory()
62+
->has(
63+
Field::factory([
64+
'name' => 'title',
65+
'label' => 'Hero Title',
66+
'type' => 'text',
67+
]),
68+
'fields'
69+
)
70+
->state([
71+
'title' => 'Hero',
72+
'name' => 'hero',
73+
]),
74+
'fieldGroups'
75+
)
76+
->create([
77+
'title' => 'Page Document Type',
78+
'slug' => 'page-document-type',
79+
'category' => 'web', // Ensure it's a web type document
80+
])
81+
)
82+
->create([
83+
'title' => 'Test Page',
84+
'slug' => 'test-page',
85+
]);
86+
$content->refresh();
87+
88+
// Create publish version
89+
$status = ContentStatusManifest::getOption('publish');
90+
$content->status = $status->getValue();
91+
$publishTime = now();
92+
$content->propertyData = json_encode([
93+
'hero' => [
94+
'title' => 'Test Hero Title',
95+
],
96+
]);
97+
$content->setPublishableData([
98+
'published_at' => $publishTime,
99+
]);
100+
$content->setPublishableState($status->getName());
101+
$content->save();
102+
103+
$content->refresh();
104+
105+
// Visit the page
106+
107+
$response = $this->get($content->getUrl());
108+
109+
// Assert response and content
110+
111+
$response->assertStatus(200);
112+
113+
$response->assertSee('Test Hero Title');
114+
115+
$response->assertSee('Test Page');
116+
});

tests/src/Feature/Resources/ExtraResourceTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use SolutionForest\InspireCms\Tests\TestCase;
66

77
uses(TestCase::class);
8+
pest()->group('feature', 'fi-resource');
89

910
beforeEach(function () {
1011
$this->panelPath = '/' . InspireCmsConfig::get('admin.path', 'cms');
@@ -18,4 +19,4 @@
1819
$this->loginCmsPanelAsSuperAdmin()
1920
->get($url)
2021
->assertStatus(200);
21-
})->group('resource', 'feature');
22+
});

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)