diff options
author | Julius Härtl <jus@bitgrid.net> | 2023-02-15 16:16:54 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2023-02-20 12:16:34 +0100 |
commit | 614981ae9abbfed04b9d1b3663f7e9d0aa85404c (patch) | |
tree | a10819a57f5f7a04a2fbf8430b5c5f37cf01120b /tests/lib | |
parent | 6bb0985e59d7ba3c4cf9928d8bb766ac9975cd12 (diff) | |
download | nextcloud-server-614981ae9abbfed04b9d1b3663f7e9d0aa85404c.tar.gz nextcloud-server-614981ae9abbfed04b9d1b3663f7e9d0aa85404c.zip |
feat(directediting): Allow opening by file id
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/DirectEditing/ManagerTest.php | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php index 7a2f2e3d772..53588093092 100644 --- a/tests/lib/DirectEditing/ManagerTest.php +++ b/tests/lib/DirectEditing/ManagerTest.php @@ -211,6 +211,86 @@ class ManagerTest extends TestCase { $this->assertInstanceOf(NotFoundResponse::class, $secondResult); } + public function testOpenByPath() { + $expectedToken = 'TOKEN' . time(); + $file = $this->createMock(File::class); + $file->expects($this->any()) + ->method('getId') + ->willReturn(123); + $file->expects($this->any()) + ->method('getPath') + ->willReturn('/admin/files/File.txt'); + $this->random->expects($this->once()) + ->method('generate') + ->willReturn($expectedToken); + $folder = $this->createMock(Folder::class); + $this->userFolder + ->method('nodeExists') + ->withConsecutive(['/File.txt'], ['/']) + ->willReturnOnConsecutiveCalls(false, true); + $this->userFolder + ->method('get') + ->with('/File.txt') + ->willReturn($file); + $this->userFolder + ->method('getRelativePath') + ->willReturn('/File.txt'); + $this->manager->open('/File.txt', 'testeditor'); + $firstResult = $this->manager->edit($expectedToken); + $secondResult = $this->manager->edit($expectedToken); + $this->assertInstanceOf(DataResponse::class, $firstResult); + $this->assertInstanceOf(NotFoundResponse::class, $secondResult); + } + + public function testOpenById() { + $expectedToken = 'TOKEN' . time(); + $fileRead = $this->createMock(File::class); + $fileRead->method('getPermissions') + ->willReturn(1); + $fileRead->expects($this->any()) + ->method('getId') + ->willReturn(123); + $fileRead->expects($this->any()) + ->method('getPath') + ->willReturn('/admin/files/shared_file.txt'); + $file = $this->createMock(File::class); + $file->method('getPermissions') + ->willReturn(1); + $file->expects($this->any()) + ->method('getId') + ->willReturn(123); + $file->expects($this->any()) + ->method('getPath') + ->willReturn('/admin/files/File.txt'); + $this->random->expects($this->once()) + ->method('generate') + ->willReturn($expectedToken); + $folder = $this->createMock(Folder::class); + $folder->expects($this->any()) + ->method('getById') + ->willReturn([ + $fileRead, + $file + ]); + $this->userFolder + ->method('nodeExists') + ->withConsecutive(['/File.txt'], ['/']) + ->willReturnOnConsecutiveCalls(false, true); + $this->userFolder + ->method('get') + ->with('/') + ->willReturn($folder); + $this->userFolder + ->method('getRelativePath') + ->willReturn('/File.txt'); + + $this->manager->open('/', 'testeditor', 123); + $firstResult = $this->manager->edit($expectedToken); + $secondResult = $this->manager->edit($expectedToken); + $this->assertInstanceOf(DataResponse::class, $firstResult); + $this->assertInstanceOf(NotFoundResponse::class, $secondResult); + } + public function testCreateFileAlreadyExists() { $this->expectException(\RuntimeException::class); $this->userFolder |