function testConvertDAVNamespaceMixedQuotes() { $xml = '<?xml version="1.0"?><document xmlns=\'DAV:" xmlns="Another attribute\'>blablabla</document>'; $this->assertEquals($xml, Sabre_DAV_XMLUtil::convertDAVNamespace($xml)); }
/** * @depends testSupportedReportSetProperty * @depends testCalendarMultiGetReport */ function testCalendarQueryReport1ObjectNoCalData() { $body = '<?xml version="1.0"?>' . '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' . '<d:prop>' . ' <d:getetag />' . '</d:prop>' . '<c:filter>' . ' <c:comp-filter name="VCALENDAR">' . ' <c:comp-filter name="VEVENT" />' . ' </c:comp-filter>' . '</c:filter>' . '</c:calendar-query>'; $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/calendars/user1/UUID-123467/UUID-2345', 'HTTP_DEPTH' => '0')); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body); $xml = simplexml_load_string(Sabre_DAV_XMLUtil::convertDAVNamespace($this->response->body)); $xml->registerXPathNamespace('d', 'urn:DAV'); $xml->registerXPathNamespace('c', 'urn:ietf:params:xml:ns:caldav'); $check = array('/d:multistatus', '/d:multistatus/d:response', '/d:multistatus/d:response/d:href', '/d:multistatus/d:response/d:propstat', '/d:multistatus/d:response/d:propstat/d:prop', '/d:multistatus/d:response/d:propstat/d:prop/d:getetag', '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK'); foreach ($check as $v1 => $v2) { $xpath = is_int($v1) ? $v2 : $v1; $result = $xml->xpath($xpath); $this->assertEquals(1, count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body); if (!is_int($v1)) { $this->assertEquals($v2, (string) $result[0]); } } }
/** * Parses a webdav lock xml body, and returns a new Sabre_DAV_Locks_LockInfo object * * @param string $body * @return Sabre_DAV_Locks_LockInfo */ protected function parseLockRequest($body) { $xml = simplexml_load_string(Sabre_DAV_XMLUtil::convertDAVNamespace($body), null, LIBXML_NOWARNING); $xml->registerXPathNamespace('d', 'urn:DAV'); $lockInfo = new Sabre_DAV_Locks_LockInfo(); $children = $xml->children("urn:DAV"); $lockInfo->owner = (string) $children->owner; $lockInfo->token = Sabre_DAV_UUIDUtil::getUUID(); $lockInfo->scope = count($xml->xpath('d:lockscope/d:exclusive')) > 0 ? Sabre_DAV_Locks_LockInfo::EXCLUSIVE : Sabre_DAV_Locks_LockInfo::SHARED; return $lockInfo; }
/** * Parses a WebDAV multistatus response body * * This method returns an array with the following structure * * array( * 'url/to/resource' => array( * '200' => array( * '{DAV:}property1' => 'value1', * '{DAV:}property2' => 'value2', * ), * '404' => array( * '{DAV:}property1' => null, * '{DAV:}property2' => null, * ), * ) * 'url/to/resource2' => array( * .. etc .. * ) * ) * * * @param string $body xml body * @return array */ public function parseMultiStatus($body) { $body = Sabre_DAV_XMLUtil::convertDAVNamespace($body); $responseXML = simplexml_load_string($body, null, LIBXML_NOBLANKS | LIBXML_NOCDATA); if ($responseXML === false) { throw new InvalidArgumentException('The passed data is not valid XML'); } $responseXML->registerXPathNamespace('d', 'urn:DAV'); $propResult = array(); foreach ($responseXML->xpath('d:response') as $response) { $response->registerXPathNamespace('d', 'urn:DAV'); $href = $response->xpath('d:href'); $href = (string) $href[0]; $properties = array(); foreach ($response->xpath('d:propstat') as $propStat) { $propStat->registerXPathNamespace('d', 'urn:DAV'); $status = $propStat->xpath('d:status'); list($httpVersion, $statusCode, $message) = explode(' ', (string) $status[0], 3); $properties[$statusCode] = Sabre_DAV_XMLUtil::parseProperties(dom_import_simplexml($propStat), $this->propertyMap); } $propResult[$href] = $properties; } return $propResult; }