|
23 | 23 | use OCP\Files\File; |
24 | 24 | use OCP\Files\Folder; |
25 | 25 | use OCP\Files\IRootFolder; |
| 26 | +use PHPUnit\Framework\Attributes\DataProvider; |
26 | 27 | use PHPUnit\Framework\MockObject\MockObject; |
27 | 28 | use Psr\Log\NullLogger; |
28 | 29 |
|
@@ -296,6 +297,46 @@ public function testBuildsChildDataIncludesIdentifyMethodsAndMetadata(): void { |
296 | 297 | $this->assertSame(['certificate_info' => ['serialNumber' => '1234']], $result->signers[0]->metadata); |
297 | 298 | } |
298 | 299 |
|
| 300 | + #[DataProvider('provideChildMetadataContractScenarios')] |
| 301 | + public function testBuildEnvelopeChildNormalizesMetadataContract( |
| 302 | + string $filename, |
| 303 | + array $initialMetadata, |
| 304 | + int $expectedP, |
| 305 | + string $expectedExtension, |
| 306 | + ): void { |
| 307 | + $this->mockFileNode(); |
| 308 | + |
| 309 | + $this->signRequestMapper->method('getByFileId')->willReturn([]); |
| 310 | + $this->fileMapper->method('getTextOfStatus')->willReturn('pending'); |
| 311 | + |
| 312 | + $childFile = new DbFile(); |
| 313 | + $childFile->setId(1); |
| 314 | + $childFile->setUuid('uuid-1'); |
| 315 | + $childFile->setName($filename); |
| 316 | + $childFile->setStatus(1); |
| 317 | + $childFile->setNodeId(100); |
| 318 | + $childFile->setUserId('user1'); |
| 319 | + $childFile->setMetadata($initialMetadata); |
| 320 | + |
| 321 | + $options = new FileResponseOptions(); |
| 322 | + $result = $this->getService()->buildEnvelopeChildData($childFile, $options); |
| 323 | + |
| 324 | + $this->assertIsArray($result->metadata); |
| 325 | + $this->assertSame($expectedP, $result->metadata['p']); |
| 326 | + $this->assertSame($expectedExtension, $result->metadata['extension']); |
| 327 | + } |
| 328 | + |
| 329 | + public static function provideChildMetadataContractScenarios(): array { |
| 330 | + return [ |
| 331 | + 'extension absent → derived from filename lowercased' => ['contract.PDF', [], 0, 'pdf'], |
| 332 | + 'filename without extension → pdf fallback' => ['contract', [], 0, 'pdf'], |
| 333 | + 'empty extension in metadata → derived from filename' => ['doc.pdf', ['extension' => ''], 0, 'pdf'], |
| 334 | + 'non-string extension in metadata → derived from filename' => ['doc.pdf', ['extension' => 42], 0, 'pdf'], |
| 335 | + 'extension already set → preserved' => ['renamed.PDF', ['extension' => 'docx'], 0, 'docx'], |
| 336 | + 'p in metadata preserved as totalPages' => ['doc.pdf', ['p' => 5], 5, 'pdf'], |
| 337 | + ]; |
| 338 | + } |
| 339 | + |
299 | 340 | private function createMockFileElement( |
300 | 341 | int $id, |
301 | 342 | int $signRequestId, |
|
0 commit comments