added initial entries model

This commit is contained in:
jon brookes 2026-01-02 13:58:06 +00:00
parent 11f1dc6895
commit a0a1c08ece
19 changed files with 487 additions and 6 deletions

View file

@ -13,7 +13,7 @@
pest()->extend(Tests\TestCase::class)
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
->in('Feature');
->in('Feature', 'Unit');
/*
|--------------------------------------------------------------------------

View file

@ -6,5 +6,15 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
/**
* Creates the application.
*/
public function createApplication(): \Illuminate\Foundation\Application
{
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
}

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

View 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();
});