'Admin', 'slug' => 'admin']); $user = User::factory()->create(); $user->roles()->attach($adminRole); return $user; } public function test_can_create_custom_post_type(): void { $admin = $this->setupAdmin(); $this->actingAs($admin); $response = $this->post(route('admin.custom-post-types.store'), [ 'name' => 'Books', 'singular_name' => 'Book', 'slug' => 'books', 'show_in_menu' => true, 'has_archive' => true, ]); $response->assertRedirect(route('admin.custom-post-types.index')); $this->assertDatabaseHas('custom_post_types', ['slug' => 'books']); } public function test_can_add_custom_fields_to_cpt(): void { $admin = $this->setupAdmin(); $this->actingAs($admin); $cpt = CustomPostType::create(['name' => 'Books', 'singular_name' => 'Book', 'slug' => 'books']); $response = $this->post(route('admin.custom-fields.store', $cpt), [ 'label' => 'Author', 'name' => 'author_name', 'type' => 'text', 'required' => true, ]); $response->assertRedirect(); $this->assertDatabaseHas('custom_fields', ['name' => 'author_name', 'custom_post_type_id' => $cpt->id]); } public function test_can_create_post_for_cpt(): void { $admin = $this->setupAdmin(); $this->actingAs($admin); $cpt = CustomPostType::create(['name' => 'Books', 'singular_name' => 'Book', 'slug' => 'books']); $response = $this->post(route('admin.posts.store', $cpt->slug), [ 'title' => 'My Book', 'slug' => 'my-book', 'content' => [['type' => 'paragraph', 'data' => ['text' => 'Some content']]], 'status' => 'published', ]); $response->assertRedirect(route('admin.posts.index', $cpt->slug)); $this->assertDatabaseHas('posts', ['slug' => 'my-book', 'custom_post_type_id' => $cpt->id]); } }