Hides the header actions for file drops

Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
This commit is contained in:
Michael Weimann 2018-10-03 00:06:12 +02:00 committed by Morris Jobke
parent c26d847d19
commit 16f379b974
No known key found for this signature in database
GPG key ID: FE03C3A163FEDE68
2 changed files with 100 additions and 4 deletions

View file

@ -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;

View file

@ -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;
/**
@ -423,6 +424,102 @@ class ShareControllerTest extends \Test\TestCase {
$this->assertEquals($expectedResponse, $response);
}
/**
* 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
*/