summaryrefslogtreecommitdiffstats
path: root/apps/files/tests
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-08-17 08:55:30 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-08-17 18:58:20 +0200
commit1b67542e0b20d548963087d208c3ee1633e1a5a2 (patch)
tree73315eb9b14686e9669fb630174e6bfd07f71b2e /apps/files/tests
parent6da9813ced7a5118c68984eb4355e49d045161dd (diff)
downloadnextcloud-server-1b67542e0b20d548963087d208c3ee1633e1a5a2.tar.gz
nextcloud-server-1b67542e0b20d548963087d208c3ee1633e1a5a2.zip
fix(files): trashbin redirect and default fileid Sidebar open
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files/tests')
-rw-r--r--apps/files/tests/Controller/ViewControllerTest.php169
1 files changed, 13 insertions, 156 deletions
diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php
index d9ccaf47eed..b997bbcad65 100644
--- a/apps/files/tests/Controller/ViewControllerTest.php
+++ b/apps/files/tests/Controller/ViewControllerTest.php
@@ -163,74 +163,28 @@ class ViewControllerTest extends TestCase {
[$this->user->getUID(), 'files', 'crop_image_previews', true, true],
[$this->user->getUID(), 'files', 'show_grid', true],
]);
+
+ $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock();
+
+ $this->rootFolder->expects($this->any())
+ ->method('getUserFolder')
+ ->with('testuser1')
+ ->willReturn($baseFolderFiles);
$this->config
->expects($this->any())
->method('getAppValue')
->willReturnArgument(2);
- $this->shareManager->method('shareApiAllowLinks')
- ->willReturn(true);
-
- $nav = new Template('files', 'appnavigation');
- $nav->assign('navigationItems', [
- 'files' => [
- 'id' => 'files',
- 'appname' => 'files',
- 'script' => 'list.php',
- 'order' => 0,
- 'name' => \OC::$server->getL10N('files')->t('All files'),
- 'active' => false,
- 'icon' => '',
- 'type' => 'link',
- 'classes' => '',
- 'expanded' => false,
- 'unread' => 0,
- ],
- 'systemtagsfilter' => [
- 'id' => 'systemtagsfilter',
- 'appname' => 'systemtags',
- 'script' => 'list.php',
- 'order' => 25,
- 'name' => \OC::$server->getL10N('systemtags')->t('Tags'),
- 'active' => false,
- 'icon' => '',
- 'type' => 'link',
- 'classes' => '',
- 'expanded' => false,
- 'unread' => 0,
- ],
- ]);
$expected = new Http\TemplateResponse(
'files',
'index',
[
- 'usedSpacePercent' => 123,
- 'owner' => 'MyName',
- 'ownerDisplayName' => 'MyDisplayName',
- 'isPublic' => false,
- 'defaultFileSorting' => 'basename',
- 'defaultFileSortingDirection' => 'asc',
- 'showHiddenFiles' => 0,
- 'cropImagePreviews' => 1,
'fileNotFound' => 0,
- 'allowShareWithLink' => 'yes',
- 'appNavigation' => $nav,
- 'appContents' => [
- 'files' => [
- 'id' => 'files',
- 'content' => null,
- ],
- 'systemtagsfilter' => [
- 'id' => 'systemtagsfilter',
- 'content' => null,
- ],
- ],
- 'hiddenFields' => [],
- 'showgridview' => null
]
);
$policy = new Http\ContentSecurityPolicy();
+ $policy->addAllowedWorkerSrcDomain('\'self\'');
$policy->addAllowedFrameDomain('\'self\'');
$expected->setContentSecurityPolicy($policy);
@@ -249,100 +203,6 @@ class ViewControllerTest extends TestCase {
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
}
- public function testShowFileRouteWithFolder() {
- $node = $this->getMockBuilder(Folder::class)->getMock();
- $node->expects($this->once())
- ->method('getPath')
- ->willReturn('/testuser1/files/test/sub');
-
- $baseFolder = $this->getMockBuilder(Folder::class)->getMock();
-
- $this->rootFolder->expects($this->once())
- ->method('getUserFolder')
- ->with('testuser1')
- ->willReturn($baseFolder);
-
- $baseFolder->expects($this->once())
- ->method('getById')
- ->with(123)
- ->willReturn([$node]);
- $baseFolder->expects($this->once())
- ->method('getRelativePath')
- ->with('/testuser1/files/test/sub')
- ->willReturn('/test/sub');
-
- $this->urlGenerator
- ->expects($this->once())
- ->method('linkToRoute')
- ->with('files.view.index', ['dir' => '/test/sub'])
- ->willReturn('/apps/files/?dir=/test/sub');
-
- $expected = new Http\RedirectResponse('/apps/files/?dir=/test/sub');
- $this->assertEquals($expected, $this->viewController->index('', '', '123'));
- }
-
- public function testShowFileRouteWithFile() {
- $parentNode = $this->getMockBuilder(Folder::class)->getMock();
- $parentNode->expects($this->once())
- ->method('getPath')
- ->willReturn('testuser1/files/test');
-
- $baseFolder = $this->getMockBuilder(Folder::class)->getMock();
-
- $this->rootFolder->expects($this->once())
- ->method('getUserFolder')
- ->with('testuser1')
- ->willReturn($baseFolder);
-
- $node = $this->getMockBuilder(File::class)->getMock();
- $node->expects($this->once())
- ->method('getParent')
- ->willReturn($parentNode);
- $node->expects($this->once())
- ->method('getName')
- ->willReturn('somefile.txt');
-
- $baseFolder->expects($this->once())
- ->method('getById')
- ->with(123)
- ->willReturn([$node]);
- $baseFolder->expects($this->once())
- ->method('getRelativePath')
- ->with('testuser1/files/test')
- ->willReturn('/test');
-
- $this->urlGenerator
- ->expects($this->once())
- ->method('linkToRoute')
- ->with('files.view.index', ['dir' => '/test', 'scrollto' => 'somefile.txt'])
- ->willReturn('/apps/files/?dir=/test/sub&scrollto=somefile.txt');
-
- $expected = new Http\RedirectResponse('/apps/files/?dir=/test/sub&scrollto=somefile.txt');
- $this->assertEquals($expected, $this->viewController->index('', '', '123'));
- }
-
- public function testShowFileRouteWithInvalidFileId() {
- $baseFolder = $this->getMockBuilder(Folder::class)->getMock();
- $this->rootFolder->expects($this->once())
- ->method('getUserFolder')
- ->with('testuser1')
- ->willReturn($baseFolder);
-
- $baseFolder->expects($this->once())
- ->method('getById')
- ->with(123)
- ->willReturn([]);
-
- $this->urlGenerator->expects($this->once())
- ->method('linkToRoute')
- ->with('files.view.index', ['fileNotFound' => true])
- ->willReturn('redirect.url');
-
- $response = $this->viewController->index('', 'MyView', '123');
- $this->assertInstanceOf('OCP\AppFramework\Http\RedirectResponse', $response);
- $this->assertEquals('redirect.url', $response->getRedirectURL());
- }
-
public function testShowFileRouteWithTrashedFile() {
$this->appManager->expects($this->once())
->method('isEnabledForUser')
@@ -357,7 +217,7 @@ class ViewControllerTest extends TestCase {
$baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock();
$baseFolderTrash = $this->getMockBuilder(Folder::class)->getMock();
- $this->rootFolder->expects($this->once())
+ $this->rootFolder->expects($this->any())
->method('getUserFolder')
->with('testuser1')
->willReturn($baseFolderFiles);
@@ -366,7 +226,7 @@ class ViewControllerTest extends TestCase {
->with('testuser1/files_trashbin/files/')
->willReturn($baseFolderTrash);
- $baseFolderFiles->expects($this->once())
+ $baseFolderFiles->expects($this->any())
->method('getById')
->with(123)
->willReturn([]);
@@ -375,9 +235,6 @@ class ViewControllerTest extends TestCase {
$node->expects($this->once())
->method('getParent')
->willReturn($parentNode);
- $node->expects($this->once())
- ->method('getName')
- ->willReturn('somefile.txt');
$baseFolderTrash->expects($this->once())
->method('getById')
@@ -391,10 +248,10 @@ class ViewControllerTest extends TestCase {
$this->urlGenerator
->expects($this->once())
->method('linkToRoute')
- ->with('files.view.index', ['view' => 'trashbin', 'dir' => '/test.d1462861890/sub', 'scrollto' => 'somefile.txt'])
- ->willReturn('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt');
+ ->with('files.view.indexViewFileid', ['view' => 'trashbin', 'dir' => '/test.d1462861890/sub', 'fileid' => '123'])
+ ->willReturn('/apps/files/trashbin/123?dir=/test.d1462861890/sub');
- $expected = new Http\RedirectResponse('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt');
+ $expected = new Http\RedirectResponse('/apps/files/trashbin/123?dir=/test.d1462861890/sub');
$this->assertEquals($expected, $this->viewController->index('', '', '123'));
}
}