Skip to content

Commit e2232d1

Browse files
committed
group test cases config
1 parent 50f3cb6 commit e2232d1

File tree

9 files changed

+375
-397
lines changed

9 files changed

+375
-397
lines changed

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+
});

tests/src/Feature/PageTemplateTest.php

Lines changed: 65 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use SolutionForest\InspireCms\Tests\TestCase;
1313

1414
uses(TestCase::class);
15+
pest()->group('feature');
1516

1617
beforeEach(function () {
1718
// Add routes
@@ -31,89 +32,85 @@
3132
);
3233
});
3334

34-
describe('Page Template', function () {
35+
it('renders_page_template_correctly', function () {
3536

36-
it('renders_page_template_correctly', function () {
37+
$theme = $this->theme;
3738

38-
$theme = $this->theme;
39-
40-
$sampleTemplateContent = <<<'EOL'
39+
$sampleTemplateContent = <<<'EOL'
4140
<div class="page-template">
4241
<h1>@property('hero', 'title')</h1>
4342
<p>{{ $content->getTitle() }}</p>
4443
</div>
4544
EOL;
4645

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',
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',
7467
]),
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-
->create([
84-
'title' => 'Test Page',
85-
'slug' => 'test-page',
86-
]);
87-
$content->refresh();
88-
89-
// Create publish version
90-
$status = ContentStatusManifest::getOption('publish');
91-
$content->status = $status->getValue();
92-
$publishTime = now();
93-
$content->propertyData = json_encode([
94-
'hero' => [
95-
'title' => 'Test Hero Title',
96-
],
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',
9785
]);
98-
$content->setPublishableData([
99-
'published_at' => $publishTime,
100-
]);
101-
$content->setPublishableState($status->getName());
102-
$content->save();
86+
$content->refresh();
10387

104-
$content->refresh();
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();
105102

106-
// Visit the page
103+
$content->refresh();
107104

108-
$response = $this->get($content->getUrl());
105+
// Visit the page
109106

110-
// Assert response and content
107+
$response = $this->get($content->getUrl());
111108

112-
$response->assertStatus(200);
109+
// Assert response and content
113110

114-
$response->assertSee('Test Hero Title');
111+
$response->assertStatus(200);
115112

116-
$response->assertSee('Test Page');
117-
});
113+
$response->assertSee('Test Hero Title');
118114

119-
})->group('page-template', 'feature');
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/Unit/Facades/KeyValueCacheTest.php

Lines changed: 59 additions & 62 deletions
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('unit', 'facade');
89

910
function createSampleData($slug = null, $value = null)
1011
{
@@ -14,83 +15,79 @@ function createSampleData($slug = null, $value = null)
1415
]);
1516
}
1617

