summaryrefslogtreecommitdiffstats
path: root/apps/files/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-05-04 10:28:06 +0200
committerVincent Petry <pvince81@owncloud.com>2016-05-06 16:46:59 +0200
commit093e9dd4225e6681140523c75bfc20809cd6d651 (patch)
tree21541ba147dad52fefc704900b6aebe4b8d921b0 /apps/files/tests
parentba998670333b5430cd00dbce82a44f831ef34da1 (diff)
downloadnextcloud-server-093e9dd4225e6681140523c75bfc20809cd6d651.tar.gz
nextcloud-server-093e9dd4225e6681140523c75bfc20809cd6d651.zip
Add route to resolve fileid to files app URL
The following routes will redirect to the files app and display the matching folder. If the fileid is a file, it will scroll to it. - http://localhost/owncloud/index.php/f/$fileid - http://localhost/owncloud/index.php/files/?dir=somedir&fileid=$fileid
Diffstat (limited to 'apps/files/tests')
-rw-r--r--apps/files/tests/controller/ViewControllerTest.php103
1 files changed, 102 insertions, 1 deletions
diff --git a/apps/files/tests/controller/ViewControllerTest.php b/apps/files/tests/controller/ViewControllerTest.php
index 420e635b4b9..797702def6b 100644
--- a/apps/files/tests/controller/ViewControllerTest.php
+++ b/apps/files/tests/controller/ViewControllerTest.php
@@ -36,6 +36,7 @@ use OCP\IL10N;
use OCP\IConfig;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use OCP\Files\Folder;
/**
* Class ViewControllerTest
@@ -61,6 +62,8 @@ class ViewControllerTest extends TestCase {
private $user;
/** @var IUserSession */
private $userSession;
+ /** @var Folder */
+ private $userFolder;
public function setUp() {
parent::setUp();
@@ -75,6 +78,7 @@ class ViewControllerTest extends TestCase {
$this->userSession->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
+ $this->userFolder = $this->getMock('\OCP\Files\Folder');
$this->viewController = $this->getMockBuilder('\OCA\Files\Controller\ViewController')
->setConstructorArgs([
'files',
@@ -84,7 +88,8 @@ class ViewControllerTest extends TestCase {
$this->l10n,
$this->config,
$this->eventDispatcher,
- $this->userSession
+ $this->userSession,
+ $this->userFolder
])
->setMethods([
'getStorageInfo',
@@ -287,4 +292,100 @@ class ViewControllerTest extends TestCase {
$expected->setContentSecurityPolicy($policy);
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
}
+
+ public function showFileMethodProvider() {
+ return [
+ [true],
+ [false],
+ ];
+ }
+
+ /**
+ * @dataProvider showFileMethodProvider
+ */
+ public function testShowFileRouteWithFolder($useShowFile) {
+ $node = $this->getMock('\OCP\Files\Folder');
+ $node->expects($this->once())
+ ->method('getPath')
+ ->will($this->returnValue('/user/files/test/sub'));
+
+ $this->userFolder->expects($this->at(0))
+ ->method('getById')
+ ->with(123)
+ ->will($this->returnValue([$node]));
+ $this->userFolder->expects($this->at(1))
+ ->method('getRelativePath')
+ ->with('/user/files/test/sub')
+ ->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')
+ ->will($this->returnValue('/user/files/test'));
+
+ $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'));
+
+ $this->userFolder->expects($this->at(0))
+ ->method('getById')
+ ->with(123)
+ ->will($this->returnValue([$node]));
+ $this->userFolder->expects($this->at(1))
+ ->method('getRelativePath')
+ ->with('/user/files/test')
+ ->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) {
+ $this->userFolder->expects($this->at(0))
+ ->method('getById')
+ ->with(123)
+ ->will($this->returnValue([]));
+
+ $expected = new Http\NotFoundResponse();
+ if ($useShowFile) {
+ $this->assertEquals($expected, $this->viewController->showFile(123));
+ } else {
+ $this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
+ }
+ }
}