Skip to content

Commit

Permalink
feat: return PROPFIND properties indexed by status
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Dec 11, 2023
1 parent 985e810 commit eece860
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 65 deletions.
14 changes: 3 additions & 11 deletions lib/DAV/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,11 @@ public function propFindUnfiltered($url, array $properties, $depth = 0)
// If depth was 0, we only return the top item
if (0 === $depth) {
reset($result);
$statusList = current($result);
foreach ($statusList as $statusCode => $associatedProperties) {
$newResult[] = ['properties' => $associatedProperties, 'status' => $statusCode];
}

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

return $newResult;
}

/**
Expand Down
81 changes: 27 additions & 54 deletions tests/Sabre/DAV/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,12 @@ public function testPropFindUnfilteredDepth0()
$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',
],
'status' => 200,
200 => [
'{DAV:}resourcetype' => new Xml\Property\ResourceType('{DAV:}collection'),
'{DAV:}displayname' => 'Folder1',
],
[
'properties' => [
'{DAV:}contentlength' => null,
],
'status' => 404,
404 => [
'{DAV:}contentlength' => null,
],
], $result);

Expand Down Expand Up @@ -424,63 +418,42 @@ public function testPropFindUnfiltered()

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

0 comments on commit eece860

Please sign in to comment.