Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
3 changes: 1 addition & 2 deletions app/Printers/Protocols/CupsProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
51 changes: 51 additions & 0 deletions tests/Unit/Printers/CupsProtocolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use App\Api\JobModel;
use App\Printers\Protocols\CupsProtocol;

function recordingCupsProtocol(): CupsProtocol
{
return new class extends CupsProtocol
{
public array $commands = [];

public string $content = '';

protected function getCmdOutput($cmd): string
{
if ($cmd === 'lpstat -a') {
return "fixture accepting requests\n";
}
$this->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');
});
Loading