1212use OC \Files \FileInfo ;
1313use OC \Files \Mount \MountPoint ;
1414use OC \Files \Node \Node ;
15+ use OC \Files \Storage \Temporary ;
16+ use OC \Files \Storage \Wrapper \Jail ;
1517use OCP \Files \NotFoundException ;
1618use OCP \Files \NotPermittedException ;
1719use OC \Files \View ;
@@ -760,9 +762,9 @@ public function testGetByIdMultipleStorages() {
760762 public function uniqueNameProvider () {
761763 return [
762764 // input, existing, expected
763- ['foo ' , [] , 'foo ' ],
764- ['foo ' , ['foo ' ] , 'foo (2) ' ],
765- ['foo ' , ['foo ' , 'foo (2) ' ] , 'foo (3) ' ]
765+ ['foo ' , [], 'foo ' ],
766+ ['foo ' , ['foo ' ], 'foo (2) ' ],
767+ ['foo ' , ['foo ' , 'foo (2) ' ], 'foo (3) ' ]
766768 ];
767769 }
768770
@@ -782,7 +784,7 @@ public function testGetUniqueName($name, $existingFiles, $expected) {
782784 ->method ('file_exists ' )
783785 ->will ($ this ->returnCallback (function ($ path ) use ($ existingFiles , $ folderPath ) {
784786 foreach ($ existingFiles as $ existing ) {
785- if ($ folderPath . '/ ' . $ existing === $ path ){
787+ if ($ folderPath . '/ ' . $ existing === $ path ) {
786788 return true ;
787789 }
788790 }
@@ -792,4 +794,165 @@ public function testGetUniqueName($name, $existingFiles, $expected) {
792794 $ node = new \OC \Files \Node \Folder ($ root , $ view , $ folderPath );
793795 $ this ->assertEquals ($ expected , $ node ->getNonExistingName ($ name ));
794796 }
797+
798+ public function testRecent () {
799+ $ manager = $ this ->getMock ('\OC\Files\Mount\Manager ' );
800+ $ folderPath = '/bar/foo ' ;
801+ /**
802+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
803+ */
804+ $ view = $ this ->getMock ('\OC\Files\View ' );
805+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
806+ $ root = $ this ->getMock ('\OC\Files\Node\Root ' , array ('getUser ' , 'getMountsIn ' , 'getMount ' ), array ($ manager , $ view , $ this ->user ));
807+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
808+ $ folderInfo = $ this ->getMockBuilder ('\OC\Files\FileInfo ' )
809+ ->disableOriginalConstructor ()->getMock ();
810+
811+ $ baseTime = 1000 ;
812+ $ storage = new Temporary ();
813+ $ mount = new MountPoint ($ storage , '' );
814+
815+ $ folderInfo ->expects ($ this ->any ())
816+ ->method ('getMountPoint ' )
817+ ->will ($ this ->returnValue ($ mount ));
818+
819+ $ cache = $ storage ->getCache ();
820+
821+ $ id1 = $ cache ->put ('bar/foo/inside.txt ' , [
822+ 'storage_mtime ' => $ baseTime ,
823+ 'mtime ' => $ baseTime ,
824+ 'mimetype ' => 'text/plain ' ,
825+ 'size ' => 3
826+ ]);
827+ $ id2 = $ cache ->put ('bar/foo/old.txt ' , [
828+ 'storage_mtime ' => $ baseTime - 100 ,
829+ 'mtime ' => $ baseTime - 100 ,
830+ 'mimetype ' => 'text/plain ' ,
831+ 'size ' => 3
832+ ]);
833+ $ cache ->put ('bar/asd/outside.txt ' , [
834+ 'storage_mtime ' => $ baseTime ,
835+ 'mtime ' => $ baseTime ,
836+ 'mimetype ' => 'text/plain ' ,
837+ 'size ' => 3
838+ ]);
839+ $ cache ->put ('bar/foo/toold.txt ' , [
840+ 'storage_mtime ' => $ baseTime - 600 ,
841+ 'mtime ' => $ baseTime - 600 ,
842+ 'mimetype ' => 'text/plain ' ,
843+ 'size ' => 3
844+ ]);
845+
846+ $ node = new \OC \Files \Node \Folder ($ root , $ view , $ folderPath , $ folderInfo );
847+
848+
849+ $ nodes = $ node ->getRecent ($ baseTime - 500 );
850+ $ ids = array_map (function (Node $ node ) {
851+ return (int )$ node ->getId ();
852+ }, $ nodes );
853+ $ this ->assertEquals ([$ id1 , $ id2 ], $ ids );
854+ }
855+
856+ public function testRecentFolder () {
857+ $ manager = $ this ->getMock ('\OC\Files\Mount\Manager ' );
858+ $ folderPath = '/bar/foo ' ;
859+ /**
860+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
861+ */
862+ $ view = $ this ->getMock ('\OC\Files\View ' );
863+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
864+ $ root = $ this ->getMock ('\OC\Files\Node\Root ' , array ('getUser ' , 'getMountsIn ' , 'getMount ' ), array ($ manager , $ view , $ this ->user ));
865+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
866+ $ folderInfo = $ this ->getMockBuilder ('\OC\Files\FileInfo ' )
867+ ->disableOriginalConstructor ()->getMock ();
868+
869+ $ baseTime = 1000 ;
870+ $ storage = new Temporary ();
871+ $ mount = new MountPoint ($ storage , '' );
872+
873+ $ folderInfo ->expects ($ this ->any ())
874+ ->method ('getMountPoint ' )
875+ ->will ($ this ->returnValue ($ mount ));
876+
877+ $ cache = $ storage ->getCache ();
878+
879+ $ id1 = $ cache ->put ('bar/foo/folder ' , [
880+ 'storage_mtime ' => $ baseTime ,
881+ 'mtime ' => $ baseTime ,
882+ 'mimetype ' => \OCP \Files \FileInfo::MIMETYPE_FOLDER ,
883+ 'size ' => 3
884+ ]);
885+ $ id2 = $ cache ->put ('bar/foo/folder/bar.txt ' , [
886+ 'storage_mtime ' => $ baseTime ,
887+ 'mtime ' => $ baseTime ,
888+ 'mimetype ' => 'text/plain ' ,
889+ 'size ' => 3 ,
890+ 'parent ' => $ id1
891+ ]);
892+ $ id3 = $ cache ->put ('bar/foo/folder/asd.txt ' , [
893+ 'storage_mtime ' => $ baseTime ,
894+ 'mtime ' => $ baseTime - 100 ,
895+ 'mimetype ' => 'text/plain ' ,
896+ 'size ' => 3 ,
897+ 'parent ' => $ id1
898+ ]);
899+
900+ $ node = new \OC \Files \Node \Folder ($ root , $ view , $ folderPath , $ folderInfo );
901+
902+
903+ $ nodes = $ node ->getRecent ($ baseTime - 500 );
904+ $ ids = array_map (function (Node $ node ) {
905+ return (int )$ node ->getId ();
906+ }, $ nodes );
907+ $ this ->assertEquals ([$ id2 , $ id1 , $ id3 ], $ ids );// sort folders before files with the same mtime, folders get the lowest child mtime
908+ }
909+
910+ public function testRecentJail () {
911+ $ manager = $ this ->getMock ('\OC\Files\Mount\Manager ' );
912+ $ folderPath = '/bar/foo ' ;
913+ /**
914+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
915+ */
916+ $ view = $ this ->getMock ('\OC\Files\View ' );
917+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
918+ $ root = $ this ->getMock ('\OC\Files\Node\Root ' , array ('getUser ' , 'getMountsIn ' , 'getMount ' ), array ($ manager , $ view , $ this ->user ));
919+ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
920+ $ folderInfo = $ this ->getMockBuilder ('\OC\Files\FileInfo ' )
921+ ->disableOriginalConstructor ()->getMock ();
922+
923+ $ baseTime = 1000 ;
924+ $ storage = new Temporary ();
925+ $ jail = new Jail ([
926+ 'storage ' => $ storage ,
927+ 'root ' => 'folder '
928+ ]);
929+ $ mount = new MountPoint ($ jail , '/bar/foo ' );
930+
931+ $ folderInfo ->expects ($ this ->any ())
932+ ->method ('getMountPoint ' )
933+ ->will ($ this ->returnValue ($ mount ));
934+
935+ $ cache = $ storage ->getCache ();
936+
937+ $ id1 = $ cache ->put ('folder/inside.txt ' , [
938+ 'storage_mtime ' => $ baseTime ,
939+ 'mtime ' => $ baseTime ,
940+ 'mimetype ' => 'text/plain ' ,
941+ 'size ' => 3
942+ ]);
943+ $ cache ->put ('outside.txt ' , [
944+ 'storage_mtime ' => $ baseTime - 100 ,
945+ 'mtime ' => $ baseTime - 100 ,
946+ 'mimetype ' => 'text/plain ' ,
947+ 'size ' => 3
948+ ]);
949+
950+ $ node = new \OC \Files \Node \Folder ($ root , $ view , $ folderPath , $ folderInfo );
951+
952+ $ nodes = $ node ->getRecent ($ baseTime - 500 );
953+ $ ids = array_map (function (Node $ node ) {
954+ return (int )$ node ->getId ();
955+ }, $ nodes );
956+ $ this ->assertEquals ([$ id1 ], $ ids );
957+ }
795958}
0 commit comments