|
9 | 9 |
|
10 | 10 | namespace Test\Preview\Storage; |
11 | 11 |
|
| 12 | +use OC\Preview\Db\Preview; |
12 | 13 | use OC\Preview\Db\PreviewMapper; |
13 | 14 | use OC\Preview\Storage\LocalPreviewStorage; |
14 | 15 | use OCP\DB\Exception as DBException; |
|
19 | 20 | use OCP\Files\IMimeTypeDetector; |
20 | 21 | use OCP\Files\IMimeTypeLoader; |
21 | 22 | use OCP\Files\IRootFolder; |
| 23 | +use OCP\Files\NotFoundException; |
22 | 24 | use OCP\IAppConfig; |
23 | 25 | use OCP\IConfig; |
24 | 26 | use OCP\IDBConnection; |
@@ -287,4 +289,43 @@ public function testScanFetchesAllFilecacheRows(): void { |
287 | 289 |
|
288 | 290 | $this->assertSame(3, $count); |
289 | 291 | } |
| 292 | + |
| 293 | + private function makePreview(int $fileId = self::FILE_ID): Preview { |
| 294 | + $preview = new Preview(); |
| 295 | + $preview->setFileId($fileId); |
| 296 | + $preview->setWidth(1024); |
| 297 | + $preview->setHeight(768); |
| 298 | + $preview->setCropped(false); |
| 299 | + $preview->setMax(true); |
| 300 | + $preview->setMimetype('image/jpeg'); |
| 301 | + |
| 302 | + return $preview; |
| 303 | + } |
| 304 | + |
| 305 | + /** |
| 306 | + * Losing the insert race must not remove the local file: the path is derived |
| 307 | + * from the preview specification, so it is the same file the preview that |
| 308 | + * won the race now points at. |
| 309 | + */ |
| 310 | + public function testDeleteUnreferencedPreviewKeepsTheSharedFile(): void { |
| 311 | + $preview = $this->makePreview(); |
| 312 | + $this->storage->writePreview($preview, 'preview data'); |
| 313 | + |
| 314 | + $this->storage->deleteUnreferencedPreview($preview); |
| 315 | + |
| 316 | + $this->assertSame('preview data', stream_get_contents($this->storage->readPreview($preview))); |
| 317 | + } |
| 318 | + |
| 319 | + /** |
| 320 | + * Deleting a preview for real still has to remove the file. |
| 321 | + */ |
| 322 | + public function testDeletePreviewRemovesTheFile(): void { |
| 323 | + $preview = $this->makePreview(); |
| 324 | + $this->storage->writePreview($preview, 'preview data'); |
| 325 | + |
| 326 | + $this->storage->deletePreview($preview); |
| 327 | + |
| 328 | + $this->expectException(NotFoundException::class); |
| 329 | + $this->storage->readPreview($preview); |
| 330 | + } |
290 | 331 | } |
0 commit comments