2015-11-16 22:57:41 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2016-03-01 19:25:15 +03:00
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-03-01 19:25:15 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-11-16 22:57:41 +03:00
|
|
|
*
|
2016-01-12 17:02:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
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;
|
|
|
|
|
|
|
|
use OCA\Files\Controller\ViewController;
|
|
|
|
use OCP\AppFramework\Http;
|
2016-06-07 14:51:16 +03:00
|
|
|
use OCP\Files\NotFoundException;
|
2016-05-12 13:07:06 +03:00
|
|
|
use OCP\IUser;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\Template;
|
|
|
|
use Test\TestCase;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
|
|
|
use OCP\INavigationManager;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IConfig;
|
2016-04-12 12:51:50 +03:00
|
|
|
use OCP\IUserSession;
|
2015-11-16 22:57:41 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2016-05-04 11:28:06 +03:00
|
|
|
use OCP\Files\Folder;
|
2016-05-11 20:41:36 +03:00
|
|
|
use OCP\App\IAppManager;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ViewControllerTest
|
|
|
|
*
|
|
|
|
* @package OCA\Files\Tests\Controller
|
|
|
|
*/
|
|
|
|
class ViewControllerTest extends TestCase {
|
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
/** @var INavigationManager */
|
|
|
|
private $navigationManager;
|
|
|
|
/** @var IL10N */
|
|
|
|
private $l10n;
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
/** @var EventDispatcherInterface */
|
|
|
|
private $eventDispatcher;
|
|
|
|
/** @var ViewController */
|
|
|
|
private $viewController;
|
2016-04-12 12:51:50 +03:00
|
|
|
/** @var IUser */
|
|
|
|
private $user;
|
|
|
|
/** @var IUserSession */
|
|
|
|
private $userSession;
|
2016-05-11 20:41:36 +03:00
|
|
|
/** @var IAppManager */
|
|
|
|
private $appManager;
|
2016-05-04 11:28:06 +03:00
|
|
|
/** @var Folder */
|
2016-05-11 20:41:36 +03:00
|
|
|
private $rootFolder;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->request = $this->getMock('\OCP\IRequest');
|
|
|
|
$this->urlGenerator = $this->getMock('\OCP\IURLGenerator');
|
|
|
|
$this->navigationManager = $this->getMock('\OCP\INavigationManager');
|
|
|
|
$this->l10n = $this->getMock('\OCP\IL10N');
|
|
|
|
$this->config = $this->getMock('\OCP\IConfig');
|
|
|
|
$this->eventDispatcher = $this->getMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
2016-04-12 12:51:50 +03:00
|
|
|
$this->userSession = $this->getMock('\OCP\IUserSession');
|
2016-05-11 20:41:36 +03:00
|
|
|
$this->appManager = $this->getMock('\OCP\App\IAppManager');
|
2016-04-12 12:51:50 +03:00
|
|
|
$this->user = $this->getMock('\OCP\IUser');
|
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-05-11 20:41:36 +03:00
|
|
|
$this->rootFolder = $this->getMock('\OCP\Files\Folder');
|
2015-11-16 22:57:41 +03:00
|
|
|
$this->viewController = $this->getMockBuilder('\OCA\Files\Controller\ViewController')
|
|
|
|
->setConstructorArgs([
|
|
|
|
'files',
|
|
|
|
$this->request,
|
|
|
|
$this->urlGenerator,
|
|
|
|
$this->navigationManager,
|
|
|
|
$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,
|
|
|
|
$this->rootFolder
|
2015-11-16 22:57:41 +03:00
|
|
|
])
|
|
|
|
->setMethods([
|
|
|
|
'getStorageInfo',
|
|
|
|
'renderScript'
|
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexWithIE8RedirectAndDirDefined() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAgent')
|
|
|
|
->with(['/MSIE 8.0/'])
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('files.view.index')
|
|
|
|
->will($this->returnValue('/apps/files/'));
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('/apps/files/#?dir=MyDir');
|
|
|
|
$this->assertEquals($expected, $this->viewController->index('MyDir'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexWithIE8RedirectAndViewDefined() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAgent')
|
|
|
|
->with(['/MSIE 8.0/'])
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('files.view.index')
|
|
|
|
->will($this->returnValue('/apps/files/'));
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('/apps/files/#?dir=/&view=MyView');
|
|
|
|
$this->assertEquals($expected, $this->viewController->index('', 'MyView'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexWithIE8RedirectAndViewAndDirDefined() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAgent')
|
|
|
|
->with(['/MSIE 8.0/'])
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('files.view.index')
|
|
|
|
->will($this->returnValue('/apps/files/'));
|
|
|
|
|
|
|
|
$expected = new RedirectResponse('/apps/files/#?dir=MyDir&view=MyView');
|
|
|
|
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexWithRegularBrowser() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAgent')
|
|
|
|
->with(['/MSIE 8.0/'])
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
$this->viewController
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getStorageInfo')
|
|
|
|
->will($this->returnValue([
|
|
|
|
'relative' => 123,
|
|
|
|
'owner' => 'MyName',
|
|
|
|
'ownerDisplayName' => 'MyDisplayName',
|
|
|
|
]));
|
2016-04-12 18:10:09 +03:00
|
|
|
$this->config->expects($this->exactly(3))
|
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],
|
2016-04-12 12:51:50 +03:00
|
|
|
]));
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
$this->config
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getAppValue')
|
|
|
|
->will($this->returnArgument(2));
|
|
|
|
|
|
|
|
$nav = new Template('files', 'appnavigation');
|
|
|
|
$nav->assign('navigationItems', [
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'files',
|
|
|
|
'appname' => 'files',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 0,
|
|
|
|
'name' => new \OC_L10N_String(new \OC_L10N('files'), 'All files', []),
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'favorites',
|
|
|
|
'appname' => 'files',
|
|
|
|
'script' => 'simplelist.php',
|
|
|
|
'order' => 5,
|
|
|
|
'name' => null,
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'sharingin',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 10,
|
|
|
|
'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared with you', []),
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'sharingout',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 15,
|
|
|
|
'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared with others', []),
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'sharinglinks',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 20,
|
|
|
|
'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared by link', []),
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
|
|
|
'id' => 'systemtagsfilter',
|
|
|
|
'appname' => 'systemtags',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 25,
|
|
|
|
'name' => new \OC_L10N_String(new \OC_L10N('systemtags'), 'Tags', []),
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
],
|
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'trashbin',
|
|
|
|
'appname' => 'files_trashbin',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 50,
|
|
|
|
'name' => new \OC_L10N_String(new \OC_L10N('files_trashbin'), 'Deleted files', []),
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$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
|
|
|
'mailNotificationEnabled' => 'no',
|
|
|
|
'mailPublicNotificationEnabled' => 'no',
|
|
|
|
'allowShareWithLink' => 'yes',
|
|
|
|
'appNavigation' => $nav,
|
|
|
|
'appContents' => [
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'files',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'favorites',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2016-02-09 13:22:05 +03:00
|
|
|
'id' => 'sharingin',
|
2015-11-16 22:57:41 +03:00
|
|
|
'content' => null,
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2016-02-09 13:22:05 +03:00
|
|
|
'id' => 'sharingout',
|
2015-11-16 22:57:41 +03:00
|
|
|
'content' => null,
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2016-02-09 13:22:05 +03:00
|
|
|
'id' => 'sharinglinks',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
|
|
|
'id' => 'systemtagsfilter',
|
|
|
|
'content' => null,
|
|
|
|
],
|
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'trashbin',
|
|
|
|
'content' => null,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
2015-12-02 19:30:40 +03:00
|
|
|
$policy = new Http\ContentSecurityPolicy();
|
|
|
|
$policy->addAllowedFrameDomain('\'self\'');
|
|
|
|
$expected->setContentSecurityPolicy($policy);
|
2015-11-16 22:57:41 +03:00
|
|
|
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
|
|
|
|
}
|
2016-05-04 11:28:06 +03:00
|
|
|
|
|
|
|
public function showFileMethodProvider() {
|
|
|
|
return [
|
|
|
|
[true],
|
|
|
|
[false],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider showFileMethodProvider
|
|
|
|
*/
|
|
|
|
public function testShowFileRouteWithFolder($useShowFile) {
|
|
|
|
$node = $this->getMock('\OCP\Files\Folder');
|
|
|
|
$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
|
|
|
|
2016-05-11 20:41:36 +03:00
|
|
|
$baseFolder = $this->getMock('\OCP\Files\Folder');
|
|
|
|
|
|
|
|
$this->rootFolder->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('testuser1/files/')
|
|
|
|
->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');
|
|
|
|
if ($useShowFile) {
|
|
|
|
$this->assertEquals($expected, $this->viewController->showFile(123));
|
|
|
|
} else {
|
|
|
|
$this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider showFileMethodProvider
|
|
|
|
*/
|
|
|
|
public function testShowFileRouteWithFile($useShowFile) {
|
|
|
|
$parentNode = $this->getMock('\OCP\Files\Folder');
|
|
|
|
$parentNode->expects($this->once())
|
|
|
|
->method('getPath')
|
2016-05-11 20:41:36 +03:00
|
|
|
->will($this->returnValue('testuser1/files/test'));
|
|
|
|
|
|
|
|
$baseFolder = $this->getMock('\OCP\Files\Folder');
|
|
|
|
|
|
|
|
$this->rootFolder->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('testuser1/files/')
|
|
|
|
->will($this->returnValue($baseFolder));
|
2016-05-04 11:28:06 +03:00
|
|
|
|
|
|
|
$node = $this->getMock('\OCP\Files\File');
|
|
|
|
$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');
|
|
|
|
if ($useShowFile) {
|
|
|
|
$this->assertEquals($expected, $this->viewController->showFile(123));
|
|
|
|
} else {
|
|
|
|
$this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider showFileMethodProvider
|
|
|
|
*/
|
|
|
|
public function testShowFileRouteWithInvalidFileId($useShowFile) {
|
2016-05-11 20:41:36 +03:00
|
|
|
$baseFolder = $this->getMock('\OCP\Files\Folder');
|
|
|
|
$this->rootFolder->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('testuser1/files/')
|
|
|
|
->will($this->returnValue($baseFolder));
|
|
|
|
|
|
|
|
$baseFolder->expects($this->at(0))
|
2016-05-04 11:28:06 +03:00
|
|
|
->method('getById')
|
|
|
|
->with(123)
|
|
|
|
->will($this->returnValue([]));
|
|
|
|
|
|
|
|
if ($useShowFile) {
|
2016-06-07 14:51:16 +03:00
|
|
|
$this->expectException('OCP\Files\NotFoundException');
|
|
|
|
$this->viewController->showFile(123);
|
2016-05-04 11:28:06 +03:00
|
|
|
} else {
|
2016-06-07 14:51:16 +03:00
|
|
|
$response = $this->viewController->index('MyDir', 'MyView', '123');
|
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $response);
|
|
|
|
$params = $response->getParams();
|
|
|
|
$this->assertEquals(1, $params['fileNotFound']);
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-11 20:41:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider showFileMethodProvider
|
|
|
|
*/
|
|
|
|
public function testShowFileRouteWithTrashedFile($useShowFile) {
|
|
|
|
$this->appManager->expects($this->once())
|
|
|
|
->method('isEnabledForUser')
|
|
|
|
->with('files_trashbin')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$parentNode = $this->getMock('\OCP\Files\Folder');
|
|
|
|
$parentNode->expects($this->once())
|
|
|
|
->method('getPath')
|
|
|
|
->will($this->returnValue('testuser1/files_trashbin/files/test.d1462861890/sub'));
|
|
|
|
|
|
|
|
$baseFolderFiles = $this->getMock('\OCP\Files\Folder');
|
|
|
|
$baseFolderTrash = $this->getMock('\OCP\Files\Folder');
|
|
|
|
|
|
|
|
$this->rootFolder->expects($this->at(0))
|
|
|
|
->method('get')
|
|
|
|
->with('testuser1/files/')
|
|
|
|
->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([]));
|
|
|
|
|
|
|
|
$node = $this->getMock('\OCP\Files\File');
|
|
|
|
$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');
|
|
|
|
if ($useShowFile) {
|
|
|
|
$this->assertEquals($expected, $this->viewController->showFile(123));
|
|
|
|
} else {
|
|
|
|
$this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|