Skip to content

Commit 7304a23

Browse files
committed
fixup! Update tests
Signed-off-by: Roeland Jago Douma <[email protected]>
1 parent 8c8289f commit 7304a23

3 files changed

Lines changed: 31 additions & 17 deletions

File tree

lib/private/Preview/BackgroundCleanupJob.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,11 @@ public function __construct(IDBConnection $connection,
6666
public function run($argument) {
6767
foreach ($this->getDeletedFiles() as $fileId) {
6868
try {
69-
var_dump("CLEANING UP: " . $fileId);
7069
$preview = $this->previewFolder->getFolder((string)$fileId);
7170
$preview->delete();
72-
var_dump("CLEANED UP: " . $fileId);
7371
} catch (NotFoundException $e) {
74-
var_dump("!!!!!!NOT FOUND: " . $fileId);
7572
// continue
7673
} catch (NotPermittedException $e) {
77-
var_dump("!!!! NOT PERMITTED: " . $fileId);
7874
// continue
7975
}
8076
}

lib/private/Preview/Watcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function deleteNode(Node $node) {
6363

6464
try {
6565
$folder = $this->appData->getFolder((string)$node->getId());
66-
//$folder->delete();
66+
$folder->delete();
6767
} catch (NotFoundException $e) {
6868
//Nothing to do
6969
}

tests/lib/Preview/BackgroundCleanupJobTest.php

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)