]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/Property/SupportedReportSetTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / Property / SupportedReportSetTest.php
1 <?php
2
3 require_once 'Sabre/HTTP/ResponseMock.php';
4 require_once 'Sabre/DAV/AbstractServer.php';
5
6 class Sabre_DAV_Property_SupportedReportSetTest extends Sabre_DAV_AbstractServer {
7
8     public function sendPROPFIND($body) {
9
10         $serverVars = array(
11             'REQUEST_URI'    => '/',
12             'REQUEST_METHOD' => 'PROPFIND',
13             'HTTP_DEPTH'          => '0',
14         );
15
16         $request = new Sabre_HTTP_Request($serverVars);
17         $request->setBody($body);
18
19         $this->server->httpRequest = ($request);
20         $this->server->exec();
21
22     }
23
24     /**
25      * @covers Sabre_DAV_Property_SupportedReportSet
26      */
27     function testNoReports() {
28
29         $xml = '<?xml version="1.0"?>
30 <d:propfind xmlns:d="DAV:">
31   <d:prop>
32     <d:supported-report-set />
33   </d:prop>
34 </d:propfind>';
35
36         $this->sendPROPFIND($xml);
37
38         $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body);
39
40         $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body);
41         $xml = simplexml_load_string($body);
42         $xml->registerXPathNamespace('d','urn:DAV');
43
44         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
45         $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element');
46
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');
49
50         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
51         $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element');
52
53         $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200');
54
55     }
56
57     /**
58      * @covers Sabre_DAV_Property_SupportedReportSet
59      * @depends testNoReports
60      */
61     function testCustomReport() {
62
63         // Intercepting the report property
64         $this->server->subscribeEvent('afterGetProperties',array($this,'addProp'));
65
66         $xml = '<?xml version="1.0"?>
67 <d:propfind xmlns:d="DAV:">
68   <d:prop>
69     <d:supported-report-set />
70   </d:prop>
71 </d:propfind>';
72
73         $this->sendPROPFIND($xml);
74
75         $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body);
76
77         $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body);
78         $xml = simplexml_load_string($body);
79         $xml->registerXPathNamespace('d','urn:DAV');
80         $xml->registerXPathNamespace('x','http://www.rooftopsolutions.nl/testnamespace');
81
82         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
83         $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element');
84
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');
87
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');
90
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');
93
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);
96
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);
99
100         $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
101         $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element');
102
103         $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200');
104
105     }
106
107     /**
108      * This method is used as a callback for afterGetProperties
109      */
110     function addProp($path, &$properties) {
111
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');
115         }
116
117     }
118
119
120
121 }
122
123 ?>