Skip to content
Draft
4 changes: 0 additions & 4 deletions apps/comments/lib/Search/CommentsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public function getOrder(string $route, array $routeParameters): int {
public function search(IUser $user, ISearchQuery $query): SearchResult {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());

if ($userFolder === null) {
return SearchResult::complete($this->l10n->t('Comments'), []);
}

$result = [];
$numComments = 50;
$offset = 0;
Expand Down
4 changes: 2 additions & 2 deletions apps/comments/tests/Unit/Activity/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use OCP\Files\Config\ICachedMountFileInfo;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\Files\Node;
use OCP\IUser;
use OCP\IUserSession;
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testCommentEvent(): void {

$node = $this->createMock(Node::class);

$ownerFolder = $this->createMock(Folder::class);
$ownerFolder = $this->createMock(IUserFolder::class);
$ownerFolder->expects($this->any())
->method('getFirstNodeById')
->willReturn($node);
Expand Down
6 changes: 3 additions & 3 deletions apps/comments/tests/Unit/Controller/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\Files\Node;
use OCP\IRequest;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testViewSuccess(): void {
->willReturn($comment);

$file = $this->createMock(Node::class);
$folder = $this->createMock(Folder::class);
$folder = $this->createMock(IUserFolder::class);
$user = $this->createMock(IUser::class);

$this->rootFolder->expects($this->once())
Expand Down Expand Up @@ -176,7 +176,7 @@ public function testViewNoFile(): void {
->with('42')
->willReturn($comment);

$folder = $this->createMock(Folder::class);
$folder = $this->createMock(IUserFolder::class);

$this->rootFolder->expects($this->once())
->method('getUserFolder')
Expand Down
8 changes: 4 additions & 4 deletions apps/comments/tests/Unit/Notification/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\Files\Node;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function testPrepareSuccess(): void {
->method('getPath')
->willReturn('/you/files/' . $fileName);

$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(IUserFolder::class);
$this->folder->expects($this->once())
->method('getUserFolder')
->with('you')
Expand Down Expand Up @@ -196,7 +196,7 @@ public function testPrepareSuccessDeletedUser(): void {
->method('getPath')
->willReturn('/you/files/' . $fileName);

$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(IUserFolder::class);
$this->folder->expects($this->once())
->method('getUserFolder')
->with('you')
Expand Down Expand Up @@ -491,7 +491,7 @@ public function testPrepareUnresolvableFileID(): void {

$displayName = 'Huraga';

$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(IUserFolder::class);
$this->folder->expects($this->once())
->method('getUserFolder')
->with('you')
Expand Down
4 changes: 0 additions & 4 deletions apps/dav/lib/Files/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
namespace OCA\DAV\Files;

use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\IUserSession;
use OCP\Server;
Expand Down Expand Up @@ -37,9 +36,6 @@ public function getChildForPrincipal(array $principalInfo) {
return new SimpleCollection($name);
}
$userFolder = Server::get(IRootFolder::class)->getUserFolder($user->getUID());
if (!($userFolder instanceof FileInfo)) {
throw new \Exception('Home does not exist');
}
return new FilesHome($principalInfo, $userFolder);
}

Expand Down
7 changes: 4 additions & 3 deletions apps/dav/tests/unit/Controller/DirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;
Expand Down Expand Up @@ -59,7 +60,7 @@ protected function setUp(): void {
}

public function testGetUrlNonExistingFileId(): void {
$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(IUserFolder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
->willReturn($userFolder);
Expand All @@ -73,7 +74,7 @@ public function testGetUrlNonExistingFileId(): void {
}

public function testGetUrlForFolder(): void {
$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(IUserFolder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
->willReturn($userFolder);
Expand All @@ -89,7 +90,7 @@ public function testGetUrlForFolder(): void {
}

public function testGetUrlValid(): void {
$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(IUserFolder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
->willReturn($userFolder);
Expand Down
6 changes: 3 additions & 3 deletions apps/dav/tests/unit/Direct/DirectFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
use OCA\DAV\Direct\DirectFile;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\Exception\Forbidden;
use Test\TestCase;

class DirectFileTest extends TestCase {
private Direct $direct;
private IRootFolder&MockObject $rootFolder;
private Folder&MockObject $userFolder;
private IUserFolder&MockObject $userFolder;
private File&MockObject $file;
private IEventDispatcher&MockObject $eventDispatcher;
private DirectFile $directFile;
Expand All @@ -37,7 +37,7 @@ protected function setUp(): void {

$this->rootFolder = $this->createMock(IRootFolder::class);

$this->userFolder = $this->createMock(Folder::class);
$this->userFolder = $this->createMock(IUserFolder::class);
$this->rootFolder->method('getUserFolder')
->with('directUser')
->willReturn($this->userFolder);
Expand Down
22 changes: 11 additions & 11 deletions apps/files/tests/Command/DeleteOrphanedFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OC\Files\View;
use OCA\Files\Command\DeleteOrphanedFiles;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection;
use OCP\IUserManager;
Expand Down Expand Up @@ -46,6 +47,13 @@ protected function setUp(): void {
}

protected function tearDown(): void {
// since we deleted the storage it might throw a (valid) StorageNotAvailableException
try {
$view = new View('/' . $this->user1 . '/files');
$view->unlink('test');
} catch (StorageNotAvailableException|NotFoundException $e) {
}

$userManager = Server::get(IUserManager::class);
$user1 = $userManager->get($this->user1);
if ($user1) {
Expand Down Expand Up @@ -87,10 +95,10 @@ public function testClearFiles(): void {

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

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

$fileInfo = $view->getFileInfo('files/test');
$fileInfo = $view->getFileInfo('test');

$storageId = $fileInfo->getStorage()->getId();
$numericStorageId = $fileInfo->getStorage()->getCache()->getNumericStorageId();
Expand Down Expand Up @@ -126,13 +134,5 @@ public function testClearFiles(): void {

$this->assertCount(0, $this->getFile($fileInfo->getId()), 'Asserts that file gets cleaned up');
$this->assertEquals(0, $this->getMountsCount($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');
} catch (StorageNotAvailableException $e) {
}
}
}
6 changes: 3 additions & 3 deletions apps/files/tests/Controller/ConversionApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\Files\Conversion\IConversionManager;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\IL10N;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -33,7 +33,7 @@ class ConversionApiControllerTest extends TestCase {
private IConversionManager&MockObject $fileConversionManager;
private IRootFolder&MockObject $rootFolder;
private File&MockObject $file;
private Folder&MockObject $userFolder;
private IUserFolder&MockObject $userFolder;
private IL10N&MockObject $l10n;
private string $user;

Expand All @@ -46,7 +46,7 @@ protected function setUp(): void {
$this->l10n = $this->createMock(IL10N::class);
$this->user = 'userid';

$this->userFolder = $this->createMock(Folder::class);
$this->userFolder = $this->createMock(IUserFolder::class);

$this->rootFolder = $this->createMock(IRootFolder::class);
$this->rootFolder->method('getUserFolder')->with($this->user)->willReturn($this->userFolder);
Expand Down
7 changes: 4 additions & 3 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\Files\Template\ITemplateManager;
use OCP\ICacheFactory;
use OCP\IConfig;
Expand Down Expand Up @@ -173,7 +174,7 @@ public function testIndexWithRegularBrowser(): void {
[$this->user->getUID(), 'files', 'show_grid', true],
]);

$baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock();
$baseFolderFiles = $this->getMockBuilder(IUserFolder::class)->getMock();

$this->rootFolder->expects($this->any())
->method('getUserFolder')
Expand Down Expand Up @@ -221,7 +222,7 @@ public function testShortRedirect(?string $openfile, ?string $opendetails, strin
->with('files')
->willReturn(true);

$baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock();
$baseFolderFiles = $this->getMockBuilder(IUserFolder::class)->getMock();
$this->rootFolder->expects($this->any())
->method('getUserFolder')
->with('testuser1')
Expand Down Expand Up @@ -256,7 +257,7 @@ public function testShowFileRouteWithTrashedFile(): void {
->method('getPath')
->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub');

$baseFolderFiles = $this->createMock(Folder::class);
$baseFolderFiles = $this->createMock(IUserFolder::class);
$baseFolderTrash = $this->createMock(Folder::class);

$this->rootFolder->expects($this->any())
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function setUp(): void {
$mount = $this->view->getMount($this->filename);
$mount->getStorage()->getScanner()->scan('', Scanner::SCAN_RECURSIVE);

$this->userFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$this->userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);

$this->appConfig = $this->createMock(IAppConfig::class);
}
Expand Down
5 changes: 3 additions & 2 deletions apps/files_sharing/tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
use OCP\IUserSession;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function testCheckDirectCanBeDownloaded(
$file = $this->createMock(File::class);
$file->method('getStorage')->willReturn($fileStorage);

$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(IUserFolder::class);
$userFolder->method('get')->willReturn($file);

$user = $this->createMock(IUser::class);
Expand Down Expand Up @@ -166,7 +167,7 @@ function (string $fileStorage) use ($nonSharedStorage, $secureSharedStorage) {
$rootFolder->method('getStorage')->willReturn($nonSharedStorage);
$rootFolder->method('getDirectoryListing')->willReturn([$folder]);

$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(IUserFolder::class);
$userFolder->method('get')->willReturn($rootFolder);

$user = $this->createMock(IUser::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace OCA\Files_Sharing\Tests\Collaboration;

use OCA\Files_Sharing\Collaboration\ShareRecipientSorter;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\Files\Node;
use OCP\IUser;
use OCP\IUserSession;
Expand Down Expand Up @@ -42,8 +42,7 @@ protected function setUp(): void {
public function testSort($data): void {
$node = $this->createMock(Node::class);

/** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */
$folder = $this->createMock(Folder::class);
$folder = $this->createMock(IUserFolder::class);
$this->rootFolder->expects($this->any())
->method('getUserFolder')
->willReturn($folder);
Expand Down Expand Up @@ -81,8 +80,7 @@ public function testSort($data): void {
}

public function testSortNoNodes(): void {
/** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */
$folder = $this->createMock(Folder::class);
$folder = $this->createMock(IUserFolder::class);
$this->rootFolder->expects($this->any())
->method('getUserFolder')
->willReturn($folder);
Expand Down
Loading
Loading