52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Models;
|
|
|
|
use App\Models\Page;
|
|
use App\Models\PageLink;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class PageLinkTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_page_link_model_fillable_fields_and_relationships(): void
|
|
{
|
|
$source = Page::factory()->create(['url' => 'https://source.example.com/post/1']);
|
|
$target = Page::factory()->create(['url' => 'https://target.example.com/page/2']);
|
|
|
|
$link = PageLink::create([
|
|
'source_page_id' => $source->id,
|
|
'target_page_id' => $target->id,
|
|
]);
|
|
|
|
$fresh = $link->fresh();
|
|
|
|
$this->assertNotNull($fresh);
|
|
$this->assertSame($source->id, $fresh->source_page_id);
|
|
$this->assertSame($target->id, $fresh->target_page_id);
|
|
|
|
$this->assertInstanceOf(Page::class, $fresh->sourcePage);
|
|
$this->assertSame($source->id, $fresh->sourcePage->id);
|
|
|
|
$this->assertInstanceOf(Page::class, $fresh->targetPage);
|
|
$this->assertSame($target->id, $fresh->targetPage->id);
|
|
}
|
|
|
|
public function test_page_link_factory_with_source_and_target_methods_create_a_link(): void
|
|
{
|
|
$source = Page::factory()->create(['url' => 'https://source.example.com/post/1']);
|
|
$target = Page::factory()->create(['url' => 'https://target.example.com/page/2']);
|
|
|
|
$link = PageLink::factory()
|
|
->withSource($source)
|
|
->withTarget($target)
|
|
->create();
|
|
|
|
$this->assertSame($source->id, $link->source_page_id);
|
|
$this->assertSame($target->id, $link->target_page_id);
|
|
}
|
|
}
|