2727
2828use OC \User \Manager ;
2929use OCA \Files_Versions \Command \CleanUp ;
30+ use OCP \Files \Cache \ICache ;
31+ use OCP \Files \Folder ;
3032use OCP \Files \IRootFolder ;
33+ use OCP \Files \Storage \IStorage ;
3134use Test \TestCase ;
3235
3336/**
@@ -48,16 +51,20 @@ class CleanupTest extends TestCase {
4851 /** @var \PHPUnit\Framework\MockObject\MockObject | IRootFolder */
4952 protected $ rootFolder ;
5053
54+ /** @var \PHPUnit\Framework\MockObject\MockObject | VersionsMapper */
55+ protected $ versionMapper ;
56+
5157 protected function setUp (): void {
5258 parent ::setUp ();
5359
5460 $ this ->rootFolder = $ this ->getMockBuilder ('OCP\Files\IRootFolder ' )
5561 ->disableOriginalConstructor ()->getMock ();
5662 $ this ->userManager = $ this ->getMockBuilder ('OC\User\Manager ' )
5763 ->disableOriginalConstructor ()->getMock ();
64+ $ this ->versionMapper = $ this ->getMockBuilder ('OCA\Files_Versions\Db\VersionsMapper ' )
65+ ->disableOriginalConstructor ()->getMock ();
5866
59-
60- $ this ->cleanup = new CleanUp ($ this ->rootFolder , $ this ->userManager );
67+ $ this ->cleanup = new CleanUp ($ this ->rootFolder , $ this ->userManager , $ this ->versionMapper );
6168 }
6269
6370 /**
@@ -70,8 +77,24 @@ public function testDeleteVersions($nodeExists) {
7077 ->with ('/testUser/files_versions ' )
7178 ->willReturn ($ nodeExists );
7279
73-
74- if ($ nodeExists ) {
80+ $ userFolder = $ this ->createMock (Folder::class);
81+ $ userHomeStorage = $ this ->createMock (IStorage::class);
82+ $ userHomeStorageCache = $ this ->createMock (ICache::class);
83+ $ this ->rootFolder ->expects ($ this ->once ())
84+ ->method ('getUserFolder ' )
85+ ->with ('testUser ' )
86+ ->willReturn ($ userFolder );
87+ $ userFolder ->expects ($ this ->once ())
88+ ->method ('getStorage ' )
89+ ->willReturn ($ userHomeStorage );
90+ $ userHomeStorage ->expects ($ this ->once ())
91+ ->method ('getCache ' )
92+ ->willReturn ($ userHomeStorageCache );
93+ $ userHomeStorageCache ->expects ($ this ->once ())
94+ ->method ('getNumericStorageId ' )
95+ ->willReturn (1 );
96+
97+ if ($ nodeExists ) {
7598 $ this ->rootFolder ->expects ($ this ->once ())
7699 ->method ('get ' )
77100 ->with ('/testUser/files_versions ' )
@@ -104,7 +127,7 @@ public function testExecuteDeleteListOfUsers() {
104127
105128 $ instance = $ this ->getMockBuilder ('OCA\Files_Versions\Command\CleanUp ' )
106129 ->setMethods (['deleteVersions ' ])
107- ->setConstructorArgs ([$ this ->rootFolder , $ this ->userManager ])
130+ ->setConstructorArgs ([$ this ->rootFolder , $ this ->userManager , $ this -> versionMapper ])
108131 ->getMock ();
109132 $ instance ->expects ($ this ->exactly (count ($ userIds )))
110133 ->method ('deleteVersions ' )
@@ -136,7 +159,7 @@ public function testExecuteAllUsers() {
136159
137160 $ instance = $ this ->getMockBuilder ('OCA\Files_Versions\Command\CleanUp ' )
138161 ->setMethods (['deleteVersions ' ])
139- ->setConstructorArgs ([$ this ->rootFolder , $ this ->userManager ])
162+ ->setConstructorArgs ([$ this ->rootFolder , $ this ->userManager , $ this -> versionMapper ])
140163 ->getMock ();
141164
142165 $ backend = $ this ->getMockBuilder (\OCP \UserInterface::class)
0 commit comments