17-
describe('key vaue cache facade', function () {
18+
test('cacheAll stores all key-value pairs in cache', function () {
19+
// Create multiple test records
20+
$record1 = createSampleData('test_key1', 'test_value1');
21+
$record2 = createSampleData('test_key2', 'test_value2');
1822

19-
test('cacheAll stores all key-value pairs in cache', function () {
20-
// Create multiple test records
21-
$record1 = createSampleData('test_key1', 'test_value1');
22-
$record2 = createSampleData('test_key2', 'test_value2');
23+
// Call the cacheAll method which should cache all records
24+
KeyValueCache::cacheAll();
2325

24-
// Call the cacheAll method which should cache all records
25-
KeyValueCache::cacheAll();
26+
// Verify that getting these values returns the correct result from cache
27+
expect(KeyValueCache::get('test_key1'))->toBe('test_value1');
28+
expect(KeyValueCache::get('test_key2'))->toBe('test_value2');
29+
});
2630

27-
// Verify that getting these values returns the correct result from cache
28-
expect(KeyValueCache::get('test_key1'))->toBe('test_value1');
29-
expect(KeyValueCache::get('test_key2'))->toBe('test_value2');
30-
});
31+
test('set stores value in cache and can be retrieved', function () {
32+
$key = 'new_test_key';
33+
$value = 'new_test_value';
3134

32-
test('set stores value in cache and can be retrieved', function () {
33-
$key = 'new_test_key';
34-
$value = 'new_test_value';
35+
// Set the value in cache
36+
KeyValueCache::set($key, $value);
3537

36-
// Set the value in cache
37-
KeyValueCache::set($key, $value);
38+
// Verify it can be retrieved
39+
expect(KeyValueCache::get($key))->toBe($value);
40+
});
3841

39-
// Verify it can be retrieved
40-
expect(KeyValueCache::get($key))->toBe($value);
41-
});
42+
test('forget removes a value from cache', function () {
43+
$key = 'forget_test_key';
44+
$value = 'forget_test_value';
4245

43-
test('forget removes a value from cache', function () {
44-
$key = 'forget_test_key';
45-
$value = 'forget_test_value';
46+
// Create and cache a test record
47+
$record = createSampleData($key, $value);
48+
KeyValueCache::set($record->key, $record->value);
4649

47-
// Create and cache a test record
48-
$record = createSampleData($key, $value);
49-
KeyValueCache::set($record->key, $record->value);
50+
// Verify it's in cache
51+
expect(KeyValueCache::get($key))->toBe($value);
5052

51-
// Verify it's in cache
52-
expect(KeyValueCache::get($key))->toBe($value);
53+
// Forget the value
54+
KeyValueCache::forget($key);
5355

54-
// Forget the value
55-
KeyValueCache::forget($key);
56+
// The value should still be in the database but no longer in cache
57+
// Since the database is the fallback, we need to mock or spy on the cache
58+
// implementation to properly test this, but we can verify it still exists
59+
expect(KeyValue::where('key', $key)->exists())->toBeTrue();
60+
});
5661

57-
// The value should still be in the database but no longer in cache
58-
// Since the database is the fallback, we need to mock or spy on the cache
59-
// implementation to properly test this, but we can verify it still exists
60-
expect(KeyValue::where('key', $key)->exists())->toBeTrue();
61-
});
62-
63-
test('clear removes all values from cache', function () {
64-
// Create multiple test records and cache them
65-
$keys = ['clear_key1', 'clear_key2', 'clear_key3'];
66-
$values = ['clear_value1', 'clear_value2', 'clear_value3'];
62+
test('clear removes all values from cache', function () {
63+
// Create multiple test records and cache them
64+
$keys = ['clear_key1', 'clear_key2', 'clear_key3'];
65+
$values = ['clear_value1', 'clear_value2', 'clear_value3'];
6766

68-
foreach ($keys as $index => $key) {
69-
createSampleData($key, $values[$index]);
70-
KeyValueCache::set($key, $values[$index]);
71-
}
67+
foreach ($keys as $index => $key) {
68+
createSampleData($key, $values[$index]);
69+
KeyValueCache::set($key, $values[$index]);
70+
}
7271

73-
// Verify they're all in cache
74-
foreach ($keys as $index => $key) {
75-
expect(KeyValueCache::get($key))->toBe($values[$index]);
76-
}
72+
// Verify they're all in cache
73+
foreach ($keys as $index => $key) {
74+
expect(KeyValueCache::get($key))->toBe($values[$index]);
75+
}
7776

78-
// Clear the cache
79-
KeyValueCache::clear();
77+
// Clear the cache
78+
KeyValueCache::clear();
8079

81-
// All records should still exist in the database
82-
foreach ($keys as $key) {
83-
expect(KeyValue::where('key', $key)->exists())->toBeTrue();
84-
}
85-
});
86-
87-
test('get returns default value when key does not exist', function () {
88-
$nonExistentKey = 'non_existent_key_' . time();
89-
$defaultValue = 'default_test_value';
80+
// All records should still exist in the database
81+
foreach ($keys as $key) {
82+
expect(KeyValue::where('key', $key)->exists())->toBeTrue();
83+
}
84+
});
9085

91-
$result = KeyValueCache::get($nonExistentKey, $defaultValue);
86+
test('get returns default value when key does not exist', function () {
87+
$nonExistentKey = 'non_existent_key_' . time();
88+
$defaultValue = 'default_test_value';
9289

93-
expect($result)->toBe($defaultValue);
94-
});
90+
$result = KeyValueCache::get($nonExistentKey, $defaultValue);
9591

96-
})->group('unit', 'cache', 'key-value');
92+
expect($result)->toBe($defaultValue);
93+
});

0 commit comments

Comments
 (0)