Skip to content

Commit af0b8fb

Browse files
committed
fix(tests): Fix tests now that trashbin listens to events properly
Hooks are cleared in test bootstrap so switching to events activates them in tests. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent b80bc81 commit af0b8fb

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

apps/files/tests/Command/DeleteOrphanedFilesTest.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
use OC\Files\View;
1111
use OCA\Files\Command\DeleteOrphanedFiles;
12+
use OCP\Files\IRootFolder;
1213
use OCP\Files\StorageNotAvailableException;
14+
use OCP\IDBConnection;
1315
use Symfony\Component\Console\Input\InputInterface;
1416
use Symfony\Component\Console\Output\OutputInterface;
1517
use Test\TestCase;
@@ -23,25 +25,14 @@
2325
*/
2426
class DeleteOrphanedFilesTest extends TestCase {
2527

26-
/**
27-
* @var DeleteOrphanedFiles
28-
*/
29-
private $command;
30-
31-
/**
32-
* @var \OCP\IDBConnection
33-
*/
34-
private $connection;
35-
36-
/**
37-
* @var string
38-
*/
39-
private $user1;
28+
private DeleteOrphanedFiles $command;
29+
private IDBConnection $connection;
30+
private string $user1;
4031

4132
protected function setUp(): void {
4233
parent::setUp();
4334

44-
$this->connection = \OC::$server->getDatabaseConnection();
35+
$this->connection = \OCP\Server::get(IDBConnection::class);
4536

4637
$this->user1 = $this->getUniqueID('user1_');
4738

@@ -90,12 +81,13 @@ public function testClearFiles(): void {
9081
->disableOriginalConstructor()
9182
->getMock();
9283

84+
$rootFolder = \OCP\Server::get(IRootFolder::class);
85+
9386
// scan home storage so that mounts are properly setup
94-
\OC::$server->getRootFolder()->getUserFolder($this->user1)->getStorage()->getScanner()->scan('');
87+
$rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan('');
9588

9689
$this->loginAsUser($this->user1);
9790

98-
9991
$view = new View('/' . $this->user1 . '/');
10092
$view->mkdir('files/test');
10193

@@ -132,6 +124,8 @@ public function testClearFiles(): void {
132124
$this->assertCount(0, $this->getFile($fileInfo->getId()), 'Asserts that file gets cleaned up');
133125
$this->assertCount(0, $this->getMounts($numericStorageId), 'Asserts that mount gets cleaned up');
134126

127+
// Rescan folder to add back to cache before deleting
128+
$rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan('');
135129
// since we deleted the storage it might throw a (valid) StorageNotAvailableException
136130
try {
137131
$view->unlink('files/test');

tests/lib/Security/CertificateManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function setUp(): void {
4141
$this->registerMount($this->username, $storage, '/' . $this->username . '/');
4242

4343
\OC_Util::tearDownFS();
44-
\OC_User::setUserId('');
44+
\OC_User::setUserId($this->username);
4545
\OC\Files\Filesystem::tearDown();
4646
\OC_Util::setupFS($this->username);
4747

0 commit comments

Comments
 (0)