3 require_once 'Sabre/HTTP/ResponseMock.php';
4 require_once 'Sabre/DAV/AbstractServer.php';
6 class Sabre_DAV_Property_SupportedReportSetTest extends Sabre_DAV_AbstractServer {
8 public function sendPROPFIND($body) {
12 'REQUEST_METHOD' => 'PROPFIND',
16 $request = new Sabre_HTTP_Request($serverVars);
17 $request->setBody($body);
19 $this->server->httpRequest = ($request);
20 $this->server->exec();
25 * @covers Sabre_DAV_Property_SupportedReportSet
27 function testNoReports() {
29 $xml = '<?xml version="1.0"?>
30 <d:propfind xmlns:d="DAV:">
32 <d:supported-report-set />
36 $this->sendPROPFIND($xml);
38 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body);
40 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"DAV:\"",$this->response->body);
41 $xml = simplexml_load_string($body);
42 $xml->registerXPathNamespace('d','DAV:');
44 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
45 $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element');
47 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set');
48 $this->assertEquals(1,count($data),'We expected 1 \'d:supported-report-set\' element');
50 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
51 $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element');
53 $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200');
58 * @covers Sabre_DAV_Property_SupportedReportSet
59 * @depends testNoReports
61 function testCustomReport() {
63 // Intercepting the report property
64 $this->server->subscribeEvent('afterGetProperties',array($this,'addProp'));
66 $xml = '<?xml version="1.0"?>
67 <d:propfind xmlns:d="DAV:">
69 <d:supported-report-set />
73 $this->sendPROPFIND($xml);
75 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body);
77 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"DAV:\"",$this->response->body);
78 $xml = simplexml_load_string($body);
79 $xml->registerXPathNamespace('d','DAV:');
80 $xml->registerXPathNamespace('x','http://www.rooftopsolutions.nl/testnamespace');
82 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
83 $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element');
85 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set');
86 $this->assertEquals(1,count($data),'We expected 1 \'d:supported-report-set\' element');
88 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report');
89 $this->assertEquals(2,count($data),'We expected 2 \'d:supported-report\' elements');
91 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report');
92 $this->assertEquals(2,count($data),'We expected 2 \'d:report\' elements');
94 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/x:myreport');
95 $this->assertEquals(1,count($data),'We expected 1 \'x:myreport\' element. Full body: ' . $this->response->body);
97 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/d:anotherreport');
98 $this->assertEquals(1,count($data),'We expected 1 \'d:anotherreport\' element. Full body: ' . $this->response->body);
100 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
101 $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element');
103 $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200');
108 * This method is used as a callback for afterGetProperties
110 function addProp($path, &$properties) {
112 if (isset($properties[200]['{DAV:}supported-report-set'])) {
113 $properties[200]['{DAV:}supported-report-set']->addReport('{http://www.rooftopsolutions.nl/testnamespace}myreport');
114 $properties[200]['{DAV:}supported-report-set']->addReport('{DAV:}anotherreport');