2015-08-07 10:04:27 -04:00
|
|
|
<?php
|
2024-05-28 06:34:11 -04:00
|
|
|
|
2015-08-07 10:04:27 -04:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-08-07 10:04:27 -04:00
|
|
|
*/
|
2016-05-25 10:04:15 -04:00
|
|
|
namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
|
2015-08-07 10:04:27 -04:00
|
|
|
|
2015-09-14 09:33:34 -04:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
|
use OCP\Lock\ILockingProvider;
|
2015-09-08 09:33:52 -04:00
|
|
|
|
2015-11-20 05:27:11 -05:00
|
|
|
/**
|
|
|
|
|
* Class UploadTest
|
|
|
|
|
*
|
|
|
|
|
* @group DB
|
|
|
|
|
*
|
2016-05-25 10:04:15 -04:00
|
|
|
* @package OCA\DAV\Tests\unit\Connector\Sabre\RequestTest
|
2015-11-20 05:27:11 -05:00
|
|
|
*/
|
2017-04-27 03:49:37 -04:00
|
|
|
class UploadTest extends RequestTestCase {
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testBasicUpload(): void {
|
2015-08-07 10:04:27 -04:00
|
|
|
$user = $this->getUniqueID();
|
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($view->file_exists('foo.txt'));
|
|
|
|
|
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
|
|
|
|
|
|
2015-09-08 09:33:52 -04:00
|
|
|
$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
|
2015-08-07 10:04:27 -04:00
|
|
|
$this->assertTrue($view->file_exists('foo.txt'));
|
|
|
|
|
$this->assertEquals('asd', $view->file_get_contents('foo.txt'));
|
2015-08-12 09:18:30 -04:00
|
|
|
|
|
|
|
|
$info = $view->getFileInfo('foo.txt');
|
|
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $info);
|
|
|
|
|
$this->assertEquals(3, $info->getSize());
|
2015-08-07 10:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testUploadOverWrite(): void {
|
2015-08-07 10:04:27 -04:00
|
|
|
$user = $this->getUniqueID();
|
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
2015-08-12 09:18:30 -04:00
|
|
|
$view->file_put_contents('foo.txt', 'foobar');
|
2015-08-07 10:04:27 -04:00
|
|
|
|
|
|
|
|
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
|
|
|
|
|
|
2015-09-08 09:33:52 -04:00
|
|
|
$this->assertEquals(Http::STATUS_NO_CONTENT, $response->getStatus());
|
2015-08-07 10:04:27 -04:00
|
|
|
$this->assertEquals('asd', $view->file_get_contents('foo.txt'));
|
2015-08-12 09:18:30 -04:00
|
|
|
|
|
|
|
|
$info = $view->getFileInfo('foo.txt');
|
|
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $info);
|
|
|
|
|
$this->assertEquals(3, $info->getSize());
|
2015-08-07 10:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testUploadOverWriteReadLocked(): void {
|
2015-09-14 09:33:34 -04:00
|
|
|
$user = $this->getUniqueID();
|
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
|
|
|
|
$view->file_put_contents('foo.txt', 'bar');
|
|
|
|
|
|
|
|
|
|
$view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);
|
|
|
|
|
|
2018-11-04 07:21:34 -05:00
|
|
|
$result = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
|
|
|
|
|
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
|
2015-09-14 09:33:34 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testUploadOverWriteWriteLocked(): void {
|
2015-09-14 09:33:34 -04:00
|
|
|
$user = $this->getUniqueID();
|
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
2016-09-23 11:21:07 -04:00
|
|
|
$this->loginAsUser($user);
|
2015-09-14 09:33:34 -04:00
|
|
|
|
|
|
|
|
$view->file_put_contents('foo.txt', 'bar');
|
|
|
|
|
|
|
|
|
|
$view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);
|
|
|
|
|
|
2018-11-04 07:21:34 -05:00
|
|
|
$result = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
|
|
|
|
|
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
|
2015-09-14 09:33:34 -04:00
|
|
|
}
|
2015-08-07 10:04:27 -04:00
|
|
|
}
|