Skip to content

Commit

Permalink
feat(libreoffice): add password form field
Browse files Browse the repository at this point in the history
  • Loading branch information
gulien committed Sep 20, 2024
1 parent 362845b commit 7997a35
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Modules/LibreOffice.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public function index(Index $index): self
return $this;
}

/**
* Sets the password for opening the source file.
*/
public function password(string $password): self
{
$this->formValue('password', $password);

return $this;
}

/**
* Sets the paper orientation to landscape.
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/Modules/LibreOfficeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
function (
array $files,
string|null $password = null,
bool $landscape = false,
string|null $nativePageRanges = null,
bool|null $exportFormFields = null,
Expand Down Expand Up @@ -43,6 +44,10 @@ function (
): void {
$libreOffice = Gotenberg::libreOffice('');

if ($password !== null) {
$libreOffice->password($password);
}

if ($landscape) {
$libreOffice->landscape();
}
Expand Down Expand Up @@ -149,6 +154,7 @@ function (
$body = sanitize($request->getBody()->getContents());

expect($request->getUri()->getPath())->toBe('/forms/libreoffice/convert');
expect($body)->unless($password === null, fn ($body) => $body->toContainFormValue('password', $password));
expect($body)->unless($landscape === false, fn ($body) => $body->toContainFormValue('landscape', '1'));
expect($body)->unless($nativePageRanges === null, fn ($body) => $body->toContainFormValue('nativePageRanges', $nativePageRanges));
expect($body)->unless($exportFormFields === null, fn ($body) => $body->toContainFormValue('exportFormFields', $exportFormFields === true ? '1' : '0'));
Expand Down Expand Up @@ -201,6 +207,7 @@ function (
Stream::string('my.docx', 'Word content'),
Stream::string('my_second.docx', 'Second Word content'),
],
'foo',
true,
'1-2',
false,
Expand Down

0 comments on commit 7997a35

Please sign in to comment.