Fix files_sharing tests

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-02-09 11:34:34 +01:00 committed by Roeland Jago Douma
parent 038aad73c7
commit 4a1cbefc90
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 31 additions and 5 deletions

View File

@ -441,7 +441,7 @@ class ShareController extends Controller {
$csp->addAllowedFrameDomain('\'self\'');
$response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl);
$response->setHeaderTitle($share->getNode()->getName());
$response->setHeaderTitle($shareTmpl['filename']);
$response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']]));
$response->setHeaderActions([
new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $shareTmpl['downloadURL'], 0),

View File

@ -34,7 +34,11 @@ namespace OCA\Files_Sharing\Tests\Controllers;
use OC\Files\Filesystem;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Sharing\Controller\ShareController;
use OCA\Files_Sharing\Template\ExternalShareMenuAction;
use OCA\Files_Sharing\Template\LinkMenuAction;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\Template\SimpleMenuAction;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
@ -84,6 +88,8 @@ class ShareControllerTest extends \Test\TestCase {
private $federatedShareProvider;
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
private $eventDispatcher;
/** @var IL10N */
private $l10n;
protected function setUp() {
parent::setUp();
@ -102,6 +108,7 @@ class ShareControllerTest extends \Test\TestCase {
$this->federatedShareProvider->expects($this->any())
->method('isIncomingServer2serverShareEnabled')->willReturn(true);
$this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$this->l10n = $this->createMock(IL10N::class);
$this->shareController = new \OCA\Files_Sharing\Controller\ShareController(
$this->appName,
@ -117,7 +124,7 @@ class ShareControllerTest extends \Test\TestCase {
$this->getMockBuilder('\OCP\Files\IRootFolder')->getMock(),
$this->federatedShareProvider,
$this->eventDispatcher,
$this->getMockBuilder(IL10N::class)->getMock(),
$this->l10n,
$this->getMockBuilder('\OCP\Defaults')->getMock()
);
@ -348,6 +355,11 @@ class ShareControllerTest extends \Test\TestCase {
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
$this->urlGenerator->expects($this->at(0))
->method('linkToRouteAbsolute')
->with('files_sharing.sharecontroller.downloadShare', ['token' => 'token'])
->willReturn('downloadURL');
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
$this->config->method('getSystemValue')
@ -379,6 +391,12 @@ class ShareControllerTest extends \Test\TestCase {
->method('dispatch')
->with('OCA\Files_Sharing::loadAdditionalScripts');
$this->l10n->expects($this->any())
->method('t')
->will($this->returnCallback(function($text, $parameters) {
return vsprintf($text, $parameters);
}));
$response = $this->shareController->showShare('token');
$sharedTmplParams = array(
'displayName' => 'ownerDisplay',
@ -391,7 +409,7 @@ class ShareControllerTest extends \Test\TestCase {
'server2serversharing' => true,
'protected' => 'true',
'dir' => '',
'downloadURL' => null,
'downloadURL' => 'downloadURL',
'fileSize' => '33 B',
'nonHumanFileSize' => 33,
'maxSizeAnimateGif' => 10,
@ -404,13 +422,21 @@ class ShareControllerTest extends \Test\TestCase {
'disclaimer' => 'My disclaimer text',
'shareUrl' => null,
'previewImage' => null,
'previewURL' => null,
'previewURL' => 'downloadURL',
);
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
$expectedResponse = new TemplateResponse($this->appName, 'public', $sharedTmplParams, 'base');
$expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams);
$expectedResponse->setContentSecurityPolicy($csp);
$expectedResponse->setHeaderTitle($sharedTmplParams['filename']);
$expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']);
$expectedResponse->setHeaderActions([
new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $sharedTmplParams['downloadURL'], 0),
new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $sharedTmplParams['downloadURL'], 10, $sharedTmplParams['fileSize']),
new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $sharedTmplParams['previewURL']),
new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $sharedTmplParams['owner'], $sharedTmplParams['displayName'], $sharedTmplParams['filename']),
]);
$this->assertEquals($expectedResponse, $response);
}