@@ -500,6 +500,7 @@ public function testPromoteReshareFile(): void {
500500 ->getMock ();
501501
502502 $ file = $ this ->createMock (File::class);
503+ $ file ->method ('getId ' )->willReturn (42 );
503504
504505 $ share = $ this ->createMock (IShare::class);
505506 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_USER );
@@ -528,6 +529,13 @@ public function testPromoteReshareFile(): void {
528529
529530 $ manager ->expects ($ this ->exactly (1 ))->method ('updateShare ' )->with ($ reShare );
530531
532+ $ this ->userManager ->method ('userExists ' )->willReturn (true );
533+ $ userFolder = $ this ->createMock (Folder::class);
534+ $ this ->rootFolder ->method ('getUserFolder ' )->with ('userA ' )->willReturn ($ userFolder );
535+ $ userFolder ->method ('getFirstNodeById ' )
536+ ->with (42 )
537+ ->willReturn ($ file );
538+
531539 $ qb = $ this ->createMock (IQueryBuilder::class);
532540 $ result = $ this ->createMock (IResult::class);
533541 $ qb ->method ('select ' )
@@ -544,7 +552,7 @@ public function testPromoteReshareFile(): void {
544552 ->willReturn ($ qb );
545553 $ result ->method ('fetch ' )
546554 ->willReturnOnConsecutiveCalls (
547- ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER ],
555+ ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER , ' uid_owner ' => ' userA ' , ' file_source ' => 42 ],
548556 false ,
549557 );
550558
@@ -585,19 +593,35 @@ public function testPromoteReshare(): void {
585593 $ reShareInOtherFolder ->method ('getNode ' )->willReturn ($ otherFolder );
586594
587595 $ this ->defaultProvider ->method ('getSharesBy ' )
588- ->willReturnCallback (function ($ userId , $ shareType , $ node , $ reshares , $ limit , $ offset ) use ($ reShare , $ reShareInSubFolder , $ reShareInOtherFolder ) {
596+ ->willReturnCallback (function ($ userId , $ shareType , $ node , $ reshares , $ limit , $ offset ) use ($ folder , $ subFolder , $ reShare , $ reShareInSubFolder , $ reShareInOtherFolder ) {
589597 if ($ shareType === IShare::TYPE_USER ) {
590- return match ($ userId ) {
591- 'userB ' => [$ reShare ,$ reShareInSubFolder ,$ reShareInOtherFolder ],
592- };
593- } else {
594- return [];
598+ if ($ userId === 'userB ' ) {
599+ if ($ node === $ folder ) {
600+ return [$ reShare ];
601+ }
602+ if ($ node === $ subFolder ) {
603+ return [$ reShareInSubFolder ];
604+ }
605+ }
595606 }
607+ $ this ->fail ();
596608 });
597609 $ manager ->method ('generalCreateChecks ' )->willThrowException (new GenericShareException ());
598610
599611 $ manager ->expects ($ this ->exactly (2 ))->method ('updateShare ' )->withConsecutive ([$ reShare ], [$ reShareInSubFolder ]);
600612
613+ $ this ->userManager ->method ('userExists ' )->willReturn (true );
614+ $ userFolder = $ this ->createMock (Folder::class);
615+ $ this ->rootFolder ->method ('getUserFolder ' )->with ('userA ' )->willReturn ($ userFolder );
616+ $ userFolder ->method ('getFirstNodeById ' )
617+ ->willReturnCallback (function ($ id ) use ($ subFolder , $ otherFolder , $ folder ) {
618+ return match ($ id ) {
619+ 41 => $ subFolder ,
620+ 42 => $ otherFolder ,
621+ 43 => $ folder ,
622+ };
623+ });
624+
601625 $ qb = $ this ->createMock (IQueryBuilder::class);
602626 $ result = $ this ->createMock (IResult::class);
603627 $ qb ->method ('select ' )
@@ -614,7 +638,9 @@ public function testPromoteReshare(): void {
614638 ->willReturn ($ qb );
615639 $ result ->method ('fetch ' )
616640 ->willReturnOnConsecutiveCalls (
617- ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER ],
641+ ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER , 'uid_owner ' => 'userA ' , 'file_source ' => 41 ],
642+ ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER , 'uid_owner ' => 'userA ' , 'file_source ' => 42 ],
643+ ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER , 'uid_owner ' => 'userA ' , 'file_source ' => 43 ],
618644 false ,
619645 );
620646
@@ -646,6 +672,13 @@ public function testPromoteReshareWhenUserHasAnotherShare(): void {
646672 /* No share is promoted because generalCreateChecks does not throw */
647673 $ manager ->expects ($ this ->never ())->method ('updateShare ' );
648674
675+ $ this ->userManager ->method ('userExists ' )->willReturn (true );
676+ $ userFolder = $ this ->createMock (Folder::class);
677+ $ this ->rootFolder ->method ('getUserFolder ' )->with ('userA ' )->willReturn ($ userFolder );
678+ $ userFolder ->method ('getFirstNodeById ' )
679+ ->with (42 )
680+ ->willReturn ($ folder );
681+
649682 $ qb = $ this ->createMock (IQueryBuilder::class);
650683 $ result = $ this ->createMock (IResult::class);
651684 $ qb ->method ('select ' )
@@ -662,7 +695,7 @@ public function testPromoteReshareWhenUserHasAnotherShare(): void {
662695 ->willReturn ($ qb );
663696 $ result ->method ('fetch ' )
664697 ->willReturnOnConsecutiveCalls (
665- ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER ],
698+ ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER , ' uid_owner ' => ' userA ' , ' file_source ' => 42 ],
666699 false ,
667700 );
668701
@@ -739,8 +772,8 @@ public function testPromoteReshareOfUsersInGroupShare(): void {
739772 ->willReturn ($ qb );
740773 $ result ->method ('fetch ' )
741774 ->willReturnOnConsecutiveCalls (
742- ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER ],
743- ['uid_initiator ' => 'userC ' , 'share_type ' => IShare::TYPE_USER ],
775+ ['uid_initiator ' => 'userB ' , 'share_type ' => IShare::TYPE_USER , ' uid_owner ' => ' userA ' , ' file_source ' => 42 ],
776+ ['uid_initiator ' => 'userC ' , 'share_type ' => IShare::TYPE_USER , ' uid_owner ' => ' userA ' , ' file_source ' => 42 ],
744777 false ,
745778 );
746779
0 commit comments