aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Controller/DirectControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/Controller/DirectControllerTest.php')
-rw-r--r--apps/dav/tests/unit/Controller/DirectControllerTest.php79
1 files changed, 29 insertions, 50 deletions
diff --git a/apps/dav/tests/unit/Controller/DirectControllerTest.php b/apps/dav/tests/unit/Controller/DirectControllerTest.php
index 0cfe7c5cde4..837adde1da7 100644
--- a/apps/dav/tests/unit/Controller/DirectControllerTest.php
+++ b/apps/dav/tests/unit/Controller/DirectControllerTest.php
@@ -3,30 +3,10 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
-namespace OCA\DAV\Tests\Unit\DAV\Controller;
+namespace OCA\DAV\Tests\unit\DAV\Controller;
use OCA\DAV\Controller\DirectController;
use OCA\DAV\Db\Direct;
@@ -35,33 +15,25 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class DirectControllerTest extends TestCase {
+ private IRootFolder&MockObject $rootFolder;
+ private DirectMapper&MockObject $directMapper;
+ private ISecureRandom&MockObject $random;
+ private ITimeFactory&MockObject $timeFactory;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IEventDispatcher&MockObject $eventDispatcher;
- /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
- private $rootFolder;
-
- /** @var DirectMapper|\PHPUnit\Framework\MockObject\MockObject */
- private $directMapper;
-
- /** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */
- private $random;
-
- /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $timeFactory;
-
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- private $urlGenerator;
-
- /** @var DirectController */
- private $controller;
+ private DirectController $controller;
protected function setUp(): void {
parent::setUp();
@@ -71,6 +43,7 @@ class DirectControllerTest extends TestCase {
$this->random = $this->createMock(ISecureRandom::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->controller = new DirectController(
'dav',
@@ -80,11 +53,12 @@ class DirectControllerTest extends TestCase {
$this->directMapper,
$this->random,
$this->timeFactory,
- $this->urlGenerator
+ $this->urlGenerator,
+ $this->eventDispatcher
);
}
- public function testGetUrlNonExistingFileId() {
+ public function testGetUrlNonExistingFileId(): void {
$userFolder = $this->createMock(Folder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
@@ -98,7 +72,7 @@ class DirectControllerTest extends TestCase {
$this->controller->getUrl(101);
}
- public function testGetUrlForFolder() {
+ public function testGetUrlForFolder(): void {
$userFolder = $this->createMock(Folder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
@@ -106,15 +80,15 @@ class DirectControllerTest extends TestCase {
$folder = $this->createMock(Folder::class);
- $userFolder->method('getById')
+ $userFolder->method('getFirstNodeById')
->with(101)
- ->willReturn([$folder]);
+ ->willReturn($folder);
$this->expectException(OCSBadRequestException::class);
$this->controller->getUrl(101);
}
- public function testGetUrlValid() {
+ public function testGetUrlValid(): void {
$userFolder = $this->createMock(Folder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
@@ -125,14 +99,17 @@ class DirectControllerTest extends TestCase {
$this->timeFactory->method('getTime')
->willReturn(42);
- $userFolder->method('getById')
+ $userFolder->method('getFirstNodeById')
->with(101)
- ->willReturn([$file]);
+ ->willReturn($file);
+
+ $userFolder->method('getRelativePath')
+ ->willReturn('/path');
$this->random->method('generate')
->with(
60,
- ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS
+ ISecureRandom::CHAR_ALPHANUMERIC
)->willReturn('superduperlongtoken');
$this->directMapper->expects($this->once())
@@ -142,11 +119,13 @@ class DirectControllerTest extends TestCase {
$this->assertSame(101, $direct->getFileId());
$this->assertSame('superduperlongtoken', $direct->getToken());
$this->assertSame(42 + 60 * 60 * 8, $direct->getExpiration());
+
+ return $direct;
});
$this->urlGenerator->method('getAbsoluteURL')
->willReturnCallback(function (string $url) {
- return 'https://my.nextcloud/'.$url;
+ return 'https://my.nextcloud/' . $url;
});
$result = $this->controller->getUrl(101);