Skip to content

Commit 30d7773

Browse files
authored
Merge pull request #12 from 123inkt/add_ppd_name_option_to_create_printer
Add the option to add a ppd-name to create printer operation
2 parents ca1ad8e + 333d0fe commit 30d7773

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/Entity/IppPrinter.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class IppPrinter
1010
private string $deviceUri;
1111
private string $location;
1212
private ?string $trayName = null;
13+
private ?string $ppdName = null;
1314

1415
public function getHostname(): string
1516
{
@@ -58,4 +59,16 @@ public function setTrayName(?string $trayName): self
5859

5960
return $this;
6061
}
62+
63+
public function getPpdName(): ?string
64+
{
65+
return $this->ppdName;
66+
}
67+
68+
public function setPpdName(?string $ppdName): self
69+
{
70+
$this->ppdName = $ppdName;
71+
72+
return $this;
73+
}
6174
}

src/Operations/Cups/CupsCreatePrinter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function create(IppPrinter $printer): IppResponseInterface
4444
$operation->addPrinterAttribute(new IppAttribute(IppTypeEnum::Bool, 'printer-is-accepting-jobs', true));
4545
$operation->addPrinterAttribute(new IppAttribute(IppTypeEnum::Uri, 'device-uri', $printer->getDeviceUri()));
4646
$operation->addPrinterAttribute(new IppAttribute(IppTypeEnum::TextWithoutLang, 'printer-location', $printer->getLocation()));
47+
if ($printer->getPpdName() !== null) {
48+
$operation->addPrinterAttribute(new IppAttribute(IppTypeEnum::NameWithoutLang, 'ppd-name', $printer->getPpdName()));
49+
}
4750

4851
return $this->client->sendRequest($operation);
4952
}

tests/Unit/Operations/Cups/CupsCreatePrinterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CupsCreatePrinterTest extends TestCase
2222
/**
2323
* @throws Throwable
2424
*/
25-
public function testPrint(): void
25+
public function testCreate(): void
2626
{
2727
$cups = 'https://cups';
2828
$server = new IppServer();
@@ -41,7 +41,7 @@ public function testPrint(): void
4141
$client->expects($this->once())->method('sendRequest')->with(static::callback(static function (IppOperation $operation) {
4242
static::assertSame(IppOperationEnum::CupsAddModifyPrinter, $operation->getOperation());
4343
static::assertCount(0, $operation->getJobAttributes(), 'Job attribute count incorrect');
44-
static::assertCount(4, $operation->getPrinterAttributes(), 'Printer attribute count incorrect');
44+
static::assertCount(5, $operation->getPrinterAttributes(), 'Printer attribute count incorrect');
4545
static::assertCount(4, $operation->getOperationAttributes(), 'Operation attribute count incorrect');
4646

4747
return true;
@@ -51,6 +51,7 @@ public function testPrint(): void
5151
$printer->setHostname('test');
5252
$printer->setDeviceUri('socket://10.10.10.10:9100');
5353
$printer->setLocation('location');
54+
$printer->setPpdName('file.ppd');
5455

5556
$printerCreator->create($printer);
5657
}

0 commit comments

Comments
 (0)