summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMichael Weimann <mail@michael-weimann.eu>2018-10-03 00:06:12 +0200
committerMorris Jobke <hey@morrisjobke.de>2018-11-07 10:19:19 +0100
commit16f379b9741a2ce9ca0ac3ea0f71a8fc98ce0890 (patch)
treea0bdae74aa8296545f4cd26960cdd14796f03423 /apps
parentc26d847d19c967aa5bc99f9bc15c27c7e95ee55f (diff)
downloadnextcloud-server-16f379b9741a2ce9ca0ac3ea0f71a8fc98ce0890.tar.gz
nextcloud-server-16f379b9741a2ce9ca0ac3ea0f71a8fc98ce0890.zip
Hides the header actions for file drops
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/Controller/ShareController.php1
-rw-r--r--apps/files_sharing/tests/Controller/ShareControllerTest.php103
2 files changed, 100 insertions, 4 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php
index 9a8e1298f93..89e619c844f 100644
--- a/apps/files_sharing/lib/Controller/ShareController.php
+++ b/apps/files_sharing/lib/Controller/ShareController.php
@@ -61,7 +61,6 @@ use OCA\Files_Sharing\Activity\Providers\Downloads;
use OCP\Files\NotFoundException;
use OCP\Files\IRootFolder;
use OCP\Share\Exceptions\ShareNotFound;
-use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use OCP\Share\IManager as ShareManager;
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php
index 564977c09bc..8d7064c031b 100644
--- a/apps/files_sharing/tests/Controller/ShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php
@@ -32,6 +32,7 @@
namespace OCA\Files_Sharing\Tests\Controllers;
use OC\Files\Filesystem;
+use OC\Files\Node\Folder;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Sharing\Controller\ShareController;
use OCP\AppFramework\Http\DataResponse;
@@ -39,7 +40,9 @@ use OCP\AppFramework\Http\Template\ExternalShareMenuAction;
use OCP\AppFramework\Http\Template\LinkMenuAction;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\Template\SimpleMenuAction;
+use OCP\Constants;
use OCP\Files\NotFoundException;
+use OCP\Files\Storage;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
@@ -47,14 +50,12 @@ use OCP\IPreview;
use OCP\IRequest;
use OCP\IUser;
use OCP\Share\Exceptions\ShareNotFound;
-use OCP\AppFramework\Http\NotFoundResponse;
-use OCP\AppFramework\Http\RedirectResponse;
-use OCP\AppFramework\Http\TemplateResponse;
use OCP\ISession;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use OCP\IURLGenerator;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
@@ -424,6 +425,102 @@ class ShareControllerTest extends \Test\TestCase {
}
/**
+ * Checks file drop shares:
+ * - there must not be any header action
+ * - the template param "hideFileList" should be true
+ *
+ * @test
+ * @return void
+ */
+ public function testShareFileDrop() {
+ $this->shareController->setToken('token');
+
+ $owner = $this->getMockBuilder(IUser::class)->getMock();
+ $owner->method('getDisplayName')->willReturn('ownerDisplay');
+ $owner->method('getUID')->willReturn('ownerUID');
+
+ /* @var MockObject|Storage $storage */
+ $storage = $this->getMockBuilder(Storage::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ /* @var MockObject|Folder $folder */
+ $folder = $this->getMockBuilder(Folder::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $folder->method('getName')->willReturn('/fileDrop');
+ $folder->method('isReadable')->willReturn(true);
+ $folder->method('isShareable')->willReturn(true);
+ $folder->method('getStorage')->willReturn($storage);
+ $folder->method('get')->with('')->willReturn($folder);
+ $folder->method('getSize')->willReturn(1337);
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setId(42);
+ $share->setPermissions(Constants::PERMISSION_CREATE)
+ ->setShareOwner('ownerUID')
+ ->setNode($folder)
+ ->setTarget('/fileDrop');
+
+ $this->shareManager
+ ->expects($this->once())
+ ->method('getShareByToken')
+ ->with('token')
+ ->willReturn($share);
+
+ $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
+
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function($text, $parameters) {
+ return vsprintf($text, $parameters);
+ }));
+
+ $response = $this->shareController->showShare();
+ // skip the "folder" param for tests
+ $responseParams = $response->getParams();
+ unset($responseParams['folder']);
+ $response->setParams($responseParams);
+
+ $sharedTmplParams = array(
+ 'displayName' => 'ownerDisplay',
+ 'owner' => 'ownerUID',
+ 'filename' => '/fileDrop',
+ 'directory_path' => '/fileDrop',
+ 'mimetype' => null,
+ 'dirToken' => 'token',
+ 'sharingToken' => 'token',
+ 'server2serversharing' => true,
+ 'protected' => 'false',
+ 'dir' => null,
+ 'downloadURL' => '',
+ 'fileSize' => '1 KB',
+ 'nonHumanFileSize' => 1337,
+ 'maxSizeAnimateGif' => null,
+ 'previewSupported' => null,
+ 'previewEnabled' => null,
+ 'previewMaxX' => null,
+ 'previewMaxY' => null,
+ 'hideFileList' => true,
+ 'shareOwner' => 'ownerDisplay',
+ 'disclaimer' => null,
+ 'shareUrl' => '',
+ 'previewImage' => '',
+ 'previewURL' => '',
+ 'note' => ''
+ );
+
+ $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
+ $csp->addAllowedFrameDomain('\'self\'');
+ $expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams);
+ $expectedResponse->setContentSecurityPolicy($csp);
+ $expectedResponse->setHeaderTitle($sharedTmplParams['filename']);
+ $expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']);
+
+ self::assertEquals($expectedResponse, $response);
+ }
+
+ /**
* @expectedException \OCP\Files\NotFoundException
*/
public function testShowShareInvalid() {