diff --git a/app/Http/Controllers/PrintServiceApi/PrintJobsController.php b/app/Http/Controllers/PrintServiceApi/PrintJobsController.php index ee240db..5e846a5 100644 --- a/app/Http/Controllers/PrintServiceApi/PrintJobsController.php +++ b/app/Http/Controllers/PrintServiceApi/PrintJobsController.php @@ -84,7 +84,7 @@ public function show(PrintJob $job) ->mapWithKeys(function ($option, $key) use ($options): array { $value = isset($options[$option['key']]) ? ($options[$option['key']] ?? $option['default']) : $option['default']; - if ($option['type'] ?? 'select' == 'Boolean') { + if (($option['type'] ?? 'select') === 'Boolean') { return [$option['key'] => $value == 'True']; } diff --git a/tests/Feature/PrintServiceApi/GetJobDetailsTest.php b/tests/Feature/PrintServiceApi/GetJobDetailsTest.php index 173daa7..f72fa98 100755 --- a/tests/Feature/PrintServiceApi/GetJobDetailsTest.php +++ b/tests/Feature/PrintServiceApi/GetJobDetailsTest.php @@ -161,6 +161,38 @@ public function test_long_content_is_served_as_link(): void ); } + public function test_ppd_choice_values_are_preserved_and_only_booleans_are_converted(): void + { + Sanctum::actingAs( + $server = PrintServer::factory()->create(), + guard: 'print_service_api' + ); + + $printer = Printer::factory()->for($server, 'Server')->ppd()->create([ + 'ppd_options' => [ + ['key' => 'PageSize', 'type' => 'PickOne', 'default' => 'Letter'], + ['key' => 'Duplex', 'type' => 'PickOne', 'default' => 'None'], + ['key' => 'Resolution', 'default' => '300dpi'], + ['key' => 'fit-to-page', 'type' => 'Boolean', 'default' => 'True'], + ['key' => 'MirrorPrint', 'type' => 'Boolean', 'default' => 'True'], + ], + ]); + $job = PrintJob::factory()->for($printer, 'Printer')->create([ + 'ppd' => true, + 'ppd_options' => ['PageSize' => 'A4', 'fit-to-page' => 'False'], + ]); + + $this->getJson('/api/print-service/jobs/'.$job->ulid) + ->assertOk() + ->assertJsonPath('options', [ + 'PageSize' => 'A4', + 'Duplex' => 'None', + 'Resolution' => '300dpi', + 'fit-to-page' => false, + 'MirrorPrint' => true, + ]); + } + public function test_cannot_access_others_jobs(): void { Sanctum::actingAs(