@@ -126,7 +126,6 @@ private function countPreviews(Root $previewRoot, array $fileIds): int {
126126 foreach ($ fileIds as $ fileId ) {
127127 try {
128128 $ previewRoot ->getFolder ((string )$ fileId );
129- var_dump ('Found: ' . $ fileId );
130129 } catch (NotFoundException $ e ) {
131130 continue ;
132131 }
@@ -161,30 +160,49 @@ public function testCleanupSystemCron() {
161160 $ this ->assertSame (0 , $ this ->countPreviews ($ root , $ fileIds ));
162161 }
163162
164- public function XtestCleanupAjax () {
163+ public function testCleanupAjax () {
165164 $ files = $ this ->setup11Previews ();
165+ $ fileIds = array_map (function (File $ f ) {
166+ return $ f ->getId ();
167+ }, $ files );
166168
167- $ preview = $ this ->appDataFactory ->get ('preview ' );
168-
169- $ previews = $ preview ->getDirectoryListing ();
170- $ this ->assertCount (11 , $ previews );
169+ $ root = $ this ->getRoot ();
171170
172- $ job = new BackgroundCleanupJob ($ this ->connection , $ this ->appDataFactory , $ this ->mimeTypeLoader , false );
171+ $ this ->assertSame (11 , $ this ->countPreviews ($ root , $ fileIds ));
172+ $ job = new BackgroundCleanupJob ($ this ->connection , $ root , $ this ->mimeTypeLoader , false );
173173 $ job ->run ([]);
174174
175175 foreach ($ files as $ file ) {
176176 $ file ->delete ();
177177 }
178178
179- $ this ->assertCount (11 , $ previews );
179+ $ root = $ this ->getRoot ();
180+ $ this ->assertSame (11 , $ this ->countPreviews ($ root , $ fileIds ));
180181 $ job ->run ([]);
181182
182- $ previews = $ preview ->getDirectoryListing ();
183- $ this ->assertCount (1 , $ previews );
183+ $ root = $ this ->getRoot ();
184+ $ this ->assertSame (1 , $ this ->countPreviews ($ root , $ fileIds ));
185+ $ job ->run ([]);
186+
187+ $ root = $ this ->getRoot ();
188+ $ this ->assertSame (0 , $ this ->countPreviews ($ root , $ fileIds ));
189+ }
190+
191+ public function testOldPreviews () {
192+ $ appdata = \OC ::$ server ->getAppDataDir ('preview ' );
193+
194+ $ f1 = $ appdata ->newFolder ('123456781 ' );
195+ $ f1 ->newFile ('foo.jpg ' , 'foo ' );
196+ $ f2 = $ appdata ->newFolder ('123456782 ' );
197+ $ f2 ->newFile ('foo.jpg ' , 'foo ' );
198+
199+ $ appdata = \OC ::$ server ->getAppDataDir ('preview ' );
200+ $ this ->assertSame (2 , count ($ appdata ->getDirectoryListing ()));
184201
202+ $ job = new BackgroundCleanupJob ($ this ->connection , $ this ->getRoot (), $ this ->mimeTypeLoader , true );
185203 $ job ->run ([]);
186204
187- $ previews = $ preview -> getDirectoryListing ( );
188- $ this ->assertCount (0 , $ previews );
205+ $ appdata = \ OC :: $ server -> getAppDataDir ( ' preview ' );
206+ $ this ->assertSame (0 , count ( $ appdata -> getDirectoryListing ()) );
189207 }
190208}
0 commit comments