|
|
|
|
@ -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())
|
|
|
|
|
|