1414 * @param Stream[] $pdfs
1515 * @param array<string,string|bool|float|int|array<string>> $metadata
1616 */
17- function (array $ pdfs , string |null $ pdfa = null , bool $ pdfua = false , array $ metadata = []): void {
17+ function (array $ pdfs , string |null $ pdfa = null , bool $ pdfua = false , array $ metadata = [], bool $ flatten = false ): void {
1818 $ pdfEngines = Gotenberg::pdfEngines ('' )->index (new DummyIndex ());
1919
2020 if ($ pdfa !== null ) {
@@ -29,12 +29,16 @@ function (array $pdfs, string|null $pdfa = null, bool $pdfua = false, array $met
2929 $ pdfEngines ->metadata ($ metadata );
3030 }
3131
32+ if ($ flatten ) {
33+ $ pdfEngines ->flattening ();
34+ }
35+
3236 $ request = $ pdfEngines ->merge (...$ pdfs );
3337 $ body = sanitize ($ request ->getBody ()->getContents ());
3438
3539 expect ($ request ->getUri ()->getPath ())->toBe ('/forms/pdfengines/merge ' );
3640 expect ($ body )->unless ($ pdfa === null , fn ($ body ) => $ body ->toContainFormValue ('pdfa ' , $ pdfa ));
37- expect ($ body )->unless ($ pdfua === false , fn ($ body ) => $ body ->toContainFormValue ('pdfa ' , $ pdfa ));
41+ expect ($ body )->unless ($ pdfua === false , fn ($ body ) => $ body ->toContainFormValue ('pdfua ' , ' 1 ' ));
3842
3943 if (count ($ metadata ) > 0 ) {
4044 $ json = json_encode ($ metadata );
@@ -45,6 +49,8 @@ function (array $pdfs, string|null $pdfa = null, bool $pdfua = false, array $met
4549 expect ($ body )->toContainFormValue ('metadata ' , $ json );
4650 }
4751
52+ expect ($ body )->unless ($ flatten === false , fn ($ body ) => $ body ->toContainFormValue ('flatten ' , '1 ' ));
53+
4854 foreach ($ pdfs as $ pdf ) {
4955 $ pdf ->getStream ()->rewind ();
5056 expect ($ body )->toContainFormFile ('foo_ ' . $ pdf ->getFilename (), $ pdf ->getStream ()->getContents (), 'application/pdf ' );
@@ -66,14 +72,31 @@ function (array $pdfs, string|null $pdfa = null, bool $pdfua = false, array $met
6672 'PDF/A-1a ' ,
6773 true ,
6874 [ 'Producer ' => 'Gotenberg ' ],
75+ true ,
6976 ],
7077]);
7178
7279it (
7380 'creates a valid request for the "/forms/pdfengines/split" endpoint ' ,
7481 /** @param Stream[] $pdfs */
75- function (array $ pdfs , SplitMode $ mode ): void {
76- $ pdfEngines = Gotenberg::pdfEngines ('' )->index (new DummyIndex ());
82+ function (array $ pdfs , SplitMode $ mode , string |null $ pdfa = null , bool $ pdfua = false , array $ metadata = [], bool $ flatten = false ): void {
83+ $ pdfEngines = Gotenberg::pdfEngines ('' );
84+
85+ if ($ pdfa !== null ) {
86+ $ pdfEngines ->pdfa ($ pdfa );
87+ }
88+
89+ if ($ pdfua ) {
90+ $ pdfEngines ->pdfua ();
91+ }
92+
93+ if (count ($ metadata ) > 0 ) {
94+ $ pdfEngines ->metadata ($ metadata );
95+ }
96+
97+ if ($ flatten ) {
98+ $ pdfEngines ->flattening ();
99+ }
77100
78101 $ request = $ pdfEngines ->split ($ mode , ...$ pdfs );
79102 $ body = sanitize ($ request ->getBody ()->getContents ());
@@ -82,10 +105,23 @@ function (array $pdfs, SplitMode $mode): void {
82105 expect ($ body )->toContainFormValue ('splitMode ' , $ mode ->mode );
83106 expect ($ body )->toContainFormValue ('splitSpan ' , $ mode ->span );
84107 expect ($ body )->toContainFormValue ('splitUnify ' , $ mode ->unify ? '1 ' : '0 ' );
108+ expect ($ body )->unless ($ pdfa === null , fn ($ body ) => $ body ->toContainFormValue ('pdfa ' , $ pdfa ));
109+ expect ($ body )->unless ($ pdfua === false , fn ($ body ) => $ body ->toContainFormValue ('pdfua ' , '1 ' ));
110+
111+ if (count ($ metadata ) > 0 ) {
112+ $ json = json_encode ($ metadata );
113+ if ($ json === false ) {
114+ throw NativeFunctionErrored::createFromLastPhpError ();
115+ }
116+
117+ expect ($ body )->toContainFormValue ('metadata ' , $ json );
118+ }
119+
120+ expect ($ body )->unless ($ flatten === false , fn ($ body ) => $ body ->toContainFormValue ('flatten ' , '1 ' ));
85121
86122 foreach ($ pdfs as $ pdf ) {
87123 $ pdf ->getStream ()->rewind ();
88- expect ($ body )->toContainFormFile (' foo_ ' . $ pdf ->getFilename (), $ pdf ->getStream ()->getContents (), 'application/pdf ' );
124+ expect ($ body )->toContainFormFile ($ pdf ->getFilename (), $ pdf ->getStream ()->getContents (), 'application/pdf ' );
89125 }
90126 },
91127)->with ([
@@ -102,17 +138,28 @@ function (array $pdfs, SplitMode $mode): void {
102138 Stream::string ('my_third.pdf ' , 'Third PDF content ' ),
103139 ],
104140 SplitMode::pages ('1-2 ' , true ),
141+ 'PDF/A-1a ' ,
142+ true ,
143+ [ 'Producer ' => 'Gotenberg ' ],
144+ true ,
105145 ],
106146]);
107147
108148it (
109149 'creates a valid request for the "/forms/pdfengines/convert" endpoint ' ,
110- function (string $ pdfa , Stream ...$ pdfs ): void {
111- $ request = Gotenberg::pdfEngines ('' )->convert ($ pdfa , ...$ pdfs );
150+ function (string $ pdfa , bool $ pdfua , Stream ...$ pdfs ): void {
151+ $ pdfEngines = Gotenberg::pdfEngines ('' );
152+
153+ if ($ pdfua ) {
154+ $ pdfEngines ->pdfua ();
155+ }
156+
157+ $ request = $ pdfEngines ->convert ($ pdfa , ...$ pdfs );
112158 $ body = sanitize ($ request ->getBody ()->getContents ());
113159
114160 expect ($ request ->getUri ()->getPath ())->toBe ('/forms/pdfengines/convert ' );
115161 expect ($ body )->toContainFormValue ('pdfa ' , $ pdfa );
162+ expect ($ body )->unless ($ pdfua === false , fn ($ body ) => $ body ->toContainFormValue ('pdfua ' , '1 ' ));
116163
117164 foreach ($ pdfs as $ pdf ) {
118165 $ pdf ->getStream ()->rewind ();
@@ -122,15 +169,43 @@ function (string $pdfa, Stream ...$pdfs): void {
122169)->with ([
123170 [
124171 'PDF/A-1a ' ,
172+ false ,
125173 Stream::string ('my.pdf ' , 'PDF content ' ),
126174 ],
127175 [
128176 'PDF/A-1a ' ,
177+ true ,
129178 Stream::string ('my.pdf ' , 'PDF content ' ),
130179 Stream::string ('my_second.pdf ' , 'Second PDF content ' ),
131180 ],
132181]);
133182
183+ it (
184+ 'creates a valid request for the "/forms/pdfengines/flatten" endpoint ' ,
185+ /** @param Stream[] $pdfs */
186+ function (array $ pdfs ): void {
187+ $ pdfEngines = Gotenberg::pdfEngines ('' );
188+
189+ $ request = $ pdfEngines ->flatten (...$ pdfs );
190+ $ body = sanitize ($ request ->getBody ()->getContents ());
191+
192+ expect ($ request ->getUri ()->getPath ())->toBe ('/forms/pdfengines/flatten ' );
193+ expect ($ body )->toContainFormValue ('flatten ' , '1 ' );
194+
195+ foreach ($ pdfs as $ pdf ) {
196+ $ pdf ->getStream ()->rewind ();
197+ expect ($ body )->toContainFormFile ($ pdf ->getFilename (), $ pdf ->getStream ()->getContents (), 'application/pdf ' );
198+ }
199+ },
200+ )->with ([
201+ [
202+ [
203+ Stream::string ('my.pdf ' , 'PDF content ' ),
204+ Stream::string ('my_second.pdf ' , 'Second PDF content ' ),
205+ ],
206+ ],
207+ ]);
208+
134209it (
135210 'creates a valid request for the "/forms/pdfengines/metadata/read" endpoint ' ,
136211 /** @param Stream[] $pdfs */
0 commit comments