Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <[email protected]>
  • Loading branch information
come-nc committed Sep 23, 2024
commit af0b8fbd178bdbca159475a232a8b54ccb746df7
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