diff options
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/appinfo/info.xml | 1 | ||||
-rw-r--r-- | apps/dav/appinfo/v1/publicwebdav.php | 4 | ||||
-rw-r--r-- | apps/dav/appinfo/v2/publicremote.php | 4 | ||||
-rw-r--r-- | apps/dav/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/dav/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/dav/l10n/de.js | 2 | ||||
-rw-r--r-- | apps/dav/l10n/de.json | 2 | ||||
-rw-r--r-- | apps/dav/l10n/de_DE.js | 2 | ||||
-rw-r--r-- | apps/dav/l10n/de_DE.json | 2 | ||||
-rw-r--r-- | apps/dav/l10n/et_EE.js | 7 | ||||
-rw-r--r-- | apps/dav/l10n/et_EE.json | 7 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/File.php | 3 | ||||
-rw-r--r-- | apps/dav/lib/Files/Sharing/FilesDropPlugin.php | 91 | ||||
-rw-r--r-- | apps/dav/lib/Migration/RegisterUpdateCalendarResourcesRoomBackgroundJob.php | 30 | ||||
-rw-r--r-- | apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php | 161 |
15 files changed, 178 insertions, 140 deletions
diff --git a/apps/dav/appinfo/info.xml b/apps/dav/appinfo/info.xml index e0f4608e8c2..2b3a9fcede8 100644 --- a/apps/dav/appinfo/info.xml +++ b/apps/dav/appinfo/info.xml @@ -41,6 +41,7 @@ <step>OCA\DAV\Migration\BuildSocialSearchIndex</step> <step>OCA\DAV\Migration\RefreshWebcalJobRegistrar</step> <step>OCA\DAV\Migration\RegisterBuildReminderIndexBackgroundJob</step> + <step>OCA\DAV\Migration\RegisterUpdateCalendarResourcesRoomBackgroundJob</step> <step>OCA\DAV\Migration\RemoveOrphanEventsAndContacts</step> <step>OCA\DAV\Migration\RemoveClassifiedEventActivity</step> <step>OCA\DAV\Migration\RemoveDeletedUsersCalendarSubscriptions</step> diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index aa16d6c584a..af49ca5462c 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -104,11 +104,9 @@ $server = $serverFactory->createServer(false, $baseuri, $requestUri, $authPlugin if (!$isReadable) { $filesDropPlugin->enable(); } - - $view = new View($node->getPath()); - $filesDropPlugin->setView($view); $filesDropPlugin->setShare($share); + $view = new View($node->getPath()); return $view; }); diff --git a/apps/dav/appinfo/v2/publicremote.php b/apps/dav/appinfo/v2/publicremote.php index 62336a9b80f..fbb3ddd2cb3 100644 --- a/apps/dav/appinfo/v2/publicremote.php +++ b/apps/dav/appinfo/v2/publicremote.php @@ -131,11 +131,9 @@ $server = $serverFactory->createServer(true, $baseuri, $requestUri, $authPlugin, if (!$isReadable) { $filesDropPlugin->enable(); } - - $view = new View($node->getPath()); - $filesDropPlugin->setView($view); $filesDropPlugin->setShare($share); + $view = new View($node->getPath()); return $view; }); diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index 913f5b46d98..fc753e79908 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -316,6 +316,7 @@ return array( 'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => $baseDir . '/../lib/Migration/RefreshWebcalJobRegistrar.php', 'OCA\\DAV\\Migration\\RegenerateBirthdayCalendars' => $baseDir . '/../lib/Migration/RegenerateBirthdayCalendars.php', 'OCA\\DAV\\Migration\\RegisterBuildReminderIndexBackgroundJob' => $baseDir . '/../lib/Migration/RegisterBuildReminderIndexBackgroundJob.php', + 'OCA\\DAV\\Migration\\RegisterUpdateCalendarResourcesRoomBackgroundJob' => $baseDir . '/../lib/Migration/RegisterUpdateCalendarResourcesRoomBackgroundJob.php', 'OCA\\DAV\\Migration\\RemoveClassifiedEventActivity' => $baseDir . '/../lib/Migration/RemoveClassifiedEventActivity.php', 'OCA\\DAV\\Migration\\RemoveDeletedUsersCalendarSubscriptions' => $baseDir . '/../lib/Migration/RemoveDeletedUsersCalendarSubscriptions.php', 'OCA\\DAV\\Migration\\RemoveObjectProperties' => $baseDir . '/../lib/Migration/RemoveObjectProperties.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index 6369511343e..cd46530ecd4 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -331,6 +331,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php', 'OCA\\DAV\\Migration\\RegenerateBirthdayCalendars' => __DIR__ . '/..' . '/../lib/Migration/RegenerateBirthdayCalendars.php', 'OCA\\DAV\\Migration\\RegisterBuildReminderIndexBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/RegisterBuildReminderIndexBackgroundJob.php', + 'OCA\\DAV\\Migration\\RegisterUpdateCalendarResourcesRoomBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/RegisterUpdateCalendarResourcesRoomBackgroundJob.php', 'OCA\\DAV\\Migration\\RemoveClassifiedEventActivity' => __DIR__ . '/..' . '/../lib/Migration/RemoveClassifiedEventActivity.php', 'OCA\\DAV\\Migration\\RemoveDeletedUsersCalendarSubscriptions' => __DIR__ . '/..' . '/../lib/Migration/RemoveDeletedUsersCalendarSubscriptions.php', 'OCA\\DAV\\Migration\\RemoveObjectProperties' => __DIR__ . '/..' . '/../lib/Migration/RemoveObjectProperties.php', diff --git a/apps/dav/l10n/de.js b/apps/dav/l10n/de.js index d6569cdc4f9..66e17898188 100644 --- a/apps/dav/l10n/de.js +++ b/apps/dav/l10n/de.js @@ -282,7 +282,7 @@ OC.L10N.register( "Saved availability" : "Verfügbarkeit gespeichert", "Failed to save availability" : "Verfügbarkeit konnte nicht gespeichert werden", "Time zone:" : "Zeitzone:", - "to" : "an", + "to" : "bis", "Delete slot" : "Slot löschen", "No working hours set" : "Keine Arbeitszeiten konfiguriert", "Add slot" : "Slot hinzufügen", diff --git a/apps/dav/l10n/de.json b/apps/dav/l10n/de.json index e3a6f980ba1..94354959e6f 100644 --- a/apps/dav/l10n/de.json +++ b/apps/dav/l10n/de.json @@ -280,7 +280,7 @@ "Saved availability" : "Verfügbarkeit gespeichert", "Failed to save availability" : "Verfügbarkeit konnte nicht gespeichert werden", "Time zone:" : "Zeitzone:", - "to" : "an", + "to" : "bis", "Delete slot" : "Slot löschen", "No working hours set" : "Keine Arbeitszeiten konfiguriert", "Add slot" : "Slot hinzufügen", diff --git a/apps/dav/l10n/de_DE.js b/apps/dav/l10n/de_DE.js index 1072d8f9ff2..0a53ba564a7 100644 --- a/apps/dav/l10n/de_DE.js +++ b/apps/dav/l10n/de_DE.js @@ -282,7 +282,7 @@ OC.L10N.register( "Saved availability" : "Verfügbarkeit gespeichert", "Failed to save availability" : "Verfügbarkeit konnte nicht gespeichert werden", "Time zone:" : "Zeitzone:", - "to" : "an", + "to" : "bis", "Delete slot" : "Zeitfenster löschen", "No working hours set" : "Keine Arbeitszeiten konfiguriert", "Add slot" : "Zeitfenster hinzufügen", diff --git a/apps/dav/l10n/de_DE.json b/apps/dav/l10n/de_DE.json index 721cee8c91a..7bf998eec36 100644 --- a/apps/dav/l10n/de_DE.json +++ b/apps/dav/l10n/de_DE.json @@ -280,7 +280,7 @@ "Saved availability" : "Verfügbarkeit gespeichert", "Failed to save availability" : "Verfügbarkeit konnte nicht gespeichert werden", "Time zone:" : "Zeitzone:", - "to" : "an", + "to" : "bis", "Delete slot" : "Zeitfenster löschen", "No working hours set" : "Keine Arbeitszeiten konfiguriert", "Add slot" : "Zeitfenster hinzufügen", diff --git a/apps/dav/l10n/et_EE.js b/apps/dav/l10n/et_EE.js index 69f941b3daa..2cf7703d686 100644 --- a/apps/dav/l10n/et_EE.js +++ b/apps/dav/l10n/et_EE.js @@ -31,7 +31,11 @@ OC.L10N.register( "{actor} deleted event {event} from calendar {calendar}" : "{actor} kustutas sündmuse {event} kalendrist {calendar}", "You deleted event {event} from calendar {calendar}" : "Sa kustutasid sündmuse {event} kalendrist {calendar}", "{actor} updated event {event} in calendar {calendar}" : "{actor} uuendas sündmust {event} kalendris {calendar}", - "You updated event {event} in calendar {calendar}" : "Sa uuendasid sündmust {event} kalendris {calendar}", + "You updated event {event} in calendar {calendar}" : "Sa uuendasid „{event}“ sündmust „{calendar}“ kalendris", + "{actor} moved event {event} from calendar {sourceCalendar} to calendar {targetCalendar}" : "{actor} teisaldas „{event}“ sündmuse „{sourceCalendar}“ kalendrist „{targetCalendar}“ kalendrisse", + "You moved event {event} from calendar {sourceCalendar} to calendar {targetCalendar}" : "Sina teisaldasid „{event}“ sündmuse „{sourceCalendar}“ kalendrist „{targetCalendar}“ kalendrisse", + "{actor} restored event {event} of calendar {calendar}" : "{actor} taastas „{event}“ sündmuse „{calendar}“ kalendris", + "You restored event {event} of calendar {calendar}" : "Sina taastasid „{event}“ sündmuse „{calendar}“ kalendris", "Busy" : "Hõivatud", "{actor} created to-do {todo} in list {calendar}" : "{actor} lisas {todo} ülesande {calendar} loendissse", "You created to-do {todo} in list {calendar}" : "Sina lisasid {todo} ülesande {calendar} loendisse", @@ -68,6 +72,7 @@ OC.L10N.register( "Description: %s" : "Kirjeldus: %s", "Where: %s" : "Kus: %s", "%1$s via %2$s" : "%1$s %2$s kaudu", + "Every Day between %1$s - %2$s until %3$s" : "Iga päev ajavahemikus %1$s-%2$s kuni %3$s", "Cancelled: %1$s" : "Tühistatud: %1$s", "\"%1$s\" has been canceled" : "„%1$s“ on tühistatud", "Re: %1$s" : "Re: %1$s", diff --git a/apps/dav/l10n/et_EE.json b/apps/dav/l10n/et_EE.json index 2eed43d0c8f..e4615d45ca2 100644 --- a/apps/dav/l10n/et_EE.json +++ b/apps/dav/l10n/et_EE.json @@ -29,7 +29,11 @@ "{actor} deleted event {event} from calendar {calendar}" : "{actor} kustutas sündmuse {event} kalendrist {calendar}", "You deleted event {event} from calendar {calendar}" : "Sa kustutasid sündmuse {event} kalendrist {calendar}", "{actor} updated event {event} in calendar {calendar}" : "{actor} uuendas sündmust {event} kalendris {calendar}", - "You updated event {event} in calendar {calendar}" : "Sa uuendasid sündmust {event} kalendris {calendar}", + "You updated event {event} in calendar {calendar}" : "Sa uuendasid „{event}“ sündmust „{calendar}“ kalendris", + "{actor} moved event {event} from calendar {sourceCalendar} to calendar {targetCalendar}" : "{actor} teisaldas „{event}“ sündmuse „{sourceCalendar}“ kalendrist „{targetCalendar}“ kalendrisse", + "You moved event {event} from calendar {sourceCalendar} to calendar {targetCalendar}" : "Sina teisaldasid „{event}“ sündmuse „{sourceCalendar}“ kalendrist „{targetCalendar}“ kalendrisse", + "{actor} restored event {event} of calendar {calendar}" : "{actor} taastas „{event}“ sündmuse „{calendar}“ kalendris", + "You restored event {event} of calendar {calendar}" : "Sina taastasid „{event}“ sündmuse „{calendar}“ kalendris", "Busy" : "Hõivatud", "{actor} created to-do {todo} in list {calendar}" : "{actor} lisas {todo} ülesande {calendar} loendissse", "You created to-do {todo} in list {calendar}" : "Sina lisasid {todo} ülesande {calendar} loendisse", @@ -66,6 +70,7 @@ "Description: %s" : "Kirjeldus: %s", "Where: %s" : "Kus: %s", "%1$s via %2$s" : "%1$s %2$s kaudu", + "Every Day between %1$s - %2$s until %3$s" : "Iga päev ajavahemikus %1$s-%2$s kuni %3$s", "Cancelled: %1$s" : "Tühistatud: %1$s", "\"%1$s\" has been canceled" : "„%1$s“ on tühistatud", "Re: %1$s" : "Re: %1$s", diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 045b9d7e784..98e0f2e9e4b 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -19,6 +19,7 @@ use OCA\DAV\Connector\Sabre\Exception\Forbidden as DAVForbiddenException; use OCA\DAV\Connector\Sabre\Exception\UnsupportedMediaType; use OCP\App\IAppManager; use OCP\Encryption\Exceptions\GenericEncryptionException; +use OCP\Files; use OCP\Files\EntityTooLargeException; use OCP\Files\FileInfo; use OCP\Files\ForbiddenException; @@ -229,7 +230,7 @@ class File extends Node implements IFile { // because we have no clue about the cause we can only throw back a 500/Internal Server Error throw new Exception($this->l10n->t('Could not write file contents')); } - [$count, $result] = \OC_Helper::streamCopy($data, $target); + [$count, $result] = Files::streamCopy($data, $target, true); fclose($target); } diff --git a/apps/dav/lib/Files/Sharing/FilesDropPlugin.php b/apps/dav/lib/Files/Sharing/FilesDropPlugin.php index ad7648795da..9aee5283ea9 100644 --- a/apps/dav/lib/Files/Sharing/FilesDropPlugin.php +++ b/apps/dav/lib/Files/Sharing/FilesDropPlugin.php @@ -5,7 +5,8 @@ */ namespace OCA\DAV\Files\Sharing; -use OC\Files\View; +use OCP\Files\Folder; +use OCP\Files\NotFoundException; use OCP\Share\IShare; use Sabre\DAV\Exception\MethodNotAllowed; use Sabre\DAV\ServerPlugin; @@ -17,14 +18,9 @@ use Sabre\HTTP\ResponseInterface; */ class FilesDropPlugin extends ServerPlugin { - private ?View $view = null; private ?IShare $share = null; private bool $enabled = false; - public function setView(View $view): void { - $this->view = $view; - } - public function setShare(IShare $share): void { $this->share = $share; } @@ -33,7 +29,6 @@ class FilesDropPlugin extends ServerPlugin { $this->enabled = true; } - /** * This initializes the plugin. * It is ONLY initialized by the server on a file drop request. @@ -45,7 +40,12 @@ class FilesDropPlugin extends ServerPlugin { } public function onMkcol(RequestInterface $request, ResponseInterface $response) { - if (!$this->enabled || $this->share === null || $this->view === null) { + if (!$this->enabled || $this->share === null) { + return; + } + + $node = $this->share->getNode(); + if (!($node instanceof Folder)) { return; } @@ -57,7 +57,12 @@ class FilesDropPlugin extends ServerPlugin { } public function beforeMethod(RequestInterface $request, ResponseInterface $response) { - if (!$this->enabled || $this->share === null || $this->view === null) { + if (!$this->enabled || $this->share === null) { + return; + } + + $node = $this->share->getNode(); + if (!($node instanceof Folder)) { return; } @@ -127,45 +132,55 @@ class FilesDropPlugin extends ServerPlugin { } // Create the folders along the way - $folders = $this->getPathSegments(dirname($relativePath)); - foreach ($folders as $folder) { - if ($folder === '') { + $folder = $node; + $pathSegments = $this->getPathSegments(dirname($relativePath)); + foreach ($pathSegments as $pathSegment) { + if ($pathSegment === '') { continue; - } // skip empty parts - if (!$this->view->file_exists($folder)) { - $this->view->mkdir($folder); + } + + try { + // get the current folder + $currentFolder = $folder->get($pathSegment); + // check target is a folder + if ($currentFolder instanceof Folder) { + $folder = $currentFolder; + } else { + // otherwise look in the parent folder if we already create an unique folder name + foreach ($folder->getDirectoryListing() as $child) { + // we look for folders which match "NAME (SUFFIX)" + if ($child instanceof Folder && str_starts_with($child->getName(), $pathSegment)) { + $suffix = substr($child->getName(), strlen($pathSegment)); + if (preg_match('/^ \(\d+\)$/', $suffix)) { + // we found the unique folder name and can use it + $folder = $child; + break; + } + } + } + // no folder found so we need to create a new unique folder name + if (!isset($child) || $child !== $folder) { + $folder = $folder->newFolder($folder->getNonExistingName($pathSegment)); + } + } + } catch (NotFoundException) { + // the folder does simply not exist so we create it + $folder = $folder->newFolder($pathSegment); } } // Finally handle conflicts on the end files - $noConflictPath = \OC_Helper::buildNotExistingFileNameForView(dirname($relativePath), basename($relativePath), $this->view); - $path = '/files/' . $token . '/' . $noConflictPath; - $url = $request->getBaseUrl() . str_replace('//', '/', $path); + $uniqueName = $folder->getNonExistingName(basename($relativePath)); + $relativePath = substr($folder->getPath(), strlen($node->getPath())); + $path = '/files/' . $token . '/' . $relativePath . '/' . $uniqueName; + $url = rtrim($request->getBaseUrl(), '/') . str_replace('//', '/', $path); $request->setUrl($url); } private function getPathSegments(string $path): array { // Normalize slashes and remove trailing slash - $path = rtrim(str_replace('\\', '/', $path), '/'); - - // Handle absolute paths starting with / - $isAbsolute = str_starts_with($path, '/'); - - $segments = explode('/', $path); - - // Add back the leading slash for the first segment if needed - $result = []; - $current = $isAbsolute ? '/' : ''; - - foreach ($segments as $segment) { - if ($segment === '') { - // skip empty parts - continue; - } - $current = rtrim($current, '/') . '/' . $segment; - $result[] = $current; - } + $path = trim(str_replace('\\', '/', $path), '/'); - return $result; + return explode('/', $path); } } diff --git a/apps/dav/lib/Migration/RegisterUpdateCalendarResourcesRoomBackgroundJob.php b/apps/dav/lib/Migration/RegisterUpdateCalendarResourcesRoomBackgroundJob.php new file mode 100644 index 00000000000..9d77aefafd2 --- /dev/null +++ b/apps/dav/lib/Migration/RegisterUpdateCalendarResourcesRoomBackgroundJob.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\DAV\Migration; + +use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob; +use OCP\BackgroundJob\IJobList; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class RegisterUpdateCalendarResourcesRoomBackgroundJob implements IRepairStep { + public function __construct( + private readonly IJobList $jobList, + ) { + } + + public function getName() { + return 'Register a background job to update rooms and resources'; + } + + public function run(IOutput $output) { + $this->jobList->add(UpdateCalendarResourcesRoomsBackgroundJob::class); + } +} diff --git a/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php b/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php index dc1e067dafd..16891ced3d0 100644 --- a/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php +++ b/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php @@ -5,10 +5,12 @@ */ namespace OCA\DAV\Tests\Files\Sharing; -use OC\Files\View; use OCA\DAV\Files\Sharing\FilesDropPlugin; +use OCP\Files\Folder; +use OCP\Files\NotFoundException; use OCP\Share\IAttributes; use OCP\Share\IShare; +use PHPUnit\Framework\MockObject\MockObject; use Sabre\DAV\Exception\MethodNotAllowed; use Sabre\DAV\Server; use Sabre\HTTP\RequestInterface; @@ -17,29 +19,25 @@ use Test\TestCase; class FilesDropPluginTest extends TestCase { - /** @var View|\PHPUnit\Framework\MockObject\MockObject */ - private $view; + private FilesDropPlugin $plugin; - /** @var IShare|\PHPUnit\Framework\MockObject\MockObject */ - private $share; - - /** @var Server|\PHPUnit\Framework\MockObject\MockObject */ - private $server; - - /** @var FilesDropPlugin */ - private $plugin; - - /** @var RequestInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $request; - - /** @var ResponseInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $response; + private Folder&MockObject $node; + private IShare&MockObject $share; + private Server&MockObject $server; + private RequestInterface&MockObject $request; + private ResponseInterface&MockObject $response; protected function setUp(): void { parent::setUp(); - $this->view = $this->createMock(View::class); + $this->node = $this->createMock(Folder::class); + $this->node->method('getPath') + ->willReturn('/files/token'); + $this->share = $this->createMock(IShare::class); + $this->share->expects(self::any()) + ->method('getNode') + ->willReturn($this->node); $this->server = $this->createMock(Server::class); $this->plugin = new FilesDropPlugin(); @@ -56,28 +54,7 @@ class FilesDropPluginTest extends TestCase { ->willReturn('token'); } - public function testInitialize(): void { - $this->server->expects($this->at(0)) - ->method('on') - ->with( - $this->equalTo('beforeMethod:*'), - $this->equalTo([$this->plugin, 'beforeMethod']), - $this->equalTo(999) - ); - $this->server->expects($this->at(1)) - ->method('on') - ->with( - $this->equalTo('method:MKCOL'), - $this->equalTo([$this->plugin, 'onMkcol']), - ); - - $this->plugin->initialize($this->server); - } - public function testNotEnabled(): void { - $this->view->expects($this->never()) - ->method($this->anything()); - $this->request->expects($this->never()) ->method($this->anything()); @@ -86,7 +63,6 @@ class FilesDropPluginTest extends TestCase { public function testValid(): void { $this->plugin->enable(); - $this->plugin->setView($this->view); $this->plugin->setShare($this->share); $this->request->method('getMethod') @@ -98,9 +74,10 @@ class FilesDropPluginTest extends TestCase { $this->request->method('getBaseUrl') ->willReturn('https://example.com'); - $this->view->method('file_exists') - ->with('/file.txt') - ->willReturn(false); + $this->node->expects(self::once()) + ->method('getNonExistingName') + ->with('file.txt') + ->willReturn('file.txt'); $this->request->expects($this->once()) ->method('setUrl') @@ -111,7 +88,6 @@ class FilesDropPluginTest extends TestCase { public function testFileAlreadyExistsValid(): void { $this->plugin->enable(); - $this->plugin->setView($this->view); $this->plugin->setShare($this->share); $this->request->method('getMethod') @@ -123,14 +99,9 @@ class FilesDropPluginTest extends TestCase { $this->request->method('getBaseUrl') ->willReturn('https://example.com'); - $this->view->method('file_exists') - ->willReturnCallback(function ($path) { - if ($path === 'file.txt' || $path === '/file.txt') { - return true; - } else { - return false; - } - }); + $this->node->method('getNonExistingName') + ->with('file.txt') + ->willReturn('file (2).txt'); $this->request->expects($this->once()) ->method('setUrl') @@ -141,7 +112,6 @@ class FilesDropPluginTest extends TestCase { public function testNoMKCOLWithoutNickname(): void { $this->plugin->enable(); - $this->plugin->setView($this->view); $this->plugin->setShare($this->share); $this->request->method('getMethod') @@ -154,7 +124,6 @@ class FilesDropPluginTest extends TestCase { public function testMKCOLWithNickname(): void { $this->plugin->enable(); - $this->plugin->setView($this->view); $this->plugin->setShare($this->share); $this->request->method('getMethod') @@ -174,7 +143,6 @@ class FilesDropPluginTest extends TestCase { public function testSubdirPut(): void { $this->plugin->enable(); - $this->plugin->setView($this->view); $this->plugin->setShare($this->share); $this->request->method('getMethod') @@ -193,14 +161,30 @@ class FilesDropPluginTest extends TestCase { $this->request->method('getBaseUrl') ->willReturn('https://example.com'); - $this->view->method('file_exists') - ->willReturnCallback(function ($path) { - if ($path === 'file.txt' || $path === '/folder/file.txt') { - return true; - } else { - return false; - } - }); + $nodeName = $this->createMock(Folder::class); + $nodeFolder = $this->createMock(Folder::class); + $nodeFolder->expects(self::once()) + ->method('getPath') + ->willReturn('/files/token/nickname/folder'); + $nodeFolder->method('getNonExistingName') + ->with('file.txt') + ->willReturn('file.txt'); + $nodeName->expects(self::once()) + ->method('get') + ->with('folder') + ->willThrowException(new NotFoundException()); + $nodeName->expects(self::once()) + ->method('newFolder') + ->with('folder') + ->willReturn($nodeFolder); + + $this->node->expects(self::once()) + ->method('get') + ->willThrowException(new NotFoundException()); + $this->node->expects(self::once()) + ->method('newFolder') + ->with('nickname') + ->willReturn($nodeName); $this->request->expects($this->once()) ->method('setUrl') @@ -211,7 +195,6 @@ class FilesDropPluginTest extends TestCase { public function testRecursiveFolderCreation(): void { $this->plugin->enable(); - $this->plugin->setView($this->view); $this->plugin->setShare($this->share); $this->request->method('getMethod') @@ -227,40 +210,40 @@ class FilesDropPluginTest extends TestCase { ->willReturn('/files/token/folder/subfolder/file.txt'); $this->request->method('getBaseUrl') ->willReturn('https://example.com'); - $this->view->method('file_exists') - ->willReturn(false); - - $this->view->expects($this->exactly(4)) - ->method('file_exists') - ->withConsecutive( - ['/nickname'], - ['/nickname/folder'], - ['/nickname/folder/subfolder'], - ['/nickname/folder/subfolder/file.txt'] - ) - ->willReturnOnConsecutiveCalls( - false, - false, - false, - false, - ); - $this->view->expects($this->exactly(3)) - ->method('mkdir') - ->withConsecutive( - ['/nickname'], - ['/nickname/folder'], - ['/nickname/folder/subfolder'], - ); $this->request->expects($this->once()) ->method('setUrl') ->with($this->equalTo('https://example.com/files/token/nickname/folder/subfolder/file.txt')); + + $subfolder = $this->createMock(Folder::class); + $subfolder->expects(self::once()) + ->method('getNonExistingName') + ->with('file.txt') + ->willReturn('file.txt'); + $subfolder->expects(self::once()) + ->method('getPath') + ->willReturn('/files/token/nickname/folder/subfolder'); + + $folder = $this->createMock(Folder::class); + $folder->expects(self::once()) + ->method('get') + ->with('subfolder') + ->willReturn($subfolder); + + $nickname = $this->createMock(Folder::class); + $nickname->expects(self::once()) + ->method('get') + ->with('folder') + ->willReturn($folder); + + $this->node->method('get') + ->with('nickname') + ->willReturn($nickname); $this->plugin->beforeMethod($this->request, $this->response); } public function testOnMkcol(): void { $this->plugin->enable(); - $this->plugin->setView($this->view); $this->plugin->setShare($this->share); $this->response->expects($this->once()) |