aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Utils')
-rw-r--r--tests/lib/Files/Utils/ScannerTest.php56
1 files changed, 29 insertions, 27 deletions
diff --git a/tests/lib/Files/Utils/ScannerTest.php b/tests/lib/Files/Utils/ScannerTest.php
index eb0b9938886..49399ef70a6 100644
--- a/tests/lib/Files/Utils/ScannerTest.php
+++ b/tests/lib/Files/Utils/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\Utils;
@@ -11,20 +11,25 @@ namespace Test\Files\Utils;
use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
+use OC\Files\Utils\Scanner;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
+use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Storage\IStorageFactory;
+use OCP\IDBConnection;
use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
-class TestScanner extends \OC\Files\Utils\Scanner {
+class TestScanner extends Scanner {
/**
- * @var \OC\Files\Mount\MountPoint[] $mounts
+ * @var MountPoint[] $mounts
*/
private $mounts = [];
/**
- * @param \OC\Files\Mount\MountPoint $mount
+ * @param MountPoint $mount
*/
public function addMount($mount) {
$this->mounts[] = $mount;
@@ -52,17 +57,17 @@ class ScannerTest extends \Test\TestCase {
parent::setUp();
$this->userBackend = new \Test\Util\User\Dummy();
- \OC::$server->getUserManager()->registerBackend($this->userBackend);
+ Server::get(IUserManager::class)->registerBackend($this->userBackend);
$this->loginAsUser();
}
protected function tearDown(): void {
$this->logout();
- \OC::$server->getUserManager()->removeBackend($this->userBackend);
+ Server::get(IUserManager::class)->removeBackend($this->userBackend);
parent::tearDown();
}
- public function testReuseExistingRoot() {
+ public function testReuseExistingRoot(): void {
$storage = new Temporary([]);
$mount = new MountPoint($storage, '');
Filesystem::getMountManager()->addMount($mount);
@@ -72,7 +77,7 @@ class ScannerTest extends \Test\TestCase {
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->addMount($mount);
$scanner->scan('');
@@ -84,7 +89,7 @@ class ScannerTest extends \Test\TestCase {
$this->assertEquals($oldRoot, $newRoot);
}
- public function testReuseExistingFile() {
+ public function testReuseExistingFile(): void {
$storage = new Temporary([]);
$mount = new MountPoint($storage, '');
Filesystem::getMountManager()->addMount($mount);
@@ -94,7 +99,7 @@ class ScannerTest extends \Test\TestCase {
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->addMount($mount);
$scanner->scan('');
@@ -106,7 +111,7 @@ class ScannerTest extends \Test\TestCase {
$this->assertEquals($old, $new);
}
- public function testScanSubMount() {
+ public function testScanSubMount(): void {
$uid = $this->getUniqueID();
$this->userBackend->createUser($uid, 'test');
@@ -125,24 +130,21 @@ class ScannerTest extends \Test\TestCase {
}
});
- \OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
+ Server::get(IMountProviderCollection::class)->registerProvider($mountProvider);
$cache = $storage->getCache();
$storage->mkdir('folder');
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new Scanner($uid, Server::get(IDBConnection::class), Server::get(IEventDispatcher::class), Server::get(LoggerInterface::class));
$this->assertFalse($cache->inCache('folder/bar.txt'));
$scanner->scan('/' . $uid . '/files/foo');
$this->assertTrue($cache->inCache('folder/bar.txt'));
}
- /**
- * @return array
- */
- public function invalidPathProvider() {
+ public static function invalidPathProvider(): array {
return [
[
'../',
@@ -157,18 +159,18 @@ class ScannerTest extends \Test\TestCase {
}
/**
- * @dataProvider invalidPathProvider
* @param string $invalidPath
*/
- public function testInvalidPathScanning($invalidPath) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('invalidPathProvider')]
+ public function testInvalidPathScanning($invalidPath): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid path to scan');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->scan($invalidPath);
}
- public function testPropagateEtag() {
+ public function testPropagateEtag(): void {
$storage = new Temporary([]);
$mount = new MountPoint($storage, '');
Filesystem::getMountManager()->addMount($mount);
@@ -178,7 +180,7 @@ class ScannerTest extends \Test\TestCase {
$storage->file_put_contents('folder/bar.txt', 'qwerty');
$storage->touch('folder/bar.txt', time() - 200);
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->addMount($mount);
$scanner->scan('');
@@ -192,7 +194,7 @@ class ScannerTest extends \Test\TestCase {
$this->assertNotEquals($oldRoot->getEtag(), $newRoot->getEtag());
}
- public function testShallow() {
+ public function testShallow(): void {
$storage = new Temporary([]);
$mount = new MountPoint($storage, '');
Filesystem::getMountManager()->addMount($mount);
@@ -204,7 +206,7 @@ class ScannerTest extends \Test\TestCase {
$storage->file_put_contents('folder/bar.txt', 'qwerty');
$storage->file_put_contents('folder/subfolder/foobar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->addMount($mount);
$scanner->scan('', $recusive = false);