/** * Unserializes the property. * * This static method should return a an instance of this object. * * @param \DOMElement $prop * @param array $propertyMap * @return DAV\IProperty */ static function unserialize(\DOMElement $prop, array $propertyMap) { // Delegating this to the ResponseList property. It does make more // sense there. $result = ResponseList::unserialize($prop, $propertyMap); $result = $result->getResponses(); return $result[0]; }
public function testSubsequentSyncSyncCollectionDepthFallBack() { // Making a change $this->collection->addChange(['file1.txt'], [], []); // Making another change $this->collection->addChange([], ['file2.txt'], ['file3.txt']); $request = HTTP\Sapi::createFromServerArray(['REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/coll/', 'CONTENT_TYPE' => 'application/xml', 'HTTP_DEPTH' => "1"]); $body = <<<BLA <?xml version="1.0" encoding="utf-8" ?> <D:sync-collection xmlns:D="DAV:"> <D:sync-token>http://sabre.io/ns/sync/1</D:sync-token> <D:prop> <D:getcontentlength/> </D:prop> </D:sync-collection> BLA; $request->setBody($body); $response = $this->request($request); $this->assertEquals(207, $response->status, 'Full response body:' . $response->body); $dom = DAV\XMLUtil::loadDOMDocument($response->body); // Checking the sync-token $this->assertEquals('http://sabre.io/ns/sync/2', $dom->getElementsByTagNameNS('urn:DAV', 'sync-token')->item(0)->nodeValue); $responses = DAV\Property\ResponseList::unserialize($dom->documentElement, []); $responses = $responses->getResponses(); $this->assertEquals(2, count($responses), 'We expected exactly 2 {DAV:}response'); $response = $responses[0]; $this->assertNull($response->getHttpStatus()); $this->assertEquals('/coll/file2.txt', $response->getHref()); $this->assertEquals([200 => ['{DAV:}getcontentlength' => 3]], $response->getResponseProperties()); $response = $responses[1]; $this->assertEquals('404', $response->getHttpStatus()); $this->assertEquals('/coll/file3.txt', $response->getHref()); $this->assertEquals([], $response->getResponseProperties()); }
/** * Parses a WebDAV multistatus response body * * This method returns an array with the following structure * * [ * 'url/to/resource' => [ * '200' => [ * '{DAV:}property1' => 'value1', * '{DAV:}property2' => 'value2', * ], * '404' => [ * '{DAV:}property1' => null, * '{DAV:}property2' => null, * ], * ], * 'url/to/resource2' => [ * .. etc .. * ] * ] * * * @param string $body xml body * @return array */ function parseMultiStatus($body) { try { $dom = XMLUtil::loadDOMDocument($body); } catch (Exception\BadRequest $e) { throw new \InvalidArgumentException('The body passed to parseMultiStatus could not be parsed. Is it really xml?'); } $responses = Property\ResponseList::unserialize($dom->documentElement, $this->propertyMap); $result = []; foreach ($responses->getResponses() as $response) { $result[$response->getHref()] = $response->getResponseProperties(); } return $result; }
function testCalendarQueryDepth0() { $xml = <<<XML <?xml version="1.0"?> <c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> <d:prop> <c:calendar-data content-type="application/calendar+json" /> </d:prop> <c:filter> <c:comp-filter name="VCALENDAR" /> </c:filter> </c:calendar-query> XML; $headers = ['Depth' => '0']; $request = new Request('REPORT', '/calendars/user1/foo/bar.ics', $headers, $xml); $response = $this->request($request); $this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString()); $body = $response->getBodyAsString(); // Getting from the xml body to the actual returned data is // unfortunately very convoluted. $responses = \Sabre\DAV\Property\ResponseList::unserialize(\Sabre\DAV\XMLUtil::loadDOMDocument($body)->firstChild, $this->server->propertyMap); $responses = $responses->getResponses(); $this->assertEquals(1, count($responses)); $response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"]; $response = json_decode($response, true); if (json_last_error()) { $this->fail('Json decoding error: ' . json_last_error_msg()); } $this->assertEquals(['vcalendar', [], [['vevent', [], []]]], $response); }