2015-11-16 22:57:41 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-03-01 19:25:15 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-11-16 22:57:41 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files\Tests\Controller;
|
|
|
|
|
2018-07-12 15:30:39 +03:00
|
|
|
use OCA\Files\Activity\Helper;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCA\Files\Controller\ViewController;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\App\IAppManager;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\AppFramework\Http;
|
2019-08-02 21:08:54 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\Files\File;
|
|
|
|
use OCP\Files\Folder;
|
2016-08-19 09:15:30 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IURLGenerator;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IUser;
|
2016-04-12 12:51:50 +03:00
|
|
|
use OCP\IUserSession;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Template;
|
2015-11-16 22:57:41 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2019-11-22 22:52:10 +03:00
|
|
|
use Test\TestCase;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ViewControllerTest
|
|
|
|
*
|
|
|
|
* @package OCA\Files\Tests\Controller
|
|
|
|
*/
|
|
|
|
class ViewControllerTest extends TestCase {
|
2016-08-19 09:15:30 +03:00
|
|
|
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
2015-11-16 22:57:41 +03:00
|
|
|
private $request;
|
2016-08-19 09:15:30 +03:00
|
|
|
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
2015-11-16 22:57:41 +03:00
|
|
|
private $urlGenerator;
|
|
|
|
/** @var IL10N */
|
|
|
|
private $l10n;
|
2016-08-19 09:15:30 +03:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2015-11-16 22:57:41 +03:00
|
|
|
private $config;
|
|
|
|
/** @var EventDispatcherInterface */
|
|
|
|
private $eventDispatcher;
|
2016-08-19 09:15:30 +03:00
|
|
|
/** @var ViewController|\PHPUnit_Framework_MockObject_MockObject */
|
2015-11-16 22:57:41 +03:00
|
|
|
private $viewController;
|
2016-04-12 12:51:50 +03:00
|
|
|
/** @var IUser */
|
|
|
|
private $user;
|
|
|
|
/** @var IUserSession */
|
|
|
|
private $userSession;
|
2016-08-19 09:15:30 +03:00
|
|
|
/** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-05-11 20:41:36 +03:00
|
|
|
private $appManager;
|
2016-08-19 09:15:30 +03:00
|
|
|
/** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */
|
2016-05-11 20:41:36 +03:00
|
|
|
private $rootFolder;
|
2018-07-12 15:30:39 +03:00
|
|
|
/** @var Helper|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $activityHelper;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2015-11-16 22:57:41 +03:00
|
|
|
parent::setUp();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->request = $this->getMockBuilder(IRequest::class)->getMock();
|
|
|
|
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
|
|
|
|
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
|
|
|
|
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
|
2019-08-02 21:08:54 +03:00
|
|
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->userSession = $this->getMockBuilder(IUserSession::class)->getMock();
|
2016-08-16 21:58:33 +03:00
|
|
|
$this->appManager = $this->getMockBuilder('\OCP\App\IAppManager')->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->user = $this->getMockBuilder(IUser::class)->getMock();
|
2016-05-11 20:41:36 +03:00
|
|
|
$this->user->expects($this->any())
|
|
|
|
->method('getUID')
|
|
|
|
->will($this->returnValue('testuser1'));
|
2016-04-12 12:51:50 +03:00
|
|
|
$this->userSession->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->will($this->returnValue($this->user));
|
2016-08-19 09:15:30 +03:00
|
|
|
$this->rootFolder = $this->getMockBuilder('\OCP\Files\IRootFolder')->getMock();
|
2018-07-12 15:30:39 +03:00
|
|
|
$this->activityHelper = $this->createMock(Helper::class);
|
2015-11-16 22:57:41 +03:00
|
|
|
$this->viewController = $this->getMockBuilder('\OCA\Files\Controller\ViewController')
|
|
|
|
->setConstructorArgs([
|
|
|
|
'files',
|
|
|
|
$this->request,
|
|
|
|
$this->urlGenerator,
|
|
|
|
$this->l10n,
|
|
|
|
$this->config,
|
2016-04-12 12:51:50 +03:00
|
|
|
$this->eventDispatcher,
|
2016-05-04 11:28:06 +03:00
|
|
|
$this->userSession,
|
2016-05-11 20:41:36 +03:00
|
|
|
$this->appManager,
|
2018-07-12 15:30:39 +03:00
|
|
|
$this->rootFolder,
|
|
|
|
$this->activityHelper,
|
2015-11-16 22:57:41 +03:00
|
|
|
])
|
|
|
|
->setMethods([
|
|
|
|
'getStorageInfo',
|
|
|
|
'renderScript'
|
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexWithRegularBrowser() {
|
|
|
|
$this->viewController
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getStorageInfo')
|
|
|
|
->will($this->returnValue([
|
2017-06-12 11:32:25 +03:00
|
|
|
'used' => 123,
|
|
|
|
'quota' => 100,
|
|
|
|
'total' => 100,
|
2015-11-16 22:57:41 +03:00
|
|
|
'relative' => 123,
|
|
|
|
'owner' => 'MyName',
|
|
|
|
'ownerDisplayName' => 'MyDisplayName',
|
|
|
|
]));
|
2018-07-12 15:30:39 +03:00
|
|
|
$this->config
|
2016-04-12 12:51:50 +03:00
|
|
|
->method('getUserValue')
|
|
|
|
->will($this->returnValueMap([
|
|
|
|
[$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'],
|
2016-04-12 18:10:09 +03:00
|
|
|
[$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc'],
|
|
|
|
[$this->user->getUID(), 'files', 'show_hidden', false, false],
|
2018-11-15 22:29:10 +03:00
|
|
|
[$this->user->getUID(), 'files', 'show_grid', true],
|
2016-04-12 12:51:50 +03:00
|
|
|
]));
|
2015-11-16 22:57:41 +03:00
|
|
|
|
2018-11-06 17:52:49 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getAppValue')
|
|
|
|
->will($this->returnArgument(2));
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
$nav = new Template('files', 'appnavigation');
|
2017-06-12 11:32:25 +03:00
|
|
|
$nav->assign('usage_relative', 123);
|
2019-07-02 20:49:55 +03:00
|
|
|
$nav->assign('usage', '123 B');
|
2017-06-12 11:32:25 +03:00
|
|
|
$nav->assign('quota', 100);
|
|
|
|
$nav->assign('total_space', '100 B');
|
2018-07-12 15:30:39 +03:00
|
|
|
//$nav->assign('webdavurl', '');
|
2015-11-16 22:57:41 +03:00
|
|
|
$nav->assign('navigationItems', [
|
2018-07-13 15:47:00 +03:00
|
|
|
'files' => [
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'files',
|
|
|
|
'appname' => 'files',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 0,
|
2016-10-28 23:08:32 +03:00
|
|
|
'name' => \OC::$server->getL10N('files')->t('All files'),
|
2016-07-11 13:58:43 +03:00
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
2017-03-26 22:26:45 +03:00
|
|
|
'type' => 'link',
|
2017-09-21 19:23:36 +03:00
|
|
|
'classes' => '',
|
2016-07-11 13:58:43 +03:00
|
|
|
],
|
2018-07-13 15:47:00 +03:00
|
|
|
'recent' => [
|
2016-07-11 13:58:43 +03:00
|
|
|
'id' => 'recent',
|
|
|
|
'appname' => 'files',
|
2016-07-25 11:41:53 +03:00
|
|
|
'script' => 'recentlist.php',
|
2016-07-11 13:58:43 +03:00
|
|
|
'order' => 2,
|
2016-10-28 23:08:32 +03:00
|
|
|
'name' => \OC::$server->getL10N('files')->t('Recent'),
|
2015-11-16 22:57:41 +03:00
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
2017-03-26 22:26:45 +03:00
|
|
|
'type' => 'link',
|
2017-09-21 19:23:36 +03:00
|
|
|
'classes' => '',
|
2015-11-16 22:57:41 +03:00
|
|
|
],
|
2018-07-13 15:47:00 +03:00
|
|
|
'favorites' => [
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'favorites',
|
|
|
|
'appname' => 'files',
|
|
|
|
'script' => 'simplelist.php',
|
|
|
|
'order' => 5,
|
2018-07-13 15:47:00 +03:00
|
|
|
'name' => \OC::$server->getL10N('files')->t('Favorites'),
|
2015-11-16 22:57:41 +03:00
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
2017-03-26 22:26:45 +03:00
|
|
|
'type' => 'link',
|
2018-09-14 23:06:56 +03:00
|
|
|
'classes' => 'collapsible',
|
|
|
|
'sublist' => [
|
|
|
|
[
|
|
|
|
'id' => '-test1',
|
|
|
|
'view' => 'files',
|
|
|
|
'href' => '',
|
|
|
|
'dir' => '/test1',
|
|
|
|
'order' => 6,
|
|
|
|
'folderPosition' => 1,
|
|
|
|
'name' => 'test1',
|
|
|
|
'icon' => 'files',
|
|
|
|
'quickaccesselement' => 'true',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'test2',
|
|
|
|
'id' => '-test2-',
|
|
|
|
'view' => 'files',
|
|
|
|
'href' => '',
|
|
|
|
'dir' => '/test2/',
|
|
|
|
'order' => 7,
|
|
|
|
'folderPosition' => 2,
|
|
|
|
'icon' => 'files',
|
|
|
|
'quickaccesselement' => 'true',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'sub4',
|
|
|
|
'id' => '-test3-sub4',
|
|
|
|
'view' => 'files',
|
|
|
|
'href' => '',
|
|
|
|
'dir' => '/test3/sub4',
|
|
|
|
'order' => 8,
|
|
|
|
'folderPosition' => 3,
|
|
|
|
'icon' => 'files',
|
|
|
|
'quickaccesselement' => 'true',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'sub6',
|
|
|
|
'id' => '-test5-sub6-',
|
|
|
|
'view' => 'files',
|
|
|
|
'href' => '',
|
|
|
|
'dir' => '/test5/sub6/',
|
|
|
|
'order' => 9,
|
|
|
|
'folderPosition' => 4,
|
|
|
|
'icon' => 'files',
|
|
|
|
'quickaccesselement' => 'true',
|
|
|
|
],
|
|
|
|
],
|
2018-07-12 15:30:39 +03:00
|
|
|
'defaultExpandedState' => false,
|
2018-07-13 15:47:00 +03:00
|
|
|
'expandedState' => 'show_Quick_Access'
|
2015-11-16 22:57:41 +03:00
|
|
|
],
|
2018-07-13 15:47:00 +03:00
|
|
|
'systemtagsfilter' => [
|
2016-02-26 11:52:29 +03:00
|
|
|
'id' => 'systemtagsfilter',
|
|
|
|
'appname' => 'systemtags',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 25,
|
2016-10-28 23:08:32 +03:00
|
|
|
'name' => \OC::$server->getL10N('systemtags')->t('Tags'),
|
2016-02-26 11:52:29 +03:00
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
2017-03-26 22:26:45 +03:00
|
|
|
'type' => 'link',
|
2017-09-21 19:23:36 +03:00
|
|
|
'classes' => '',
|
2016-02-26 11:52:29 +03:00
|
|
|
],
|
2018-07-13 15:47:00 +03:00
|
|
|
'trashbin' => [
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'trashbin',
|
|
|
|
'appname' => 'files_trashbin',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 50,
|
2016-10-28 23:08:32 +03:00
|
|
|
'name' => \OC::$server->getL10N('files_trashbin')->t('Deleted files'),
|
2015-11-16 22:57:41 +03:00
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
2017-03-26 22:26:45 +03:00
|
|
|
'type' => 'link',
|
2017-09-18 11:44:37 +03:00
|
|
|
'classes' => 'pinned',
|
2017-03-26 22:26:45 +03:00
|
|
|
],
|
2018-07-24 11:59:03 +03:00
|
|
|
'shareoverview' => [
|
|
|
|
'id' => 'shareoverview',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 18,
|
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Shares'),
|
|
|
|
'classes' => 'collapsible',
|
|
|
|
'sublist' => [
|
|
|
|
[
|
|
|
|
'id' => 'sharingout',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 16,
|
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Shared with others'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 'sharingin',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 15,
|
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Shared with you'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 'sharinglinks',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 17,
|
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Shared by link', []),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 'deletedshares',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 19,
|
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Deleted shares'),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
'type' => 'link',
|
|
|
|
'expandedState' => 'show_sharing_menu',
|
|
|
|
'defaultExpandedState' => false,
|
|
|
|
]
|
2015-11-16 22:57:41 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$expected = new Http\TemplateResponse(
|
|
|
|
'files',
|
|
|
|
'index',
|
|
|
|
[
|
|
|
|
'usedSpacePercent' => 123,
|
|
|
|
'owner' => 'MyName',
|
|
|
|
'ownerDisplayName' => 'MyDisplayName',
|
|
|
|
'isPublic' => false,
|
2016-04-12 12:51:50 +03:00
|
|
|
'defaultFileSorting' => 'name',
|
|
|
|
'defaultFileSortingDirection' => 'asc',
|
2016-06-07 14:51:16 +03:00
|
|
|
'showHiddenFiles' => 0,
|
|
|
|
'fileNotFound' => 0,
|
2015-11-16 22:57:41 +03:00
|
|
|
'allowShareWithLink' => 'yes',
|
|
|
|
'appNavigation' => $nav,
|
|
|
|
'appContents' => [
|
2018-07-13 15:47:00 +03:00
|
|
|
'files' => [
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'files',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2018-07-13 15:47:00 +03:00
|
|
|
'recent' => [
|
2016-07-11 13:58:43 +03:00
|
|
|
'id' => 'recent',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2018-07-13 15:47:00 +03:00
|
|
|
'favorites' => [
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'favorites',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2018-07-13 15:47:00 +03:00
|
|
|
'systemtagsfilter' => [
|
2016-02-26 11:52:29 +03:00
|
|
|
'id' => 'systemtagsfilter',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2018-07-13 15:47:00 +03:00
|
|
|
'trashbin' => [
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'trashbin',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2018-07-24 11:59:03 +03:00
|
|
|
'sharingout' => [
|
|
|
|
'id' => 'sharingout',
|
|
|
|
'content' => null,
|
|
|
|
],
|
|
|
|
'sharingin' => [
|
|
|
|
'id' => 'sharingin',
|
|
|
|
'content' => null,
|
|
|
|
],
|
|
|
|
'sharinglinks' => [
|
|
|
|
'id' => 'sharinglinks',
|
|
|
|
'content' => null,
|
|
|
|
],
|
|
|
|
'deletedshares' => [
|
|
|
|
'id' => 'deletedshares',
|
|
|
|
'content' => null,
|
|
|
|
],
|
|
|
|
'shareoverview' => [
|
|
|
|
'id' => 'shareoverview',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2018-09-14 23:06:56 +03:00
|
|
|
'-test1' => [
|
|
|
|
'id' => '-test1',
|
|
|
|
'content' => '',
|
|
|
|
],
|
|
|
|
'-test2-' => [
|
|
|
|
'id' => '-test2-',
|
|
|
|
'content' => '',
|
|
|
|
],
|
|
|
|
'-test3-sub4' => [
|
|
|
|
'id' => '-test3-sub4',
|
|
|
|
'content' => '',
|
|
|
|
],
|
|
|
|
'-test5-sub6-' => [
|
|
|
|
'id' => '-test5-sub6-',
|
|
|
|
'content' => '',
|
|
|
|
],
|
2015-11-16 22:57:41 +03:00
|
|
|
],
|
2017-06-12 11:32:25 +03:00
|
|
|
'hiddenFields' => [],
|
2018-11-15 22:29:10 +03:00
|
|
|
'showgridview' => false,
|
2018-11-06 17:52:49 +03:00
|
|
|
'isIE' => false,
|
2015-11-16 22:57:41 +03:00
|
|
|
]
|
|
|
|
);
|
2015-12-02 19:30:40 +03:00
|
|
|
$policy = new Http\ContentSecurityPolicy();
|
|
|
|
$policy->addAllowedFrameDomain('\'self\'');
|
|
|
|
$expected->setContentSecurityPolicy($policy);
|
2018-07-12 15:30:39 +03:00
|
|
|
|
|
|
|
$this->activityHelper->method('getFavoriteFilePaths')
|
|
|
|
->with($this->user->getUID())
|
|
|
|
->willReturn([
|
|
|
|
'item' => [],
|
2018-09-14 23:06:56 +03:00
|
|
|
'folders' => [
|
|
|
|
'/test1',
|
|
|
|
'/test2/',
|
|
|
|
'/test3/sub4',
|
|
|
|
'/test5/sub6/',
|
|
|
|
],
|
2018-07-12 15:30:39 +03:00
|
|
|
]);
|
|
|
|
|
2015-11-16 22:57:41 +03:00
|
|
|
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
|
|
|
|
}
|
2016-05-04 11:28:06 +03:00
|
|
|
|
2016-08-19 09:15:30 +03:00
|
|
|
public function testShowFileRouteWithFolder() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$node = $this->getMockBuilder(Folder::class)->getMock();
|
2016-05-04 11:28:06 +03:00
|
|
|
$node->expects($this->once())
|
|
|
|
->method('getPath')
|
2016-05-11 20:41:36 +03:00
|
|
|
->will($this->returnValue('/testuser1/files/test/sub'));
|
2016-05-04 11:28:06 +03:00
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$baseFolder = $this->getMockBuilder(Folder::class)->getMock();
|
2016-05-11 20:41:36 +03:00
|
|
|
|
|
|
|
$this->rootFolder->expects($this->once())
|
2016-08-19 09:15:30 +03:00
|
|
|
->method('getUserFolder')
|
|
|
|
->with('testuser1')
|
2016-05-11 20:41:36 +03:00
|
|
|
->will($this->returnValue($baseFolder));
|
|
|
|
|
|
|
|
$baseFolder->expects($this->at(0))
|
2016-05-04 11:28:06 +03:00
|
|
|
->method('getById')
|
|
|
|
->with(123)
|
|
|
|
->will($this->returnValue([$node]));
|
2016-05-11 20:41:36 +03:00
|
|
|
$baseFolder->expects($this->at(1))
|
2016-05-04 11:28:06 +03:00
|
|
|
->method('getRelativePath')
|
2016-05-11 20:41:36 +03:00
|
|
|
->with('/testuser1/files/test/sub')
|
2016-05-04 11:28:06 +03:00
|
|
|
->will($this->returnValue('/test/sub'));
|
|
|
|
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('files.view.index', ['dir' => '/test/sub'])
|
|
|
|
->will($this->returnValue('/apps/files/?dir=/test/sub'));
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('/apps/files/?dir=/test/sub');
|
2016-08-19 09:15:30 +03:00
|
|
|
$this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
|
|
|
|
2016-08-19 09:15:30 +03:00
|
|
|
public function testShowFileRouteWithFile() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$parentNode = $this->getMockBuilder(Folder::class)->getMock();
|
2016-05-04 11:28:06 +03:00
|
|
|
$parentNode->expects($this->once())
|
|
|
|
->method('getPath')
|
2016-05-11 20:41:36 +03:00
|
|
|
->will($this->returnValue('testuser1/files/test'));
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$baseFolder = $this->getMockBuilder(Folder::class)->getMock();
|
2016-05-11 20:41:36 +03:00
|
|
|
|
|
|
|
$this->rootFolder->expects($this->once())
|
2016-08-19 09:15:30 +03:00
|
|
|
->method('getUserFolder')
|
|
|
|
->with('testuser1')
|
2016-05-11 20:41:36 +03:00
|
|
|
->will($this->returnValue($baseFolder));
|
2016-05-04 11:28:06 +03:00
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$node = $this->getMockBuilder(File::class)->getMock();
|
2016-05-04 11:28:06 +03:00
|
|
|
$node->expects($this->once())
|
|
|
|
->method('getParent')
|
|
|
|
->will($this->returnValue($parentNode));
|
|
|
|
$node->expects($this->once())
|
|
|
|
->method('getName')
|
|
|
|
->will($this->returnValue('somefile.txt'));
|
|
|
|
|
2016-05-11 20:41:36 +03:00
|
|
|
$baseFolder->expects($this->at(0))
|
2016-05-04 11:28:06 +03:00
|
|
|
->method('getById')
|
|
|
|
->with(123)
|
|
|
|
->will($this->returnValue([$node]));
|
2016-05-11 20:41:36 +03:00
|
|
|
$baseFolder->expects($this->at(1))
|
2016-05-04 11:28:06 +03:00
|
|
|
->method('getRelativePath')
|
2016-05-11 20:41:36 +03:00
|
|
|
->with('testuser1/files/test')
|
2016-05-04 11:28:06 +03:00
|
|
|
->will($this->returnValue('/test'));
|
|
|
|
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('files.view.index', ['dir' => '/test', 'scrollto' => 'somefile.txt'])
|
|
|
|
->will($this->returnValue('/apps/files/?dir=/test/sub&scrollto=somefile.txt'));
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('/apps/files/?dir=/test/sub&scrollto=somefile.txt');
|
2016-08-19 09:15:30 +03:00
|
|
|
$this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
|
|
|
|
2016-08-19 09:15:30 +03:00
|
|
|
public function testShowFileRouteWithInvalidFileId() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$baseFolder = $this->getMockBuilder(Folder::class)->getMock();
|
2016-05-11 20:41:36 +03:00
|
|
|
$this->rootFolder->expects($this->once())
|
2016-08-19 09:15:30 +03:00
|
|
|
->method('getUserFolder')
|
|
|
|
->with('testuser1')
|
2016-05-11 20:41:36 +03:00
|
|
|
->will($this->returnValue($baseFolder));
|
|
|
|
|
|
|
|
$baseFolder->expects($this->at(0))
|
2016-05-04 11:28:06 +03:00
|
|
|
->method('getById')
|
|
|
|
->with(123)
|
|
|
|
->will($this->returnValue([]));
|
|
|
|
|
2016-08-19 11:10:19 +03:00
|
|
|
$this->urlGenerator->expects($this->once())
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('files.view.index', ['fileNotFound' => true])
|
|
|
|
->willReturn('redirect.url');
|
|
|
|
|
2016-08-19 09:15:30 +03:00
|
|
|
$response = $this->viewController->index('MyDir', 'MyView', '123');
|
2016-08-19 11:10:19 +03:00
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\RedirectResponse', $response);
|
|
|
|
$this->assertEquals('redirect.url', $response->getRedirectURL());
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
2016-05-11 20:41:36 +03:00
|
|
|
|
2016-08-19 09:15:30 +03:00
|
|
|
public function testShowFileRouteWithTrashedFile() {
|
2016-05-11 20:41:36 +03:00
|
|
|
$this->appManager->expects($this->once())
|
|
|
|
->method('isEnabledForUser')
|
|
|
|
->with('files_trashbin')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$parentNode = $this->getMockBuilder(Folder::class)->getMock();
|
2016-05-11 20:41:36 +03:00
|
|
|
$parentNode->expects($this->once())
|
|
|
|
->method('getPath')
|
|
|
|
->will($this->returnValue('testuser1/files_trashbin/files/test.d1462861890/sub'));
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock();
|
|
|
|
$baseFolderTrash = $this->getMockBuilder(Folder::class)->getMock();
|
2016-05-11 20:41:36 +03:00
|
|
|
|
|
|
|
$this->rootFolder->expects($this->at(0))
|
2016-08-19 09:15:30 +03:00
|
|
|
->method('getUserFolder')
|
|
|
|
->with('testuser1')
|
2016-05-11 20:41:36 +03:00
|
|
|
->will($this->returnValue($baseFolderFiles));
|
|
|
|
$this->rootFolder->expects($this->at(1))
|
|
|
|
->method('get')
|
|
|
|
->with('testuser1/files_trashbin/files/')
|
|
|
|
->will($this->returnValue($baseFolderTrash));
|
|
|
|
|
|
|
|
$baseFolderFiles->expects($this->once())
|
|
|
|
->method('getById')
|
|
|
|
->with(123)
|
|
|
|
->will($this->returnValue([]));
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$node = $this->getMockBuilder(File::class)->getMock();
|
2016-05-11 20:41:36 +03:00
|
|
|
$node->expects($this->once())
|
|
|
|
->method('getParent')
|
|
|
|
->will($this->returnValue($parentNode));
|
|
|
|
$node->expects($this->once())
|
|
|
|
->method('getName')
|
|
|
|
->will($this->returnValue('somefile.txt'));
|
|
|
|
|
|
|
|
$baseFolderTrash->expects($this->at(0))
|
|
|
|
->method('getById')
|
|
|
|
->with(123)
|
|
|
|
->will($this->returnValue([$node]));
|
|
|
|
$baseFolderTrash->expects($this->at(1))
|
|
|
|
->method('getRelativePath')
|
|
|
|
->with('testuser1/files_trashbin/files/test.d1462861890/sub')
|
|
|
|
->will($this->returnValue('/test.d1462861890/sub'));
|
|
|
|
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('files.view.index', ['view' => 'trashbin', 'dir' => '/test.d1462861890/sub', 'scrollto' => 'somefile.txt'])
|
|
|
|
->will($this->returnValue('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt'));
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt');
|
2016-08-19 09:15:30 +03:00
|
|
|
$this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
|
2016-05-11 20:41:36 +03:00
|
|
|
}
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|