aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/DirectEditing/ManagerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/DirectEditing/ManagerTest.php')
-rw-r--r--tests/lib/DirectEditing/ManagerTest.php44
1 files changed, 28 insertions, 16 deletions
diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php
index 53588093092..2ad7f98df49 100644
--- a/tests/lib/DirectEditing/ManagerTest.php
+++ b/tests/lib/DirectEditing/ManagerTest.php
@@ -1,5 +1,9 @@
<?php
+/**
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
namespace Test\DirectEditing;
use OC\DirectEditing\Manager;
@@ -19,6 +23,7 @@ use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
+use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -121,7 +126,7 @@ class ManagerTest extends TestCase {
$this->editor = new Editor();
$this->random = $this->createMock(ISecureRandom::class);
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = Server::get(IDBConnection::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->userFolder = $this->createMock(Folder::class);
@@ -153,12 +158,12 @@ class ManagerTest extends TestCase {
$this->manager->registerDirectEditor($this->editor);
}
- public function testEditorRegistration() {
+ public function testEditorRegistration(): void {
$this->assertEquals($this->manager->getEditors(), ['testeditor' => $this->editor]);
}
- public function testCreateToken() {
+ public function testCreateToken(): void {
$expectedToken = 'TOKEN' . time();
$file = $this->createMock(File::class);
$file->expects($this->any())
@@ -170,8 +175,10 @@ class ManagerTest extends TestCase {
$folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
- ->withConsecutive(['/File.txt'], ['/'])
- ->willReturnOnConsecutiveCalls(false, true);
+ ->willReturnMap([
+ ['/File.txt', false],
+ ['/', true],
+ ]);
$this->userFolder
->method('get')
->with('/')
@@ -183,7 +190,7 @@ class ManagerTest extends TestCase {
$this->assertEquals($token, $expectedToken);
}
- public function testCreateTokenAccess() {
+ public function testCreateTokenAccess(): void {
$expectedToken = 'TOKEN' . time();
$file = $this->createMock(File::class);
$file->expects($this->any())
@@ -195,8 +202,10 @@ class ManagerTest extends TestCase {
$folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
- ->withConsecutive(['/File.txt'], ['/'])
- ->willReturnOnConsecutiveCalls(false, true);
+ ->willReturnMap([
+ ['/File.txt', false],
+ ['/', true],
+ ]);
$this->userFolder
->method('get')
->with('/')
@@ -211,7 +220,7 @@ class ManagerTest extends TestCase {
$this->assertInstanceOf(NotFoundResponse::class, $secondResult);
}
- public function testOpenByPath() {
+ public function testOpenByPath(): void {
$expectedToken = 'TOKEN' . time();
$file = $this->createMock(File::class);
$file->expects($this->any())
@@ -223,11 +232,12 @@ class ManagerTest extends TestCase {
$this->random->expects($this->once())
->method('generate')
->willReturn($expectedToken);
- $folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
- ->withConsecutive(['/File.txt'], ['/'])
- ->willReturnOnConsecutiveCalls(false, true);
+ ->willReturnMap([
+ ['/File.txt', false],
+ ['/', true],
+ ]);
$this->userFolder
->method('get')
->with('/File.txt')
@@ -242,7 +252,7 @@ class ManagerTest extends TestCase {
$this->assertInstanceOf(NotFoundResponse::class, $secondResult);
}
- public function testOpenById() {
+ public function testOpenById(): void {
$expectedToken = 'TOKEN' . time();
$fileRead = $this->createMock(File::class);
$fileRead->method('getPermissions')
@@ -274,8 +284,10 @@ class ManagerTest extends TestCase {
]);
$this->userFolder
->method('nodeExists')
- ->withConsecutive(['/File.txt'], ['/'])
- ->willReturnOnConsecutiveCalls(false, true);
+ ->willReturnMap([
+ ['/File.txt', false],
+ ['/', true],
+ ]);
$this->userFolder
->method('get')
->with('/')
@@ -291,7 +303,7 @@ class ManagerTest extends TestCase {
$this->assertInstanceOf(NotFoundResponse::class, $secondResult);
}
- public function testCreateFileAlreadyExists() {
+ public function testCreateFileAlreadyExists(): void {
$this->expectException(\RuntimeException::class);
$this->userFolder
->method('nodeExists')