|
37 | 37 | use OCA\Libresign\Service\SignRequest\StatusService; |
38 | 38 | use OCA\Libresign\Service\SignRequest\StatusUpdatePolicy; |
39 | 39 | use OCP\EventDispatcher\IEventDispatcher; |
| 40 | +use OCP\Files\Folder; |
40 | 41 | use OCP\Files\IMimeTypeDetector; |
41 | 42 | use OCP\Http\Client\IClient; |
42 | 43 | use OCP\Http\Client\IClientService; |
@@ -769,4 +770,67 @@ public function testOrderedFlowRespectsSigningOrderWhenFileIsAbleToSign(): void |
769 | 770 | 'Second signer in ordered flow should remain DRAFT until first signs' |
770 | 771 | ); |
771 | 772 | } |
| 773 | + |
| 774 | + /** |
| 775 | + * Regression test for issue #7343. |
| 776 | + * |
| 777 | + * processFileData() must extract the inner `file` descriptor |
| 778 | + * and pass it to FileService::getNodeFromData(), not the whole |
| 779 | + * item (which would create a double-nested `file.file.path` |
| 780 | + * and trigger "No file source provided"). |
| 781 | + */ |
| 782 | + public function testSaveEnvelopeExtractsFileDescriptorFromNestedFilesArrayItems(): void { |
| 783 | + $service = $this->getService(['saveFile']); |
| 784 | + |
| 785 | + $envelope = new \OCA\Libresign\Db\File(); |
| 786 | + $envelope->setId(10); |
| 787 | + |
| 788 | + $folder = $this->createMock(Folder::class); |
| 789 | + $folder->method('getId')->willReturn(99); |
| 790 | + |
| 791 | + $nodeA = $this->createMock(\OCP\Files\Node::class); |
| 792 | + $nodeB = $this->createMock(\OCP\Files\Node::class); |
| 793 | + |
| 794 | + $childA = new \OCA\Libresign\Db\File(); |
| 795 | + $childA->setId(11); |
| 796 | + $childB = new \OCA\Libresign\Db\File(); |
| 797 | + $childB->setId(12); |
| 798 | + |
| 799 | + $this->user->method('getUID')->willReturn('testuser'); |
| 800 | + $this->envelopeService->method('validateEnvelopeConstraints'); |
| 801 | + $this->envelopeService->method('createEnvelope')->willReturn($envelope); |
| 802 | + $this->envelopeService->method('getEnvelopeFolder')->willReturn($folder); |
| 803 | + $this->envelopeService->method('addFileToEnvelope')->willReturn(new \OCA\Libresign\Db\File()); |
| 804 | + |
| 805 | + // KEY assertion: getNodeFromData must receive the inner file descriptor, |
| 806 | + // not the doubled-nested wrapper { file: { path }, name }. |
| 807 | + $this->fileService->expects($this->exactly(2)) |
| 808 | + ->method('getNodeFromData') |
| 809 | + ->with($this->callback(function (array $data): bool { |
| 810 | + return isset($data['file']['path']) && !isset($data['file']['file']); |
| 811 | + })) |
| 812 | + ->willReturnOnConsecutiveCalls($nodeA, $nodeB); |
| 813 | + |
| 814 | + $this->envelopeFileRelocator->method('ensureFileInEnvelopeFolder') |
| 815 | + ->willReturnOnConsecutiveCalls($nodeA, $nodeB); |
| 816 | + |
| 817 | + $service->method('saveFile')->willReturnOnConsecutiveCalls($childA, $childB); |
| 818 | + |
| 819 | + $result = $service->saveEnvelope([ |
| 820 | + 'files' => [ |
| 821 | + ['file' => ['path' => '/A/file1.pdf'], 'name' => 'file1'], |
| 822 | + ['file' => ['path' => '/B/file2.pdf'], 'name' => 'file2'], |
| 823 | + ], |
| 824 | + 'name' => 'My Envelope', |
| 825 | + 'userManager' => $this->user, |
| 826 | + 'settings' => [], |
| 827 | + 'signers' => [], |
| 828 | + 'status' => \OCA\Libresign\Enum\FileStatus::DRAFT->value, |
| 829 | + 'visibleElements' => [], |
| 830 | + 'signatureFlow' => null, |
| 831 | + ]); |
| 832 | + |
| 833 | + $this->assertSame($envelope, $result['envelope']); |
| 834 | + $this->assertCount(2, $result['files']); |
| 835 | + } |
772 | 836 | } |
0 commit comments