Skip to content

Commit 3afdfdd

Browse files
committed
Update tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent ef203c1 commit 3afdfdd

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

lib/private/Preview/BackgroundCleanupJob.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ public function __construct(IDBConnection $connection,
6666
public function run($argument) {
6767
foreach ($this->getDeletedFiles() as $fileId) {
6868
try {
69-
$preview = $this->previewFolder->getFolder($fileId);
69+
var_dump("CLEANING UP: " . $fileId);
70+
$preview = $this->previewFolder->getFolder((string)$fileId);
7071
$preview->delete();
72+
var_dump("CLEANED UP: " . $fileId);
7173
} catch (NotFoundException $e) {
74+
var_dump("!!!!!!NOT FOUND: " . $fileId);
7275
// continue
7376
} catch (NotPermittedException $e) {
77+
var_dump("!!!! NOT PERMITTED: " . $fileId);
7478
// continue
7579
}
7680
}

tests/lib/Preview/BackgroundCleanupJobTest.php

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424

2525
use OC\Files\AppData\Factory;
2626
use OC\Preview\BackgroundCleanupJob;
27+
use OC\Preview\Storage\Root;
2728
use OC\PreviewManager;
2829
use OC\SystemConfig;
30+
use OCP\Files\File;
31+
use OCP\Files\IMimeTypeLoader;
2932
use OCP\Files\IRootFolder;
33+
use OCP\Files\NotFoundException;
3034
use OCP\IDBConnection;
3135
use Test\Traits\MountProviderTrait;
3236
use Test\Traits\UserTrait;
@@ -49,9 +53,6 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
4953
/** @var bool */
5054
private $trashEnabled;
5155

52-
/** @var Factory */
53-
private $appDataFactory;
54-
5556
/** @var IDBConnection */
5657
private $connection;
5758

@@ -61,6 +62,9 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
6162
/** @var IRootFolder */
6263
private $rootFolder;
6364

65+
/** @var IMimeTypeLoader */
66+
private $mimeTypeLoader;
67+
6468
protected function setUp(): void {
6569
parent::setUp();
6670

@@ -78,13 +82,10 @@ protected function setUp(): void {
7882
$this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $this->userId);
7983
$appManager->disableApp('files_trashbin');
8084

81-
$this->appDataFactory = new Factory(
82-
\OC::$server->getRootFolder(),
83-
\OC::$server->getSystemConfig()
84-
);
8585
$this->connection = \OC::$server->getDatabaseConnection();
8686
$this->previewManager = \OC::$server->getPreviewManager();
8787
$this->rootFolder = \OC::$server->getRootFolder();
88+
$this->mimeTypeLoader = \OC::$server->getMimeTypeLoader();
8889
}
8990

9091
protected function tearDown(): void {
@@ -98,6 +99,13 @@ protected function tearDown(): void {
9899
parent::tearDown();
99100
}
100101

102+
private function getRoot(): Root {
103+
return new Root(
104+
\OC::$server->getRootFolder(),
105+
\OC::$server->getSystemConfig()
106+
);
107+
}
108+
101109
private function setup11Previews(): array {
102110
$userFolder = $this->rootFolder->getUserFolder($this->userId);
103111

@@ -112,37 +120,56 @@ private function setup11Previews(): array {
112120
return $files;
113121
}
114122

123+
private function countPreviews(Root $previewRoot, array $fileIds): int {
124+
$i = 0;
125+
126+
foreach ($fileIds as $fileId) {
127+
try {
128+
$previewRoot->getFolder((string)$fileId);
129+
var_dump('Found: ' . $fileId);
130+
} catch (NotFoundException $e) {
131+
continue;
132+
}
133+
134+
$i++;
135+
}
136+
137+
return $i;
138+
}
139+
115140
public function testCleanupSystemCron() {
116141
$files = $this->setup11Previews();
142+
$fileIds = array_map(function (File $f) {
143+
return $f->getId();
144+
}, $files);
117145

118-
$preview = $this->appDataFactory->get('preview');
146+
$root = $this->getRoot();
119147

120-
$previews = $preview->getDirectoryListing();
121-
$this->assertCount(11, $previews);
122-
123-
$job = new BackgroundCleanupJob($this->connection, $this->appDataFactory, true);
148+
$this->assertSame(11, $this->countPreviews($root, $fileIds));
149+
$job = new BackgroundCleanupJob($this->connection, $root, $this->mimeTypeLoader, true);
124150
$job->run([]);
125151

126152
foreach ($files as $file) {
127153
$file->delete();
128154
}
129155

130-
$this->assertCount(11, $previews);
156+
$root = $this->getRoot();
157+
$this->assertSame(11, $this->countPreviews($root, $fileIds));
131158
$job->run([]);
132159

133-
$previews = $preview->getDirectoryListing();
134-
$this->assertCount(0, $previews);
160+
$root = $this->getRoot();
161+
$this->assertSame(0, $this->countPreviews($root, $fileIds));
135162
}
136163

137-
public function testCleanupAjax() {
164+
public function XtestCleanupAjax() {
138165
$files = $this->setup11Previews();
139166

140167
$preview = $this->appDataFactory->get('preview');
141168

142169
$previews = $preview->getDirectoryListing();
143170
$this->assertCount(11, $previews);
144171

145-
$job = new BackgroundCleanupJob($this->connection, $this->appDataFactory, false);
172+
$job = new BackgroundCleanupJob($this->connection, $this->appDataFactory, $this->mimeTypeLoader, false);
146173
$job->run([]);
147174

148175
foreach ($files as $file) {

0 commit comments

Comments
 (0)