added initial entries model
This commit is contained in:
parent
11f1dc6895
commit
a0a1c08ece
19 changed files with 487 additions and 6 deletions
19
tests/Unit/EntryModelTest.php
Normal file
19
tests/Unit/EntryModelTest.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Entry;
|
||||
|
||||
it('has correct fillable attributes', function () {
|
||||
$expected = [
|
||||
'title',
|
||||
'slug',
|
||||
'description',
|
||||
'is_published',
|
||||
'is_featured',
|
||||
'published_at',
|
||||
'content',
|
||||
];
|
||||
|
||||
$entry = new Entry();
|
||||
|
||||
expect($entry->getFillable())->toEqual($expected);
|
||||
});
|
||||
53
tests/Unit/EntryResourceTest.php
Normal file
53
tests/Unit/EntryResourceTest.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
use App\Filament\Resources\Entries\EntryResource;
|
||||
use App\Models\Entry;
|
||||
|
||||
it('references the correct model and record title attribute', function () {
|
||||
$defaults = (new ReflectionClass(EntryResource::class))->getDefaultProperties();
|
||||
|
||||
expect($defaults['model'] ?? null)->toBe(Entry::class);
|
||||
expect($defaults['recordTitleAttribute'] ?? null)->toBe('title');
|
||||
});
|
||||
|
||||
it('defines the expected pages', function () {
|
||||
$pages = EntryResource::getPages();
|
||||
|
||||
expect(array_keys($pages))->toEqual(['index', 'create', 'view', 'edit']);
|
||||
});
|
||||
|
||||
it('accepts new record when entered via the form schema', function () {
|
||||
|
||||
$data = [
|
||||
'title' => 'Test Entry',
|
||||
'slug' => 'test-entry',
|
||||
'description' => 'This is a test entry.',
|
||||
'is_published' => true,
|
||||
'is_featured' => false,
|
||||
'published_at' => now()->toDateString(),
|
||||
'content' => '<p>This is the content of the test entry.</p>',
|
||||
];
|
||||
|
||||
$entry = new Entry();
|
||||
$entry->fill($data);
|
||||
|
||||
expect($entry->slug)->toBe('test-entry');
|
||||
});
|
||||
|
||||
it('deletes a record correctly', function () {
|
||||
$entry = Entry::create([
|
||||
'title' => 'Test Entry to Delete',
|
||||
'slug' => 'test-entry-to-delete',
|
||||
'description' => 'This is a test entry.',
|
||||
'is_published' => false,
|
||||
'is_featured' => false,
|
||||
'published_at' => null,
|
||||
'content' => '<p>This is the content of the test entry.</p>',
|
||||
]);
|
||||
|
||||
$entryId = $entry->id;
|
||||
$entry->delete();
|
||||
|
||||
$deletedEntry = Entry::find($entryId);
|
||||
expect($deletedEntry)->toBeNull();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue