2015-03-04 05:37:35 -05:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2015-03-04 05:37:35 -05:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2015-03-04 05:37:35 -05:00
|
|
|
*/
|
2019-11-22 14:52:10 -05:00
|
|
|
|
2016-05-20 09:38:20 -04:00
|
|
|
namespace Test\Files\ObjectStore;
|
2015-03-04 05:37:35 -05:00
|
|
|
|
2023-04-12 12:08:14 -04:00
|
|
|
use OC\Files\Cache\Scanner;
|
|
|
|
|
use OC\Files\ObjectStore\ObjectStoreScanner;
|
|
|
|
|
use OC\Files\Storage\Temporary;
|
|
|
|
|
use OCP\Files\Cache\ICache;
|
|
|
|
|
use OCP\Files\Storage\IStorage;
|
|
|
|
|
use Test\TestCase;
|
2015-03-04 05:37:35 -05:00
|
|
|
|
2025-10-20 19:52:40 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\Group('DB')]
|
2023-04-12 12:08:14 -04:00
|
|
|
class ObjectStoreScannerTest extends TestCase {
|
|
|
|
|
private IStorage $storage;
|
|
|
|
|
private ICache $cache;
|
|
|
|
|
private ObjectStoreScanner $scanner;
|
|
|
|
|
private Scanner $realScanner;
|
2015-03-04 05:37:35 -05:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2015-03-04 05:37:35 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2023-04-12 12:08:14 -04:00
|
|
|
$this->storage = new Temporary([]);
|
|
|
|
|
$this->cache = $this->storage->getCache();
|
|
|
|
|
$this->scanner = new ObjectStoreScanner($this->storage);
|
|
|
|
|
$this->realScanner = new Scanner($this->storage);
|
2015-03-04 05:37:35 -05:00
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testFile(): void {
|
2015-03-04 05:37:35 -05:00
|
|
|
$data = "dummy file data\n";
|
|
|
|
|
$this->storage->file_put_contents('foo.txt', $data);
|
|
|
|
|
|
2025-01-26 08:56:17 -05:00
|
|
|
$this->assertNull($this->scanner->scanFile('foo.txt'),
|
2015-03-04 05:37:35 -05:00
|
|
|
'Asserting that no error occurred while scanFile()'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function fillTestFolders() {
|
|
|
|
|
$textData = "dummy file data\n";
|
2018-08-28 09:58:27 -04:00
|
|
|
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
|
2015-03-04 05:37:35 -05:00
|
|
|
$this->storage->mkdir('folder');
|
|
|
|
|
$this->storage->file_put_contents('foo.txt', $textData);
|
|
|
|
|
$this->storage->file_put_contents('foo.png', $imgData);
|
|
|
|
|
$this->storage->file_put_contents('folder/bar.txt', $textData);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testFolder(): void {
|
2015-03-04 05:37:35 -05:00
|
|
|
$this->fillTestFolders();
|
|
|
|
|
|
2025-01-26 08:56:17 -05:00
|
|
|
$this->assertNull(
|
2015-03-04 05:37:35 -05:00
|
|
|
$this->scanner->scan(''),
|
|
|
|
|
'Asserting that no error occurred while scan()'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testBackgroundScan(): void {
|
2015-03-04 05:37:35 -05:00
|
|
|
$this->fillTestFolders();
|
|
|
|
|
$this->storage->mkdir('folder2');
|
|
|
|
|
$this->storage->file_put_contents('folder2/bar.txt', 'foobar');
|
|
|
|
|
|
2023-04-12 12:08:14 -04:00
|
|
|
$this->realScanner->scan('');
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(6, $this->cache->get('folder2')->getSize());
|
|
|
|
|
|
|
|
|
|
$this->cache->put('folder2', ['size' => -1]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(-1, $this->cache->get('folder2')->getSize());
|
2015-03-04 05:37:35 -05:00
|
|
|
|
|
|
|
|
$this->scanner->backgroundScan();
|
|
|
|
|
|
2023-04-12 12:08:14 -04:00
|
|
|
$this->assertEquals(6, $this->cache->get('folder2')->getSize());
|
2015-03-04 05:37:35 -05:00
|
|
|
}
|
|
|
|
|
}
|