Skip to content

Commit

Permalink
Preserve backward-compatibility of client propFind
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Dec 11, 2023
1 parent 72548b7 commit db80aae
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/DAV/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function __construct(array $settings)
*
* @param 1|0 $depth
*/
public function propFind(string $url, array $properties, int $depth = 0): array
public function propFind($url, array $properties, $depth = 0): array
{
$result = $this->doPropFind($url, $properties, $depth);

Expand Down Expand Up @@ -265,7 +265,7 @@ public function propFindUnfiltered(string $url, array $properties, int $depth =
*
* @param 1|0 $depth
*/
private function doPropFind(string $url, array $properties, int $depth = 0): array
private function doPropFind($url, array $properties, $depth = 0): array
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
Expand Down Expand Up @@ -441,7 +441,7 @@ public function getAbsoluteUrl($url)
{
return Uri\resolve(
$this->baseUri,
$url
(string) $url
);
}

Expand Down
51 changes: 49 additions & 2 deletions tests/Sabre/DAV/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,41 @@ public function testPropFind()
], $request->getHeaders());
}

public function testPropFindWithIntegerUrl()
{
$client = new ClientMock([
'baseUri' => '/',
]);

$responseBody = <<<XML
<?xml version="1.0"?>
<multistatus xmlns="DAV:">
<response>
<href>/123456</href>
<propstat>
<prop>
<displayname>bar</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>
XML;

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

self::assertEquals(['{DAV:}displayname' => 'bar'], $result);

$request = $client->request;
self::assertEquals('PROPFIND', $request->getMethod());
self::assertEquals('/123456', $request->getUrl());
self::assertEquals([
'Depth' => ['0'],
'Content-Type' => ['application/xml'],
], $request->getHeaders());
}

public function testPropFindError()
{
$this->expectException('Sabre\HTTP\ClientHttpException');
Expand All @@ -146,7 +181,19 @@ public function testPropFindError()
$client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir']);
}

public function testPropFindDepth1()
public function depthProvider(): array
{
return [
['1'],
[1],
];
}

/**
* @param int|string $depth
* @dataProvider depthProvider
*/
public function testPropFindDepth1($depth)
{
$client = new ClientMock([
'baseUri' => '/',
Expand All @@ -168,7 +215,7 @@ public function testPropFindDepth1()
XML;

$client->response = new Response(207, [], $responseBody);
$result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir'], 1);
$result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir'], $depth);

self::assertEquals([
'/foo' => [
Expand Down

0 comments on commit db80aae

Please sign in to comment.