@@ -223,13 +223,19 @@ public static function provideMetadataFieldScenarios(): array {
223223 ];
224224 }
225225
226- public function testLoadMetadataNormalizesRequiredContractFields (): void {
226+ #[DataProvider('provideMetadataContractNormalizationScenarios ' )]
227+ public function testLoadMetadataNormalizesRequiredContractFields (
228+ string $ filename ,
229+ array $ initialMetadata ,
230+ int $ expectedP ,
231+ string $ expectedExtension ,
232+ ): void {
227233 $ file = new File ();
228234 $ file ->setId (1 );
229- $ file ->setName (' contract.PDF ' );
235+ $ file ->setName ($ filename );
230236 $ file ->setUserId ('user123 ' );
231237 $ file ->setSignedNodeId (123 );
232- $ file ->setMetadata ([] );
238+ $ file ->setMetadata ($ initialMetadata );
233239 $ file ->setUuid ('uuid-123 ' );
234240
235241 $ fileNode = $ this ->createMock (\OCP \Files \File::class);
@@ -247,7 +253,17 @@ public function testLoadMetadataNormalizesRequiredContractFields(): void {
247253 $ service ->loadMetadata ($ file , $ fileData );
248254
249255 $ this ->assertIsArray ($ fileData ->metadata );
250- $ this ->assertSame (0 , $ fileData ->metadata ['p ' ]);
251- $ this ->assertSame ('pdf ' , $ fileData ->metadata ['extension ' ]);
256+ $ this ->assertSame ($ expectedP , $ fileData ->metadata ['p ' ]);
257+ $ this ->assertSame ($ expectedExtension , $ fileData ->metadata ['extension ' ]);
258+ }
259+
260+ public static function provideMetadataContractNormalizationScenarios (): array {
261+ return [
262+ 'uppercase extension lowercased when not in metadata ' => ['contract.PDF ' , [], 0 , 'pdf ' ],
263+ 'fallback to pdf when filename has no extension ' => ['contract ' , [], 0 , 'pdf ' ],
264+ 'empty extension in metadata treated as missing ' => ['contract.pdf ' , ['extension ' => '' ], 0 , 'pdf ' ],
265+ 'existing extension in metadata is preserved ' => ['renamed.PDF ' , ['extension ' => 'docx ' ], 0 , 'docx ' ],
266+ 'p in metadata is preserved as totalPages when already set ' => ['doc.pdf ' , ['p ' => 99 ], 99 , 'pdf ' ],
267+ ];
252268 }
253269}
0 commit comments