diff options
Diffstat (limited to 'tests/lib/Files/Cache/ScannerTest.php')
-rw-r--r-- | tests/lib/Files/Cache/ScannerTest.php | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php index 22d458a4a9b..123c13893f7 100644 --- a/tests/lib/Files/Cache/ScannerTest.php +++ b/tests/lib/Files/Cache/ScannerTest.php @@ -1,9 +1,9 @@ <?php + /** - * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Files\Cache; @@ -15,6 +15,8 @@ use OC\Files\Cache\Scanner; use OC\Files\Storage\Storage; use OC\Files\Storage\Temporary; use OCP\Files\Cache\IScanner; +use OCP\IDBConnection; +use OCP\Server; use Test\TestCase; /** @@ -43,7 +45,7 @@ class ScannerTest extends TestCase { parent::tearDown(); } - public function testFile() { + public function testFile(): void { $data = "dummy file data\n"; $this->storage->file_put_contents('foo.txt', $data); $this->scanner->scanFile('foo.txt'); @@ -64,11 +66,11 @@ class ScannerTest extends TestCase { $this->assertEquals($cachedData['mimetype'], 'image/png'); } - public function testFile4Byte() { + public function testFile4Byte(): void { $data = "dummy file data\n"; $this->storage->file_put_contents('foo🙈.txt', $data); - if (OC::$server->getDatabaseConnection()->supports4ByteText()) { + if (Server::get(IDBConnection::class)->supports4ByteText()) { $this->assertNotNull($this->scanner->scanFile('foo🙈.txt')); $this->assertTrue($this->cache->inCache('foo🙈.txt'), true); @@ -82,7 +84,7 @@ class ScannerTest extends TestCase { } } - public function testFileInvalidChars() { + public function testFileInvalidChars(): void { $data = "dummy file data\n"; $this->storage->file_put_contents("foo\nbar.txt", $data); @@ -99,7 +101,7 @@ class ScannerTest extends TestCase { $this->storage->file_put_contents('folder/bar.txt', $textData); } - public function testFolder() { + public function testFolder(): void { $this->fillTestFolders(); $this->scanner->scan(''); @@ -121,7 +123,7 @@ class ScannerTest extends TestCase { $this->assertEquals($cachedDataFolder2['size'], $cachedDataText2['size']); } - public function testShallow() { + public function testShallow(): void { $this->fillTestFolders(); $this->scanner->scan('', IScanner::SCAN_SHALLOW); @@ -149,7 +151,7 @@ class ScannerTest extends TestCase { $this->assertNotEquals($cachedDataFolder['size'], -1); } - public function testBackgroundScan() { + public function testBackgroundScan(): void { $this->fillTestFolders(); $this->storage->mkdir('folder2'); $this->storage->file_put_contents('folder2/bar.txt', 'foobar'); @@ -171,7 +173,7 @@ class ScannerTest extends TestCase { $this->assertFalse($this->cache->getIncomplete()); } - public function testBackgroundScanOnlyRecurseIncomplete() { + public function testBackgroundScanOnlyRecurseIncomplete(): void { $this->fillTestFolders(); $this->storage->mkdir('folder2'); $this->storage->file_put_contents('folder2/bar.txt', 'foobar'); @@ -197,7 +199,7 @@ class ScannerTest extends TestCase { $this->assertFalse($this->cache->getIncomplete()); } - public function testBackgroundScanNestedIncompleteFolders() { + public function testBackgroundScanNestedIncompleteFolders(): void { $this->storage->mkdir('folder'); $this->scanner->backgroundScan(); @@ -235,7 +237,7 @@ class ScannerTest extends TestCase { $this->assertEquals(6, $this->cache->get('folder/subfolder2')['size']); } - public function testReuseExisting() { + public function testReuseExisting(): void { $this->fillTestFolders(); $this->scanner->scan(''); @@ -274,7 +276,7 @@ class ScannerTest extends TestCase { $this->assertEquals($oldData['size'], $newData['size']); } - public function testRemovedFile() { + public function testRemovedFile(): void { $this->fillTestFolders(); $this->scanner->scan(''); @@ -284,7 +286,7 @@ class ScannerTest extends TestCase { $this->assertFalse($this->cache->inCache('foo.txt')); } - public function testRemovedFolder() { + public function testRemovedFolder(): void { $this->fillTestFolders(); $this->scanner->scan(''); @@ -295,7 +297,7 @@ class ScannerTest extends TestCase { $this->assertFalse($this->cache->inCache('folder/bar.txt')); } - public function testScanRemovedFile() { + public function testScanRemovedFile(): void { $this->fillTestFolders(); $this->scanner->scan(''); @@ -305,7 +307,7 @@ class ScannerTest extends TestCase { $this->assertFalse($this->cache->inCache('folder/bar.txt')); } - public function testETagRecreation() { + public function testETagRecreation(): void { $this->fillTestFolders(); $this->scanner->scan('folder/bar.txt'); @@ -331,14 +333,14 @@ class ScannerTest extends TestCase { $this->assertNotEmpty($newData0['etag']); } - public function testRepairParent() { + public function testRepairParent(): void { $this->fillTestFolders(); $this->scanner->scan(''); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $oldFolderId = $this->cache->getId('folder'); // delete the folder without removing the children - $query = OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId))); $query->execute(); @@ -357,14 +359,14 @@ class ScannerTest extends TestCase { $this->assertEquals($newFolderId, $cachedData['parent']); } - public function testRepairParentShallow() { + public function testRepairParentShallow(): void { $this->fillTestFolders(); $this->scanner->scan(''); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $oldFolderId = $this->cache->getId('folder'); // delete the folder without removing the children - $query = OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId))); $query->execute(); @@ -384,18 +386,18 @@ class ScannerTest extends TestCase { } /** - * @dataProvider dataTestIsPartialFile * * @param string $path * @param bool $expected */ - public function testIsPartialFile($path, $expected) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsPartialFile')] + public function testIsPartialFile($path, $expected): void { $this->assertSame($expected, $this->scanner->isPartialFile($path) ); } - public function dataTestIsPartialFile() { + public static function dataTestIsPartialFile(): array { return [ ['foo.txt.part', true], ['/sub/folder/foo.txt.part', true], @@ -405,7 +407,7 @@ class ScannerTest extends TestCase { ]; } - public function testNoETagUnscannedFolder() { + public function testNoETagUnscannedFolder(): void { $this->fillTestFolders(); $this->scanner->scan(''); @@ -424,7 +426,7 @@ class ScannerTest extends TestCase { $this->assertNotEquals($newFolderEntry->getEtag(), $oldFolderEntry->getEtag()); } - public function testNoETagUnscannedSubFolder() { + public function testNoETagUnscannedSubFolder(): void { $this->fillTestFolders(); $this->storage->mkdir('folder/sub'); |