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;
|
|
|
|
|
|
|
|
use OCA\Files\Controller\ViewController;
|
|
|
|
use OCP\AppFramework\Http;
|
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;
|
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\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 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();
|
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();
|
2016-08-16 21:58:33 +03:00
|
|
|
$this->eventDispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
|
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();
|
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,
|
|
|
|
$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([
|
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',
|
|
|
|
]));
|
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');
|
2017-06-12 11:32:25 +03:00
|
|
|
$nav->assign('usage_relative', 123);
|
|
|
|
$nav->assign('usage', '123 B');
|
|
|
|
$nav->assign('quota', 100);
|
|
|
|
$nav->assign('total_space', '100 B');
|
2018-04-05 11:34:24 +03:00
|
|
|
$nav->assign('webdavurl', '');
|
2015-11-16 22:57:41 +03:00
|
|
|
$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' => '',
|
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
|
|
|
],
|
|
|
|
[
|
|
|
|
'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
|
|
|
],
|
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' => '',
|
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
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'sharingin',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
2017-08-25 15:41:26 +03:00
|
|
|
'order' => 15,
|
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' => '',
|
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
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'sharingout',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
2017-08-25 15:41:26 +03:00
|
|
|
'order' => 16,
|
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' => '',
|
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
|
|
|
],
|
2016-02-26 11:52:29 +03:00
|
|
|
[
|
2015-11-16 22:57:41 +03:00
|
|
|
'id' => 'sharinglinks',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
2017-08-25 15:41:26 +03:00
|
|
|
'order' => 17,
|
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' => '',
|
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-06-26 10:30:40 +03:00
|
|
|
[
|
|
|
|
'id' => 'deletedshares',
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 18,
|
|
|
|
'name' => \OC::$server->getL10N('files_sharing')->t('Deleted shares'),
|
|
|
|
'active' => false,
|
|
|
|
'icon' => '',
|
|
|
|
'type' => 'link',
|
|
|
|
'classes' => '',
|
|
|
|
],
|
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
|
|
|
],
|
|
|
|
[
|
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
|
|
|
],
|
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' => [
|
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,
|
|
|
|
],
|
2018-06-26 10:30:40 +03:00
|
|
|
[
|
|
|
|
'id' => 'deletedshares',
|
|
|
|
'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,
|
|
|
|
],
|
|
|
|
],
|
2017-06-12 11:32:25 +03:00
|
|
|
'hiddenFields' => [],
|
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);
|
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
|
|
|
}
|