Skip to content

Commit

Permalink
feat: return all property-status combinations from PROPFIND
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Nov 24, 2023
1 parent 68e2ad4 commit 2f6266b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 38 deletions.
21 changes: 11 additions & 10 deletions lib/DAV/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,21 @@ public function propFind($url, array $properties, $depth = 0)
public function propFindUnfiltered($url, array $properties, $depth = 0)
{
$result = $this->doPropFind($url, $properties, $depth);
$newResult = [];

// If depth was 0, we only return the top item
if (0 === $depth) {
reset($result);
$resourceStatusList = current($result);
reset($resourceStatusList);

return ['properties' => current($resourceStatusList), 'status' => key($resourceStatusList)];
}

$newResult = [];
foreach ($result as $href => $statusList) {
reset($statusList);
$newResult[$href] = ['properties' => current($statusList), 'status' => key($statusList)];
$statusList = current($result);
foreach ($statusList as $statusCode => $associatedProperties) {
$newResult[] = ['properties' => $associatedProperties, 'status' => $statusCode];
}
} else {
foreach ($result as $href => $statusList) {
foreach ($statusList as $statusCode => $associatedProperties) {
$newResult[$href][] = ['properties' => $associatedProperties, 'status' => $statusCode];
}
}
}

return $newResult;
Expand Down
92 changes: 64 additions & 28 deletions tests/Sabre/DAV/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,33 @@ public function testPropFindUnfilteredDepth0()
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
<d:propstat>
<d:prop>
<d:contentlength></d:contentlength>
</d:prop>
<d:status>HTTP/1.1 404 Not Found</d:status>
</d:propstat>
</d:response>
</d:multistatus>
XML;

$client->response = new Response(207, [], $responseBody);
$result = $client->propFindUnfiltered('folder1', ['{DAV:}resourcetype', '{DAV:}displayname', '{urn:zim}gir']);
$result = $client->propFindUnfiltered('folder1', ['{DAV:}resourcetype', '{DAV:}displayname', '{DAV:}contentlength', '{urn:zim}gir']);

self::assertEquals([
'properties' => [
'{DAV:}resourcetype' => new Xml\Property\ResourceType('{DAV:}collection'),
'{DAV:}displayname' => 'Folder1',
[
'properties' => [
'{DAV:}resourcetype' => new Xml\Property\ResourceType('{DAV:}collection'),
'{DAV:}displayname' => 'Folder1',
],
'status' => 200,
],
[
'properties' => [
'{DAV:}contentlength' => null,
],
'status' => 404,
],
'status' => 200,
], $result);

$request = $client->request;
Expand Down Expand Up @@ -410,42 +424,64 @@ public function testPropFindUnfiltered()

self::assertEquals([
'/folder1' => [
'properties' => [
'{DAV:}resourcetype' => new Xml\Property\ResourceType('{DAV:}collection'),
'{DAV:}displayname' => 'Folder1',
[
'properties' => [
'{DAV:}resourcetype' => new Xml\Property\ResourceType('{DAV:}collection'),
'{DAV:}displayname' => 'Folder1',
],
'status' => 200,
],
[
'properties' => [
'{DAV:}contentlength' => null,
],
'status' => 404,
],
'status' => 200,
],
'/folder1/file1.txt' => [
'properties' => [
'{DAV:}resourcetype' => null,
'{DAV:}displayname' => 'File1',
'{DAV:}contentlength' => 12,
[
'properties' => [
'{DAV:}resourcetype' => null,
'{DAV:}displayname' => 'File1',
'{DAV:}contentlength' => 12,
],
'status' => 200,
],
'status' => 200,
],
'/folder1/file2.txt' => [
'properties' => [
'{DAV:}resourcetype' => null,
'{DAV:}displayname' => 'File2',
'{DAV:}contentlength' => 27,
[
'properties' => [
'{DAV:}resourcetype' => null,
'{DAV:}displayname' => 'File2',
'{DAV:}contentlength' => 27,
],
'status' => 403,
],
'status' => 403,
],
'/folder1/file3.txt' => [
'properties' => [
'{DAV:}resourcetype' => null,
'{DAV:}displayname' => 'File3',
'{DAV:}contentlength' => 42,
[
'properties' => [
'{DAV:}resourcetype' => null,
'{DAV:}displayname' => 'File3',
'{DAV:}contentlength' => 42,
],
'status' => 425,
],
'status' => 425,
],
'/folder1/subfolder' => [
'properties' => [
'{DAV:}resourcetype' => new Xml\Property\ResourceType('{DAV:}collection'),
'{DAV:}displayname' => 'SubFolder',
[
'properties' => [
'{DAV:}resourcetype' => new Xml\Property\ResourceType('{DAV:}collection'),
'{DAV:}displayname' => 'SubFolder',
],
'status' => 200,
],
[
'properties' => [
'{DAV:}contentlength' => null,
],
'status' => 404,
],
'status' => 200,
],
], $result);

Expand Down

0 comments on commit 2f6266b

Please sign in to comment.