Skip to content

Commit

Permalink
fix(tests): Fix tests now that trashbin listens to events properly
Browse files Browse the repository at this point in the history
Hooks are cleared in test bootstrap so switching to events activates
 them in tests.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Sep 23, 2024
1 parent 8a6761a commit 98986b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions apps/files/tests/Command/DeleteOrphanedFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

use OC\Files\View;
use OCA\Files\Command\DeleteOrphanedFiles;
use OCP\Files\IRootFolder;
use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
Expand All @@ -23,25 +25,14 @@
*/
class DeleteOrphanedFilesTest extends TestCase {

/**
* @var DeleteOrphanedFiles
*/
private $command;

/**
* @var \OCP\IDBConnection
*/
private $connection;

/**
* @var string
*/
private $user1;
private DeleteOrphanedFiles $command;
private IDBConnection $connection;
private string $user1;

protected function setUp(): void {
parent::setUp();

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

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

Expand Down Expand Up @@ -90,12 +81,13 @@ public function testClearFiles(): void {
->disableOriginalConstructor()
->getMock();

$rootFolder = \OCP\Server::get(IRootFolder::class);

// scan home storage so that mounts are properly setup
\OC::$server->getRootFolder()->getUserFolder($this->user1)->getStorage()->getScanner()->scan('');
$rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan('');

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


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

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

// Rescan folder to add back to cache before deleting
$rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan('');
// since we deleted the storage it might throw a (valid) StorageNotAvailableException
try {
$view->unlink('files/test');
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Security/CertificateManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp(): void {
$this->registerMount($this->username, $storage, '/' . $this->username . '/');

\OC_Util::tearDownFS();
\OC_User::setUserId('');
\OC_User::setUserId($this->username);
\OC\Files\Filesystem::tearDown();
\OC_Util::setupFS($this->username);

Expand Down

0 comments on commit 98986b7

Please sign in to comment.