66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Attachment;
|
|
use App\Models\Forum;
|
|
use App\Models\Post;
|
|
use App\Models\PostThank;
|
|
use App\Models\Thread;
|
|
use App\Models\User;
|
|
|
|
it('exposes post relationships', function (): void {
|
|
$category = Forum::create([
|
|
'name' => 'Category',
|
|
'description' => null,
|
|
'type' => 'category',
|
|
'parent_id' => null,
|
|
'position' => 1,
|
|
]);
|
|
$forum = Forum::create([
|
|
'name' => 'Forum',
|
|
'description' => null,
|
|
'type' => 'forum',
|
|
'parent_id' => $category->id,
|
|
'position' => 1,
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
$thread = Thread::create([
|
|
'forum_id' => $forum->id,
|
|
'user_id' => $user->id,
|
|
'title' => 'Thread',
|
|
'body' => 'Body',
|
|
]);
|
|
|
|
$post = Post::create([
|
|
'thread_id' => $thread->id,
|
|
'user_id' => $user->id,
|
|
'body' => 'Post body',
|
|
]);
|
|
|
|
$attachment = Attachment::create([
|
|
'thread_id' => null,
|
|
'post_id' => $post->id,
|
|
'attachment_extension_id' => null,
|
|
'attachment_group_id' => null,
|
|
'user_id' => $user->id,
|
|
'disk' => 'local',
|
|
'path' => 'attachments/posts/'.$post->id.'/file.pdf',
|
|
'original_name' => 'file.pdf',
|
|
'extension' => 'pdf',
|
|
'mime_type' => 'application/pdf',
|
|
'size_bytes' => 10,
|
|
]);
|
|
|
|
$thank = PostThank::create([
|
|
'post_id' => $post->id,
|
|
'user_id' => $user->id,
|
|
]);
|
|
|
|
$post->load(['thread', 'user', 'attachments', 'thanks']);
|
|
|
|
expect($post->thread->id)->toBe($thread->id);
|
|
expect($post->user->id)->toBe($user->id);
|
|
expect($post->attachments->first()->id)->toBe($attachment->id);
|
|
expect($post->thanks->first()->id)->toBe($thank->id);
|
|
});
|