Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/DAV/PropFind.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public function __construct($path, array $properties, $depth = 0, $requestType =
'{DAV:}getlastmodified',
'{DAV:}getcontentlength',
'{DAV:}resourcetype',
'{DAV:}quota-used-bytes',
'{DAV:}quota-available-bytes',
'{DAV:}getetag',
'{DAV:}getcontenttype',
];
Expand Down
31 changes: 31 additions & 0 deletions tests/Sabre/DAV/Mock/QuotaCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Sabre\DAV\Mock;

use Sabre\DAV;

/**
* Mock Collection with Quota support.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Aleksander Machniak
* @license http://sabre.io/license/ Modified BSD License
*/
class QuotaCollection extends Collection implements DAV\IQuota
{
public $available = 0;
public $used = 0;

/**
* Returns the quota information.
*
* This method MUST return an array with 2 values, the first being the total used space,
* the second the available space (in bytes)
*/
public function getQuotaInfo()
{
return [$this->used, $this->available];
}
}
79 changes: 79 additions & 0 deletions tests/Sabre/DAV/PropFindQuotaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace Sabre\DAV;

use Sabre\AbstractDAVServerTestCase;
use Sabre\HTTP;

class PropFindQuotaTest extends AbstractDAVServerTestCase
{
/**
* Sets up the DAV tree.
*/
public function setUpTree()
{
$this->tree = new Mock\QuotaCollection('root', [
'file1' => 'foo',
new Mock\Collection('dir', []),
]);
}

public function testPropFindAllprops()
{
$request = new HTTP\Request('PROPFIND', '/', ['Depth' => 0]);
$response = $this->request($request);

$xml = $response->getBodyAsString();

self::assertSame(207, $response->getStatus());
self::assertTrue(false === strpos($xml, 'quota-used-bytes'));
self::assertTrue(false === strpos($xml, 'quota-available-bytes'));
}

public function testPropFindQuotaProps()
{
$this->tree->available = 123456789;
$this->tree->used = 98765;

$xml = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:">
<d:prop>
<d:quota-used-bytes />
<d:quota-available-bytes />
</d:prop>
</d:propfind>';

$request = new HTTP\Request('PROPFIND', '/', ['Depth' => 0], $xml);
$response = $this->request($request);

$xml = $response->getBodyAsString();

self::assertSame(207, $response->getStatus());
self::assertTrue(strpos($xml, '<d:quota-used-bytes>98765</d:quota-used-bytes>') > 0);
self::assertTrue(strpos($xml, '<d:quota-available-bytes>123456789</d:quota-available-bytes>') > 0);
}

public function testPropFindQuotaPropsNotFound()
{
$xml = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:">
<d:prop>
<d:quota-used-bytes />
<d:quota-available-bytes />
</d:prop>
</d:propfind>';

// Requested location does not implement iQuota interface
$request = new HTTP\Request('PROPFIND', '/dir', ['Depth' => 0], $xml);
$response = $this->request($request);

$xml = $response->getBodyAsString();

self::assertSame(207, $response->getStatus());
$expected = '<d:propstat><d:prop><d:quota-used-bytes/><d:quota-available-bytes/></d:prop>'
.'<d:status>HTTP/1.1 404 Not Found</d:status></d:propstat>';
self::assertTrue(strpos($xml, $expected) > 0);
}
}