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>
|
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>
|
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;
|
|
|
|
|
|
|
|
use OCA\Files\Controller\ViewController;
|
|
|
|
use OCP\AppFramework\Http;
|
2016-08-19 09:15:30 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
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-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 {
|
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 INavigationManager */
|
|
|
|
private $navigationManager;
|
|
|
|
/** @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;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2016-08-16 21:58:33 +03:00
|
|
|
$this->request = $this->getMockBuilder('\OCP\IRequest')->getMock();
|
|
|
|
$this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')->getMock();
|
|
|
|
$this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->getMock();
|
|
|
|
$this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock();
|
|
|
|
$this->config = $this->getMockBuilder('\OCP\IConfig')->getMock();
|
|
|
|
$this->eventDispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
|
|
|
|
$this->userSession = $this->getMockBuilder('\OCP\IUserSession')->getMock();
|
|
|
|
$this->appManager = $this->getMockBuilder('\OCP\App\IAppManager')->getMock();
|
|
|
|
$this->user = $this->getMockBuilder('\OCP\IUser')->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();
|
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 testIndexWithRegularBrowser() {
|
|
|
|
$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,
|
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' => '',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'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' => '',
|
|
|
|
],
|
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,
|
2016-10-28 23:08:32 +03:00
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Shared with you'),
|
2015-11-16 22:57:41 +03:00
|
|
|
'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,
|
2016-10-28 23:08:32 +03:00
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Shared with others'),
|
2015-11-16 22:57:41 +03:00
|
|
|
'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,
|
2016-10-28 23:08:32 +03:00
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Shared by link', []),
|
2015-11-16 22:57:41 +03:00
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
],
|
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' => '',
|
|
|
|
],
|
|
|
|
[
|
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' => '',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$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' => [
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'files',
|
|
|
|
'content' => null,
|
|
|
|
],
|
2016-07-11 13:58:43 +03:00
|
|
|
[
|
|
|
|
'id' => 'recent',
|
|
|
|
'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
|
|
|
|
2016-08-19 09:15:30 +03:00
|
|
|
public function testShowFileRouteWithFolder() {
|
2016-08-16 21:58:33 +03:00
|
|
|
$node = $this->getMockBuilder('\OCP\Files\Folder')->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
|
|
|
|
2016-08-16 21:58:33 +03:00
|
|
|
$baseFolder = $this->getMockBuilder('\OCP\Files\Folder')->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() {
|
2016-08-16 21:58:33 +03:00
|
|
|
$parentNode = $this->getMockBuilder('\OCP\Files\Folder')->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'));
|
|
|
|
|
2016-08-16 21:58:33 +03:00
|
|
|
$baseFolder = $this->getMockBuilder('\OCP\Files\Folder')->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
|
|
|
|
2016-08-16 21:58:33 +03:00
|
|
|
$node = $this->getMockBuilder('\OCP\Files\File')->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() {
|
2016-08-16 21:58:33 +03:00
|
|
|
$baseFolder = $this->getMockBuilder('\OCP\Files\Folder')->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));
|
|
|
|
|
2016-08-16 21:58:33 +03:00
|
|
|
$parentNode = $this->getMockBuilder('\OCP\Files\Folder')->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'));
|
|
|
|
|
2016-08-16 21:58:33 +03:00
|
|
|
$baseFolderFiles = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
|
|
|
|
$baseFolderTrash = $this->getMockBuilder('\OCP\Files\Folder')->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([]));
|
|
|
|
|
2016-08-16 21:58:33 +03:00
|
|
|
$node = $this->getMockBuilder('\OCP\Files\File')->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
|
|
|
}
|