2323use OC \Files \Search \SearchQuery ;
2424use OC \Files \Storage \Temporary ;
2525use OC \Files \Storage \Wrapper \Jail ;
26- use OC \Files \View ;
2726use OCP \Files \Cache \ICacheEntry ;
2827use OCP \Files \Mount \IMountPoint ;
2928use OCP \Files \NotFoundException ;
4039 */
4140class FolderTest extends NodeTest {
4241 protected function createTestNode ($ root , $ view , $ path , array $ data = [], $ internalPath = '' , $ storage = null ) {
42+ $ view ->expects ($ this ->any ())
43+ ->method ('getRoot ' )
44+ ->willReturn ('' );
4345 if ($ data || $ internalPath || $ storage ) {
4446 return new Folder ($ root , $ view , $ path , $ this ->getFileInfo ($ data , $ internalPath , $ storage ));
4547 } else {
@@ -64,27 +66,26 @@ public function testGetDirectoryContent() {
6466 /**
6567 * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
6668 */
67- $ view = $ this ->createMock (View::class);
6869 $ root = $ this ->getMockBuilder (Root::class)
69- ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
70+ ->setConstructorArgs ([$ manager , $ this -> view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
7071 ->getMock ();
7172 $ root ->expects ($ this ->any ())
7273 ->method ('getUser ' )
7374 ->willReturn ($ this ->user );
7475
75- $ view ->expects ($ this ->any ())
76+ $ this -> view ->expects ($ this ->any ())
7677 ->method ('getDirectoryContent ' )
7778 ->with ('/bar/foo ' )
7879 ->willReturn ([
7980 new FileInfo ('/bar/foo/asd ' , null , 'foo/asd ' , ['fileid ' => 2 , 'path ' => '/bar/foo/asd ' , 'name ' => 'asd ' , 'size ' => 100 , 'mtime ' => 50 , 'mimetype ' => 'text/plain ' ], null ),
8081 new FileInfo ('/bar/foo/qwerty ' , null , 'foo/qwerty ' , ['fileid ' => 3 , 'path ' => '/bar/foo/qwerty ' , 'name ' => 'qwerty ' , 'size ' => 200 , 'mtime ' => 55 , 'mimetype ' => 'httpd/unix-directory ' ], null ),
8182 ]);
82- $ view ->method ('getFileInfo ' )
83+ $ this -> view ->method ('getFileInfo ' )
8384 ->willReturn ($ this ->createMock (FileInfo::class));
84- $ view ->method ('getRelativePath ' )
85+ $ this -> view ->method ('getRelativePath ' )
8586 ->willReturn ('/bar/foo ' );
8687
87- $ node = new Folder ($ root , $ view , '/bar/foo ' );
88+ $ node = new Folder ($ root , $ this -> view , '/bar/foo ' );
8889 $ children = $ node ->getDirectoryListing ();
8990 $ this ->assertEquals (2 , count ($ children ));
9091 $ this ->assertInstanceOf ('\OC\Files\Node\File ' , $ children [0 ]);
@@ -97,10 +98,7 @@ public function testGetDirectoryContent() {
9798
9899 public function testGet () {
99100 $ manager = $ this ->createMock (Manager::class);
100- /**
101- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
102- */
103- $ view = $ this ->createMock (View::class);
101+ $ view = $ this ->getRootViewMock ();
104102 $ root = $ this ->getMockBuilder (Root::class)
105103 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
106104 ->getMock ();
@@ -119,10 +117,7 @@ public function testGet() {
119117
120118 public function testNodeExists () {
121119 $ manager = $ this ->createMock (Manager::class);
122- /**
123- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
124- */
125- $ view = $ this ->createMock (View::class);
120+ $ view = $ this ->getRootViewMock ();
126121 $ root = $ this ->getMockBuilder (Root::class)
127122 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
128123 ->getMock ();
@@ -142,10 +137,7 @@ public function testNodeExists() {
142137
143138 public function testNodeExistsNotExists () {
144139 $ manager = $ this ->createMock (Manager::class);
145- /**
146- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
147- */
148- $ view = $ this ->createMock (View::class);
140+ $ view = $ this ->getRootViewMock ();
149141 $ root = $ this ->getMockBuilder (Root::class)
150142 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
151143 ->getMock ();
@@ -163,10 +155,7 @@ public function testNodeExistsNotExists() {
163155
164156 public function testNewFolder () {
165157 $ manager = $ this ->createMock (Manager::class);
166- /**
167- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
168- */
169- $ view = $ this ->createMock (View::class);
158+ $ view = $ this ->getRootViewMock ();
170159 $ root = $ this ->getMockBuilder (Root::class)
171160 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
172161 ->getMock ();
@@ -190,10 +179,7 @@ public function testNewFolder() {
190179
191180 public function testNewFolderDeepParent () {
192181 $ manager = $ this ->createMock (Manager::class);
193- /**
194- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
195- */
196- $ view = $ this ->createMock (View::class);
182+ $ view = $ this ->getRootViewMock ();
197183 $ root = $ this ->getMockBuilder (Root::class)
198184 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
199185 ->getMock ();
@@ -220,10 +206,7 @@ public function testNewFolderNotPermitted() {
220206 $ this ->expectException (\OCP \Files \NotPermittedException::class);
221207
222208 $ manager = $ this ->createMock (Manager::class);
223- /**
224- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
225- */
226- $ view = $ this ->createMock (View::class);
209+ $ view = $ this ->getRootViewMock ();
227210 $ root = $ this ->getMockBuilder (Root::class)
228211 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
229212 ->getMock ();
@@ -240,10 +223,7 @@ public function testNewFolderNotPermitted() {
240223
241224 public function testNewFile () {
242225 $ manager = $ this ->createMock (Manager::class);
243- /**
244- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
245- */
246- $ view = $ this ->createMock (View::class);
226+ $ view = $ this ->getRootViewMock ();
247227 $ root = $ this ->getMockBuilder (Root::class)
248228 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
249229 ->getMock ();
@@ -270,10 +250,7 @@ public function testNewFileNotPermitted() {
270250 $ this ->expectException (\OCP \Files \NotPermittedException::class);
271251
272252 $ manager = $ this ->createMock (Manager::class);
273- /**
274- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
275- */
276- $ view = $ this ->createMock (View::class);
253+ $ view = $ this ->getRootViewMock ();
277254 $ root = $ this ->getMockBuilder (Root::class)
278255 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
279256 ->getMock ();
@@ -290,10 +267,7 @@ public function testNewFileNotPermitted() {
290267
291268 public function testGetFreeSpace () {
292269 $ manager = $ this ->createMock (Manager::class);
293- /**
294- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
295- */
296- $ view = $ this ->createMock (View::class);
270+ $ view = $ this ->getRootViewMock ();
297271 $ root = $ this ->getMockBuilder (Root::class)
298272 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
299273 ->getMock ();
@@ -310,10 +284,7 @@ public function testGetFreeSpace() {
310284
311285 public function testSearch () {
312286 $ manager = $ this ->createMock (Manager::class);
313- /**
314- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
315- */
316- $ view = $ this ->createMock (View::class);
287+ $ view = $ this ->getRootViewMock ();
317288 $ root = $ this ->getMockBuilder (Root::class)
318289 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
319290 ->getMock ();
@@ -353,10 +324,7 @@ public function testSearch() {
353324
354325 public function testSearchInRoot () {
355326 $ manager = $ this ->createMock (Manager::class);
356- /**
357- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
358- */
359- $ view = $ this ->createMock (View::class);
327+ $ view = $ this ->getRootViewMock ();
360328 $ root = $ this ->getMockBuilder (Root::class)
361329 ->setMethods (['getUser ' , 'getMountsIn ' , 'getMount ' ])
362330 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
@@ -397,10 +365,7 @@ public function testSearchInRoot() {
397365
398366 public function testSearchInStorageRoot () {
399367 $ manager = $ this ->createMock (Manager::class);
400- /**
401- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
402- */
403- $ view = $ this ->createMock (View::class);
368+ $ view = $ this ->getRootViewMock ();
404369 $ root = $ this ->getMockBuilder (Root::class)
405370 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
406371 ->getMock ();
@@ -440,10 +405,7 @@ public function testSearchInStorageRoot() {
440405
441406 public function testSearchSubStorages () {
442407 $ manager = $ this ->createMock (Manager::class);
443- /**
444- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
445- */
446- $ view = $ this ->createMock (View::class);
408+ $ view = $ this ->getRootViewMock ();
447409 $ root = $ this ->getMockBuilder (Root::class)
448410 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
449411 ->getMock ();
@@ -500,21 +462,18 @@ public function testSearchSubStorages() {
500462 }
501463
502464 public function testIsSubNode () {
503- $ file = new Node (null , null , '/foo/bar ' );
504- $ folder = new Folder (null , null , '/foo ' );
465+ $ file = new Node (null , $ this -> view , '/foo/bar ' );
466+ $ folder = new Folder (null , $ this -> view , '/foo ' );
505467 $ this ->assertTrue ($ folder ->isSubNode ($ file ));
506468 $ this ->assertFalse ($ folder ->isSubNode ($ folder ));
507469
508- $ file = new Node (null , null , '/foobar ' );
470+ $ file = new Node (null , $ this -> view , '/foobar ' );
509471 $ this ->assertFalse ($ folder ->isSubNode ($ file ));
510472 }
511473
512474 public function testGetById () {
513475 $ manager = $ this ->createMock (Manager::class);
514- /**
515- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
516- */
517- $ view = $ this ->createMock (View::class);
476+ $ view = $ this ->getRootViewMock ();
518477 $ root = $ this ->getMockBuilder (Root::class)
519478 ->setMethods (['getMountsIn ' , 'getMount ' ])
520479 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
@@ -561,10 +520,7 @@ public function testGetById() {
561520
562521 public function testGetByIdMountRoot () {
563522 $ manager = $ this ->createMock (Manager::class);
564- /**
565- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
566- */
567- $ view = $ this ->createMock (View::class);
523+ $ view = $ this ->getRootViewMock ();
568524 $ root = $ this ->getMockBuilder (Root::class)
569525 ->setMethods (['getMountsIn ' , 'getMount ' ])
570526 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
@@ -607,10 +563,7 @@ public function testGetByIdMountRoot() {
607563
608564 public function testGetByIdOutsideFolder () {
609565 $ manager = $ this ->createMock (Manager::class);
610- /**
611- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
612- */
613- $ view = $ this ->createMock (View::class);
566+ $ view = $ this ->getRootViewMock ();
614567 $ root = $ this ->getMockBuilder (Root::class)
615568 ->setMethods (['getMountsIn ' , 'getMount ' ])
616569 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
@@ -652,10 +605,7 @@ public function testGetByIdOutsideFolder() {
652605
653606 public function testGetByIdMultipleStorages () {
654607 $ manager = $ this ->createMock (Manager::class);
655- /**
656- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
657- */
658- $ view = $ this ->createMock (View::class);
608+ $ view = $ this ->getRootViewMock ();
659609 $ root = $ this ->getMockBuilder (Root::class)
660610 ->setMethods (['getMountsIn ' , 'getMount ' ])
661611 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
@@ -717,10 +667,7 @@ public function uniqueNameProvider() {
717667 public function testGetUniqueName ($ name , $ existingFiles , $ expected ) {
718668 $ manager = $ this ->createMock (Manager::class);
719669 $ folderPath = '/bar/foo ' ;
720- /**
721- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
722- */
723- $ view = $ this ->createMock (View::class);
670+ $ view = $ this ->getRootViewMock ();
724671 $ root = $ this ->getMockBuilder (Root::class)
725672 ->setMethods (['getUser ' , 'getMountsIn ' , 'getMount ' ])
726673 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
@@ -744,10 +691,7 @@ public function testGetUniqueName($name, $existingFiles, $expected) {
744691 public function testRecent (): void {
745692 $ manager = $ this ->createMock (Manager::class);
746693 $ folderPath = '/bar/foo ' ;
747- /**
748- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
749- */
750- $ view = $ this ->createMock (View::class);
694+ $ view = $ this ->getRootViewMock ();
751695 /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
752696 $ root = $ this ->getMockBuilder (Root::class)
753697 ->setMethods (['getUser ' , 'getMountsIn ' , 'getMount ' ])
@@ -812,10 +756,7 @@ public function testRecent(): void {
812756 public function testRecentFolder () {
813757 $ manager = $ this ->createMock (Manager::class);
814758 $ folderPath = '/bar/foo ' ;
815- /**
816- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
817- */
818- $ view = $ this ->createMock (View::class);
759+ $ view = $ this ->getRootViewMock ();
819760 /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
820761 $ root = $ this ->getMockBuilder (Root::class)
821762 ->setMethods (['getUser ' , 'getMountsIn ' , 'getMount ' ])
@@ -879,10 +820,7 @@ public function testRecentFolder() {
879820 public function testRecentJail () {
880821 $ manager = $ this ->createMock (Manager::class);
881822 $ folderPath = '/bar/foo ' ;
882- /**
883- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
884- */
885- $ view = $ this ->createMock (View::class);
823+ $ view = $ this ->getRootViewMock ();
886824 /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
887825 $ root = $ this ->getMockBuilder (Root::class)
888826 ->setMethods (['getUser ' , 'getMountsIn ' , 'getMount ' ])
@@ -968,10 +906,7 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array
968906 }
969907
970908 $ manager = $ this ->createMock (Manager::class);
971- /**
972- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
973- */
974- $ view = $ this ->createMock (View::class);
909+ $ view = $ this ->getRootViewMock ();
975910 $ root = $ this ->getMockBuilder (Root::class)
976911 ->setConstructorArgs ([$ manager , $ view , $ this ->user , $ this ->userMountCache , $ this ->logger , $ this ->userManager , $ this ->eventDispatcher ])
977912 ->getMock ();
0 commit comments