nextcloud/apps/dav/tests/unit/Connector/Sabre/RequestTest/UploadTest.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
2016-05-25 10:04:15 -04:00
namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
use OCP\AppFramework\Http;
use OCP\Lock\ILockingProvider;
2015-09-08 09:33:52 -04:00
/**
* Class UploadTest
*
* @group DB
*
2016-05-25 10:04:15 -04:00
* @package OCA\DAV\Tests\unit\Connector\Sabre\RequestTest
*/
class UploadTest extends RequestTestCase {
public function testBasicUpload(): void {
$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());
$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());
}
public function testUploadOverWrite(): void {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
2015-08-12 09:18:30 -04:00
$view->file_put_contents('foo.txt', 'foobar');
$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());
$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());
}
public function testUploadOverWriteReadLocked(): void {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'bar');
$view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);
$result = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
}
public function testUploadOverWriteWriteLocked(): void {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
$this->loginAsUser($user);
$view->file_put_contents('foo.txt', 'bar');
$view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);
$result = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
}
}