diff --git a/src/Modules/LibreOffice.php b/src/Modules/LibreOffice.php index fc37514..e455a94 100644 --- a/src/Modules/LibreOffice.php +++ b/src/Modules/LibreOffice.php @@ -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. */ diff --git a/tests/Modules/LibreOfficeTest.php b/tests/Modules/LibreOfficeTest.php index 05adbce..471612b 100644 --- a/tests/Modules/LibreOfficeTest.php +++ b/tests/Modules/LibreOfficeTest.php @@ -15,6 +15,7 @@ */ function ( array $files, + string|null $password = null, bool $landscape = false, string|null $nativePageRanges = null, bool|null $exportFormFields = null, @@ -43,6 +44,10 @@ function ( ): void { $libreOffice = Gotenberg::libreOffice(''); + if ($password !== null) { + $libreOffice->password($password); + } + if ($landscape) { $libreOffice->landscape(); } @@ -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')); @@ -201,6 +207,7 @@ function ( Stream::string('my.docx', 'Word content'), Stream::string('my_second.docx', 'Second Word content'), ], + 'foo', true, '1-2', false,