88
99namespace OCA \Files_Sharing \Tests ;
1010
11+ use OC \EventDispatcher \EventDispatcher ;
12+ use OC \Files \SetupManager ;
1113use OCA \Files_Sharing \ShareTargetValidator ;
1214use OCP \Constants ;
15+ use OCP \EventDispatcher \IEventDispatcher ;
1316use OCP \Files \Config \ICachedMountInfo ;
14- use OCP \Files \Folder ;
17+ use OCP \Files \Mount \ IMountManager ;
1518use OCP \IUser ;
1619use OCP \Server ;
20+ use OCP \Share \Events \VerifyMountPointEvent ;
21+ use OCP \Share \IManager ;
1722use OCP \Share \IShare ;
23+ use Psr \Container \ContainerInterface ;
24+ use Psr \Log \LoggerInterface ;
25+ use Symfony \Component \EventDispatcher \EventDispatcher as SymfonyEventDispatcher ;
1826
1927#[\PHPUnit \Framework \Attributes \Group('DB ' )]
2028class ShareTargetValidatorTest extends TestCase {
29+ private IEventDispatcher $ eventDispatcher ;
2130 private ShareTargetValidator $ targetValidator ;
2231
2332 private IUser $ user2 ;
@@ -40,7 +49,17 @@ protected function setUp(): void {
4049 $ this ->view ->file_put_contents ($ this ->folder . $ this ->filename , 'file in subfolder ' );
4150 $ this ->view ->file_put_contents ($ this ->folder2 . $ this ->filename , 'file in subfolder2 ' );
4251
43- $ this ->targetValidator = Server::get (ShareTargetValidator::class);
52+ $ this ->eventDispatcher = new EventDispatcher (
53+ new SymfonyEventDispatcher (),
54+ Server::get (ContainerInterface::class),
55+ $ this ->createMock (LoggerInterface::class),
56+ );
57+ $ this ->targetValidator = new ShareTargetValidator (
58+ Server::get (IManager::class),
59+ $ this ->eventDispatcher ,
60+ Server::get (SetupManager::class),
61+ Server::get (IMountManager::class),
62+ );
4463 $ this ->user2 = $ this ->createMock (IUser::class);
4564 $ this ->user2 ->method ('getUID ' )
4665 ->willReturn (self ::TEST_FILES_SHARING_API_USER2 );
@@ -138,4 +157,40 @@ public function testShareMountOverShare(): void {
138157 $ this ->shareManager ->deleteShare ($ share2 );
139158 $ this ->view ->unlink ($ this ->folder );
140159 }
160+
161+
162+ /**
163+ * test if the parent folder is created if asked for
164+ */
165+ public function testShareMountCreateParentFolder (): void {
166+ // share to user
167+ $ share = $ this ->share (
168+ IShare::TYPE_USER ,
169+ $ this ->folder ,
170+ self ::TEST_FILES_SHARING_API_USER1 ,
171+ self ::TEST_FILES_SHARING_API_USER2 ,
172+ Constants::PERMISSION_ALL );
173+ $ this ->shareManager ->acceptShare ($ share , self ::TEST_FILES_SHARING_API_USER2 );
174+
175+ $ share ->setTarget ('/foo/bar ' . $ this ->folder );
176+ $ this ->shareManager ->moveShare ($ share , self ::TEST_FILES_SHARING_API_USER2 );
177+
178+ $ share = $ this ->shareManager ->getShareById ($ share ->getFullId ());
179+ $ this ->assertSame ('/foo/bar ' . $ this ->folder , $ share ->getTarget ());
180+
181+ $ this ->eventDispatcher ->addListener (VerifyMountPointEvent::class, function (VerifyMountPointEvent $ event ) {
182+ $ event ->setCreateParent (true );
183+ });
184+ $ this ->targetValidator ->verifyMountPoint ($ this ->user2 , $ share , [], [$ share ]);
185+
186+ $ share = $ this ->shareManager ->getShareById ($ share ->getFullId ());
187+ $ this ->assertSame ('/foo/bar ' . $ this ->folder , $ share ->getTarget ());
188+ $ userFolder = $ this ->rootFolder ->getUserFolder (self ::TEST_FILES_SHARING_API_USER2 );
189+ $ this ->assertTrue ($ userFolder ->nodeExists ('/foo/bar ' ));
190+
191+ //cleanup
192+ self ::loginHelper (self ::TEST_FILES_SHARING_API_USER1 );
193+ $ this ->shareManager ->deleteShare ($ share );
194+ $ this ->view ->unlink ($ this ->folder );
195+ }
141196}
0 commit comments