set('helpdesk.disk', 'local'); $fixtures = $this->seedLookupData(); $user = $this->user(['name' => 'Attachment Create User']); $file = UploadedFile::fake()->create('warehouse-error.log', 12, 'text/plain'); Livewire::actingAs($user) ->test(TicketCreate::class) ->set('subject', 'Create ticket with one attachment') ->set('body', '
This ticket must persist a Livewire upload attachment.
') ->set('board_id', $fixtures['board']->id) ->set('priority_id', $fixtures['high']->id) ->set('category_id', $fixtures['category']->id) ->set('team_id', $fixtures['team']->id) ->set('project_id', $fixtures['project']->id) ->set('attachments', [$file]) ->call('save') ->assertHasNoErrors() ->assertRedirect(route('helpdesk.tickets.index')); $ticket = Ticket::query() ->where('subject', 'Create ticket with one attachment') ->firstOrFail(); $attachment = Attachment::query() ->where('ticket_id', $ticket->id) ->whereNull('comment_id') ->firstOrFail(); self::assertSame($user->id, (int) $attachment->user_id); self::assertSame('local', $attachment->disk); self::assertSame('warehouse-error.log', $attachment->original_name); self::assertSame('log', $attachment->extension()); Storage::disk('local')->assertExists($attachment->path); } public function test_ticket_create_persists_multiple_attachments_through_livewire(): void { Storage::fake('local'); config()->set('helpdesk.disk', 'local'); $fixtures = $this->seedLookupData(); $user = $this->user(['name' => 'Multiple Attachment User']); Livewire::actingAs($user) ->test(TicketCreate::class) ->set('subject', 'Create ticket with multiple attachments') ->set('body', 'This ticket must persist every selected Livewire upload.
') ->set('board_id', $fixtures['board']->id) ->set('priority_id', $fixtures['normal']->id) ->set('category_id', $fixtures['category']->id) ->set('team_id', $fixtures['team']->id) ->set('project_id', $fixtures['project']->id) ->set('attachments', [ UploadedFile::fake()->create('first-proof.pdf', 20, 'application/pdf'), UploadedFile::fake()->create('second-proof.txt', 8, 'text/plain'), UploadedFile::fake()->create('third-proof.csv', 6, 'text/csv'), ]) ->call('save') ->assertHasNoErrors() ->assertRedirect(route('helpdesk.tickets.index')); $ticket = Ticket::query() ->where('subject', 'Create ticket with multiple attachments') ->firstOrFail(); self::assertSame(3, Attachment::query()->where('ticket_id', $ticket->id)->whereNull('comment_id')->count()); foreach (['first-proof.pdf', 'second-proof.txt', 'third-proof.csv'] as $name) { $attachment = Attachment::query() ->where('ticket_id', $ticket->id) ->where('original_name', $name) ->firstOrFail(); Storage::disk('local')->assertExists($attachment->path); } } public function test_ticket_create_accepts_source_code_attachments_through_livewire(): void { Storage::fake('local'); config()->set('helpdesk.disk', 'local'); $fixtures = $this->seedLookupData(); $user = $this->user(['name' => 'Source Attachment User']); Livewire::actingAs($user) ->test(TicketCreate::class) ->set('subject', 'Create ticket with source attachments') ->set('body', 'This ticket must accept source files by extension.
') ->set('board_id', $fixtures['board']->id) ->set('priority_id', $fixtures['normal']->id) ->set('category_id', $fixtures['category']->id) ->set('team_id', $fixtures['team']->id) ->set('project_id', $fixtures['project']->id) ->set('attachments', [ UploadedFile::fake()->create('TicketCreate.php', 10, 'text/plain'), UploadedFile::fake()->create('upload-widget.js', 10, 'text/plain'), UploadedFile::fake()->create('warehouse-sync.rpgle', 10, 'text/plain'), ]) ->call('save') ->assertHasNoErrors() ->assertRedirect(route('helpdesk.tickets.index')); $ticket = Ticket::query() ->where('subject', 'Create ticket with source attachments') ->firstOrFail(); foreach (['TicketCreate.php', 'upload-widget.js', 'warehouse-sync.rpgle'] as $name) { $attachment = Attachment::query() ->where('ticket_id', $ticket->id) ->where('original_name', $name) ->firstOrFail(); self::assertTrue($attachment->isSourceCode(), $name . ' should be categorised as source code.'); Storage::disk('local')->assertExists($attachment->path); } } }