diff --git a/.github/workflows/phar.yml b/.github/workflows/phar.yml index fb33dc7..ff88ae6 100644 --- a/.github/workflows/phar.yml +++ b/.github/workflows/phar.yml @@ -54,7 +54,7 @@ jobs: run: mv builds/webprint-service builds/webprint-service.phar - name: Upload a Build Artifact - uses: actions/upload-artifact@v2.2.4 + uses: actions/upload-artifact@v4 with: name: binary path: builds/* diff --git a/app/Printers/Protocols/CupsProtocol.php b/app/Printers/Protocols/CupsProtocol.php index 8d85c0b..f232598 100644 --- a/app/Printers/Protocols/CupsProtocol.php +++ b/app/Printers/Protocols/CupsProtocol.php @@ -32,8 +32,7 @@ public function printJob(JobModel $job, array $protocol_options): void case 'ppd': $options = collect($job->options) - ->filter(fn ($value) => ! is_bool($value) || $value === true) - ->map(fn ($value) => is_bool($value) ? null : $value); + ->map(fn ($value) => is_bool($value) ? ($value ? 'True' : 'False') : $value); break; default: diff --git a/tests/Unit/Printers/CupsProtocolTest.php b/tests/Unit/Printers/CupsProtocolTest.php new file mode 100644 index 0000000..69722bf --- /dev/null +++ b/tests/Unit/Printers/CupsProtocolTest.php @@ -0,0 +1,51 @@ +commands[] = $cmd; + preg_match("/'([^']+)'$/", $cmd, $match); + $this->content = file_get_contents($match[1]); + + return 'request id is fixture-1'; + } + }; +} + +test('PPD preserves explicit false and true options alongside choice values', function () { + $protocol = recordingCupsProtocol(); + $protocol->printJob(new JobModel('job', 'Test', 'cups://fixture', [ + 'PageSize' => 'A4', + 'Duplex' => 'None', + 'MirrorPrint' => false, + 'fit-to-page' => true, + ], 'ppd', 'label.pdf', 'prepared PDF bytes'), ['host' => 'fixture']); + + expect($protocol->commands)->toHaveCount(1) + ->and($protocol->commands[0])->toContain("-o 'PageSize=A4'", "-o 'Duplex=None'", "-o 'MirrorPrint=False'", "-o 'fit-to-page=True'") + ->and($protocol->content)->toBe('prepared PDF bytes'); +}); + +test('RAW keeps the raw flag and does not apply PPD options', function () { + $protocol = recordingCupsProtocol(); + $protocol->printJob(new JobModel('job', 'Test', 'cups://fixture', [ + 'MirrorPrint' => false, + ], 'raw', 'label.zpl', '^XA^XZ'), ['host' => 'fixture']); + + expect($protocol->commands)->toHaveCount(1) + ->and($protocol->commands[0])->toContain("-o 'raw'")->not->toContain('MirrorPrint') + ->and($protocol->content)->toBe('^XA^XZ'); +});