2015-09-14 13:34:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2015-10-14 12:57:23 +00:00
|
|
|
namespace OCA\DAV\Tests\Unit\Connector\Sabre\RequestTest;
|
2015-09-14 13:34:28 +00:00
|
|
|
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\Lock\ILockingProvider;
|
|
|
|
|
2015-11-20 10:27:11 +00:00
|
|
|
/**
|
|
|
|
* Class DownloadTest
|
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package OCA\DAV\Tests\Unit\Connector\Sabre\RequestTest
|
|
|
|
*/
|
2015-09-14 13:34:28 +00:00
|
|
|
class DownloadTest extends RequestTest {
|
|
|
|
public function testDownload() {
|
|
|
|
$user = $this->getUniqueID();
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
|
|
$view->file_put_contents('foo.txt', 'bar');
|
|
|
|
|
|
|
|
$response = $this->request($view, $user, 'pass', 'GET', '/foo.txt');
|
|
|
|
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
|
|
|
|
$this->assertEquals(stream_get_contents($response->getBody()), 'bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-14 12:57:23 +00:00
|
|
|
* @expectedException \OCA\DAV\Connector\Sabre\Exception\FileLocked
|
2015-09-14 13:34:28 +00:00
|
|
|
*/
|
|
|
|
public function testDownloadWriteLocked() {
|
|
|
|
$user = $this->getUniqueID();
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
|
|
$view->file_put_contents('foo.txt', 'bar');
|
|
|
|
|
|
|
|
$view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);
|
|
|
|
|
|
|
|
$this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDownloadReadLocked() {
|
|
|
|
$user = $this->getUniqueID();
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
|
|
$view->file_put_contents('foo.txt', 'bar');
|
|
|
|
|
|
|
|
$view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);
|
|
|
|
|
|
|
|
$response = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
|
|
|
|
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
|
|
|
|
$this->assertEquals(stream_get_contents($response->getBody()), 'bar');
|
|
|
|
}
|
|
|
|
}
|