diff --git a/lib/DAV/Client.php b/lib/DAV/Client.php index 027aa0d6de..03b98b11d7 100644 --- a/lib/DAV/Client.php +++ b/lib/DAV/Client.php @@ -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; diff --git a/tests/Sabre/DAV/ClientTest.php b/tests/Sabre/DAV/ClientTest.php index a63184fe65..9353b691b7 100644 --- a/tests/Sabre/DAV/ClientTest.php +++ b/tests/Sabre/DAV/ClientTest.php @@ -296,19 +296,33 @@ public function testPropFindUnfilteredDepth0() HTTP/1.1 200 OK + + + + + HTTP/1.1 404 Not Found + 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; @@ -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);