Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply support for large PROPFINDS to 3.2.2 #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions lib/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1645,42 +1645,43 @@ function getResourceTypeForNode(INode $node) {


/**
* Generates a WebDAV propfind response body based on a list of nodes.
* Returns a callback generating a WebDAV propfind response body based on a list of nodes.
*
* If 'strip404s' is set to true, all 404 responses will be removed.
*
* @param array|\Traversable $fileProperties The list with nodes
* @param bool $strip404s
* @return string
* @return callable
*/
function generateMultiStatus($fileProperties, $strip404s = false) {

$w = $this->xml->getWriter();
$w->openMemory();
$w->contextUri = $this->baseUri;
$w->startDocument();

$w->startElement('{DAV:}multistatus');

foreach ($fileProperties as $entry) {

$href = $entry['href'];
unset($entry['href']);
if ($strip404s) {
unset($entry[404]);
return function() use ($fileProperties, $strip404s, $w) {
$w->openUri('php://output');
$w->contextUri = $this->baseUri;
$w->startDocument();

$w->startElement('{DAV:}multistatus');

foreach ($fileProperties as $entry) {
$href = $entry['href'];
unset($entry['href']);
if ($strip404s) {
unset($entry[404]);
}
$response = new Xml\Element\Response(
ltrim($href, '/'),
$entry
);
$w->write([
'name' => '{DAV:}response',
'value' => $response
]);
}
$response = new Xml\Element\Response(
ltrim($href, '/'),
$entry
);
$w->write([
'name' => '{DAV:}response',
'value' => $response
]);
}
$w->endElement();

return $w->outputMemory();
$w->endElement();
$w->endDocument();
$w->flush();
};

}

Expand Down
8 changes: 5 additions & 3 deletions tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ function testExpand() {

$response = $this->request($request);

$bodyAsString = $response->getBodyAsString();

// Everts super awesome xml parser.
$body = substr(
$response->body,
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
strpos($response->body, 'END:VCALENDAR') - $start + 13
$bodyAsString,
$start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
);
$body = str_replace('
', '', $body);

Expand Down
8 changes: 5 additions & 3 deletions tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ function testExpandRecurringByDayEvent() {

$response = $this->request($request);

$bodyAsString = $response->getBodyAsString();

// Everts super awesome xml parser.
$body = substr(
$response->body,
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
strpos($response->body, 'END:VCALENDAR') - $start + 13
$bodyAsString,
$start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
);
$body = str_replace('
', '', $body);

Expand Down
8 changes: 5 additions & 3 deletions tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ function testExpand() {

$response = $this->request($request);

$bodyAsString = $response->getBodyAsString();

// Everts super awesome xml parser.
$body = substr(
$response->body,
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
strpos($response->body, 'END:VCALENDAR') - $start + 13
$bodyAsString,
$start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
);
$body = str_replace('
', '', $body);

Expand Down
24 changes: 15 additions & 9 deletions tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ function testExpandCalendarQuery() {

$response = $this->request($request);

$bodyAsString = $response->getBodyAsString();

// Everts super awesome xml parser.
$body = substr(
$response->body,
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
strpos($response->body, 'END:VCALENDAR') - $start + 13
$bodyAsString,
$start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
);
$body = str_replace('
', '', $body);

Expand Down Expand Up @@ -141,11 +143,13 @@ function testExpandMultiGet() {

$this->assertEquals(207, $response->getStatus());

$bodyAsString = $response->getBodyAsString();

// Everts super awesome xml parser.
$body = substr(
$response->body,
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
strpos($response->body, 'END:VCALENDAR') - $start + 13
$bodyAsString,
$start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
);
$body = str_replace('
', '', $body);

Expand Down Expand Up @@ -178,11 +182,13 @@ function testExpandExport() {

$this->assertEquals(200, $response->getStatus());

$bodyAsString = $response->getBodyAsString();

// Everts super awesome xml parser.
$body = substr(
$response->body,
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
strpos($response->body, 'END:VCALENDAR') - $start + 13
$bodyAsString,
$start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
);
$body = str_replace('
', '', $body);

Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/CalDAV/GetEventsByTimerangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function testQueryTimerange() {

$response = $this->request($request);

$this->assertTrue(strpos($response->body, 'BEGIN:VCALENDAR') !== false);
$this->assertTrue(strpos($response->getBodyAsString(), 'BEGIN:VCALENDAR') !== false);

}

Expand Down
8 changes: 5 additions & 3 deletions tests/Sabre/CalDAV/Issue203Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ function testIssue203() {

$response = $this->request($request);

$bodyAsString = $response->getBodyAsString();

// Everts super awesome xml parser.
$body = substr(
$response->body,
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
strpos($response->body, 'END:VCALENDAR') - $start + 13
$bodyAsString,
$start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
);
$body = str_replace('
', '', $body);

Expand Down
11 changes: 6 additions & 5 deletions tests/Sabre/CalDAV/Issue205Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ function testIssue205() {

$response = $this->request($request);

$this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
$this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
$bodyAsString = $response->getBodyAsString();
$this->assertFalse(strpos($bodyAsString, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $bodyAsString);
$this->assertFalse(strpos($bodyAsString, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $bodyAsString);

// Everts super awesome xml parser.
$body = substr(
$response->body,
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
strpos($response->body, 'END:VCALENDAR') - $start + 13
$bodyAsString,
$start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
);
$body = str_replace('&#13;', '', $body);

Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/CalDAV/Issue211Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function testIssue211() {

// if this assert is reached, the endless loop is gone
// There should be no matching events
$this->assertFalse(strpos('BEGIN:VEVENT', $response->body));
$this->assertFalse(strpos('BEGIN:VEVENT', $response->getBodyAsString()));

}
}
8 changes: 5 additions & 3 deletions tests/Sabre/CalDAV/Issue220Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ function testIssue220() {

$response = $this->request($request);

$this->assertFalse(strpos($response->body, '<s:exception>PHPUnit_Framework_Error_Warning</s:exception>'), 'Error Warning occurred: ' . $response->body);
$this->assertFalse(strpos($response->body, 'Invalid argument supplied for foreach()'), 'Invalid argument supplied for foreach(): ' . $response->body);
$body = $response->getBodyAsString();

$this->assertEquals(207, $response->status);
$this->assertFalse(strpos($body, '<s:exception>PHPUnit_Framework_Error_Warning</s:exception>'), 'Error Warning occurred: ' . $body);
$this->assertFalse(strpos($body, 'Invalid argument supplied for foreach()'), 'Invalid argument supplied for foreach(): ' . $body);

$this->assertEquals(207, $response->getStatus());
}
}
2 changes: 1 addition & 1 deletion tests/Sabre/CalDAV/Issue228Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function testIssue228() {
$response = $this->request($request);

// We must check if absolutely nothing was returned from this query.
$this->assertFalse(strpos($response->body, 'BEGIN:VCALENDAR'));
$this->assertFalse(strpos($response->getBodyAsString(), 'BEGIN:VCALENDAR'));

}
}
19 changes: 13 additions & 6 deletions tests/Sabre/CalDAV/JCalTransformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ function testMultiGet() {

$response = $this->request($request);

$this->assertEquals(207, $response->getStatus(), 'Full rsponse: ' . $response->getBodyAsString());
$body = $response->getBodyAsString();

$this->assertEquals(207, $response->getStatus(), 'Full rsponse: ' . $body);

$multiStatus = $this->server->xml->parse(
$response->getBodyAsString()
$body
);

$responses = $multiStatus->getResponses();
Expand Down Expand Up @@ -131,10 +133,12 @@ function testCalendarQueryDepth1() {

$response = $this->request($request);

$this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString());
$body = $response->getBodyAsString();

$this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $body);

$multiStatus = $this->server->xml->parse(
$response->getBodyAsString()
$body
);

$responses = $multiStatus->getResponses();
Expand Down Expand Up @@ -184,10 +188,13 @@ function testCalendarQueryDepth0() {

$response = $this->request($request);

$this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString());
$body = $response->getBodyAsString();

$this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $body);


$multiStatus = $this->server->xml->parse(
$response->getBodyAsString()
$body
);

$responses = $multiStatus->getResponses();
Expand Down
Loading