diff --git a/lib/DAV/Server.php b/lib/DAV/Server.php index 09760e9d11..8b3b580c51 100644 --- a/lib/DAV/Server.php +++ b/lib/DAV/Server.php @@ -1639,6 +1639,8 @@ public function getResourceTypeForNode(INode $node) */ public function generateMultiStatus($fileProperties, $strip404s = false) { + $this->emit('beforeMultiStatus', [&$fileProperties]); + $w = $this->xml->getWriter(); $w->openMemory(); $w->contextUri = $this->baseUri; diff --git a/tests/Sabre/DAV/ServerEventsTest.php b/tests/Sabre/DAV/ServerEventsTest.php index 7d55ea02ed..fd8bc6b55a 100644 --- a/tests/Sabre/DAV/ServerEventsTest.php +++ b/tests/Sabre/DAV/ServerEventsTest.php @@ -14,6 +14,8 @@ class ServerEventsTest extends AbstractServer private $exception; + private $fileProperties; + public function testAfterBind() { $this->server->on('afterBind', [$this, 'afterBindHandler']); @@ -113,4 +115,39 @@ public function testMethod() // Fun fact, PHP 7.1 changes the order when sorting-by-callback. $this->assertTrue($k >= 2 && $k <= 3); } + + public function multiStatusHandler(&$fileProperties) + { + $this->fileProperties = $fileProperties; + $fileProperties = array_slice($fileProperties, 0, 1); + } + + public function testBeforeMultiStatus() + { + $this->server->on('beforeMultiStatus', [$this, 'multiStatusHandler']); + + $response = $this->server->generateMultiStatus([ + [ + 'href' => 'foo', + '200' => [ + 'd:getcontentlength' => 10, + ], + ], + [ + 'href' => 'bar', + '200' => [ + 'd:getcontentlength' => 11, + ], + ], + ]); + + $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $response); + $xml = simplexml_load_string($body); + $xml->registerXPathNamespace('d', 'urn:DAV'); + + $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength'); + $this->assertCount(1, $data); + + $this->assertCount(2, $this->fileProperties); + } }