Files
zemailnator/tests/Unit/Models/PageTest.php
2025-11-14 01:51:35 -08:00

63 lines
1.7 KiB
PHP

<?php
namespace Tests\Unit\Models;
use App\Models\Page;
use Tests\TestCase;
class PageTest extends TestCase
{
/** @test */
public function it_can_create_a_page_with_factory()
{
$page = Page::factory()->create();
$this->assertInstanceOf(Page::class, $page);
$this->assertIsString($page->title);
$this->assertIsString($page->slug);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$pageData = [
'title' => 'About Us',
'slug' => 'about-us',
'content' => 'About us page content',
'meta' => [
'description' => 'About us meta description',
'keywords' => 'about,company',
],
'is_published' => true,
];
$page = Page::create($pageData);
foreach ($pageData as $key => $value) {
$this->assertEquals($value, $page->$key);
}
}
/** @test */
public function it_generates_unique_slugs()
{
$page1 = Page::factory()->create(['title' => 'Same Title']);
$page2 = Page::factory()->create(['title' => 'Same Title']);
$this->assertNotEquals($page1->slug, $page2->slug);
}
/** @test */
public function it_can_query_published_pages()
{
$publishedPage = Page::factory()->create(['is_published' => true]);
$draftPage = Page::factory()->create(['is_published' => false]);
$publishedPages = Page::where('is_published', true)->get();
$draftPages = Page::where('is_published', false)->get();
$this->assertCount(1, $publishedPages);
$this->assertCount(1, $draftPages);
}
}