seedLookupData(); $repository = $this->repository(['project_id' => $fixtures['project']->id]); $ticket = $this->ticket(['project_id' => $fixtures['project']->id]); GitCommit::query()->create([ 'repository_id' => $repository->id, 'ticket_id' => $ticket->id, 'hash' => str_repeat('b', 40), 'short_hash' => 'bbbbbbb', 'branch' => 'develop', 'author_name' => 'Mark Gregory', 'author_email' => 'mark@example.com', 'message' => 'Resolve ' . $ticket->reference . ' ticket save redirect', 'url' => 'https://example.com/commit/b', 'committed_at' => now(), ]); $this->assertDatabaseHas('helpdesk_git_commits', [ 'repository_id' => $repository->id, 'ticket_id' => $ticket->id, 'short_hash' => 'bbbbbbb', ]); self::assertSame($ticket->id, $repository->commits()->firstOrFail()->ticket_id); } public function test_existing_ticket_supporting_files_route_stores_multiple_files(): void { Storage::fake('local'); config()->set('helpdesk.disk', 'local'); $user = $this->admin(); $ticket = $this->ticket(['owner' => $user]); $this->actingAs($user) ->post(route('helpdesk.tickets.attachments.store', $ticket), [ 'attachments' => [ UploadedFile::fake()->create('first-log.txt', 4, 'text/plain'), UploadedFile::fake()->create('second-proof.pdf', 8, 'application/pdf'), ], ]) ->assertRedirect(route('helpdesk.tickets.show', $ticket)); $this->assertDatabaseHas('helpdesk_attachments', [ 'ticket_id' => $ticket->id, 'comment_id' => null, 'original_name' => 'first-log.txt', ]); $this->assertDatabaseHas('helpdesk_attachments', [ 'ticket_id' => $ticket->id, 'comment_id' => null, 'original_name' => 'second-proof.pdf', ]); } public function test_existing_ticket_supporting_files_route_accepts_source_code_attachments(): void { Storage::fake('local'); config()->set('helpdesk.disk', 'local'); $user = $this->admin(); $ticket = $this->ticket(['owner' => $user]); $this->actingAs($user) ->post(route('helpdesk.tickets.attachments.store', $ticket), [ 'attachments' => [ UploadedFile::fake()->create('TicketStoreController.php', 4, 'text/plain'), UploadedFile::fake()->create('ticket-editor.js', 4, 'text/plain'), UploadedFile::fake()->create('warehouse-sync.rpgle', 4, 'text/plain'), ], ]) ->assertRedirect(route('helpdesk.tickets.show', $ticket)); $this->assertDatabaseHas('helpdesk_attachments', [ 'ticket_id' => $ticket->id, 'original_name' => 'TicketStoreController.php', ]); $this->assertDatabaseHas('helpdesk_attachments', [ 'ticket_id' => $ticket->id, 'original_name' => 'ticket-editor.js', ]); $this->assertDatabaseHas('helpdesk_attachments', [ 'ticket_id' => $ticket->id, 'original_name' => 'warehouse-sync.rpgle', ]); } public function test_attachment_service_stores_and_deletes_ticket_files(): void { Storage::fake('local'); config()->set('helpdesk.disk', 'local'); $user = $this->user(); $ticket = $this->ticket(['owner' => $user]); $file = UploadedFile::fake()->create('evidence.pdf', 32, 'application/pdf'); app(AttachmentService::class)->storeMany($ticket, [$file], $user->id); $attachment = Attachment::query()->where('ticket_id', $ticket->id)->firstOrFail(); Storage::disk('local')->assertExists($attachment->path); self::assertSame('evidence.pdf', $attachment->original_name); app(AttachmentService::class)->delete($attachment); Storage::disk('local')->assertMissing($attachment->path); $this->assertDatabaseMissing('helpdesk_attachments', ['id' => $attachment->id]); } }