Files
zemailnator/tests/Unit/Models/PageTest.php
idevakk 3706072ce5 fix: resolve PSR-4 autoloading and test failures
- Add proper Tests\ namespace to all test classes in tests/Feature and tests/Unit
  - Split RemainingModelsTest.php into separate files (PSR-4 compliance)
  - Create missing factories: MetaFactory, RemoteEmailFactory
  - Add HasFactory trait to RemoteEmail model
  - Add missing ReflectionClass imports to test files
  - Fix mass assignment issues in Meta and RemoteEmail models
  - Override database connection for RemoteEmail in testing environment
  - Fix DateTime comparison precision issues in tests
2025-11-13 09:49:21 -08:00

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