5 require_once 'Sabre/CalDAV/TestUtil.php';
6 require_once 'Sabre/DAV/Auth/MockBackend.php';
7 require_once 'Sabre/HTTP/ResponseMock.php';
9 class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase {
13 $p = new Sabre_CalDAV_ICSExportPlugin();
14 $s = new Sabre_DAV_Server();
19 function testBeforeMethod() {
21 if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
22 $cbackend = Sabre_CalDAV_TestUtil::getBackend();
23 $pbackend = new Sabre_DAVACL_MockPrincipalBackend();
27 'principaluri' => 'admin',
31 new Sabre_CalDAV_Calendar($pbackend,$cbackend,$props),
34 $p = new Sabre_CalDAV_ICSExportPlugin();
36 $s = new Sabre_DAV_Server($tree);
38 $s->addPlugin(new Sabre_CalDAV_Plugin());
40 $h = new Sabre_HTTP_Request(array(
41 'QUERY_STRING' => 'export',
45 $s->httpResponse = new Sabre_HTTP_ResponseMock();
47 $this->assertFalse($p->beforeMethod('GET','UUID-123467?export'));
49 $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status);
50 $this->assertEquals(array(
51 'Content-Type' => 'text/calendar',
52 ), $s->httpResponse->headers);
54 $obj = VObject\Reader::read($s->httpResponse->body);
56 $this->assertEquals(5,count($obj->children()));
57 $this->assertEquals(1,count($obj->VERSION));
58 $this->assertEquals(1,count($obj->CALSCALE));
59 $this->assertEquals(1,count($obj->PRODID));
60 $this->assertTrue(strpos((string)$obj->PRODID, Sabre_DAV_Version::VERSION)!==false);
61 $this->assertEquals(1,count($obj->VTIMEZONE));
62 $this->assertEquals(1,count($obj->VEVENT));
65 function testBeforeMethodNoVersion() {
67 if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
68 $cbackend = Sabre_CalDAV_TestUtil::getBackend();
69 $pbackend = new Sabre_DAVACL_MockPrincipalBackend();
73 'principaluri' => 'admin',
77 new Sabre_CalDAV_Calendar($pbackend,$cbackend,$props),
80 $p = new Sabre_CalDAV_ICSExportPlugin();
82 $s = new Sabre_DAV_Server($tree);
85 $s->addPlugin(new Sabre_CalDAV_Plugin());
87 $h = new Sabre_HTTP_Request(array(
88 'QUERY_STRING' => 'export',
92 $s->httpResponse = new Sabre_HTTP_ResponseMock();
94 Sabre_DAV_Server::$exposeVersion = false;
95 $this->assertFalse($p->beforeMethod('GET','UUID-123467?export'));
96 Sabre_DAV_Server::$exposeVersion = true;
98 $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status);
99 $this->assertEquals(array(
100 'Content-Type' => 'text/calendar',
101 ), $s->httpResponse->headers);
103 $obj = VObject\Reader::read($s->httpResponse->body);
105 $this->assertEquals(5,count($obj->children()));
106 $this->assertEquals(1,count($obj->VERSION));
107 $this->assertEquals(1,count($obj->CALSCALE));
108 $this->assertEquals(1,count($obj->PRODID));
109 $this->assertFalse(strpos((string)$obj->PRODID, Sabre_DAV_Version::VERSION)!==false);
110 $this->assertEquals(1,count($obj->VTIMEZONE));
111 $this->assertEquals(1,count($obj->VEVENT));
115 function testBeforeMethodNoGET() {
117 $p = new Sabre_CalDAV_ICSExportPlugin();
119 $s = new Sabre_DAV_Server();
122 $this->assertNull($p->beforeMethod('POST','UUID-123467?export'));
126 function testBeforeMethodNoExport() {
128 $p = new Sabre_CalDAV_ICSExportPlugin();
130 $s = new Sabre_DAV_Server();
133 $this->assertNull($p->beforeMethod('GET','UUID-123467'));
138 * @expectedException Sabre_DAVACL_Exception_NeedPrivileges
140 function testACLIntegrationBlocked() {
142 if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
143 $cbackend = Sabre_CalDAV_TestUtil::getBackend();
144 $pbackend = new Sabre_DAVACL_MockPrincipalBackend();
147 'uri'=>'UUID-123467',
148 'principaluri' => 'admin',
152 new Sabre_CalDAV_Calendar($pbackend,$cbackend,$props),
155 $p = new Sabre_CalDAV_ICSExportPlugin();
157 $s = new Sabre_DAV_Server($tree);
159 $s->addPlugin(new Sabre_CalDAV_Plugin());
160 $s->addPlugin(new Sabre_DAVACL_Plugin());
162 $h = new Sabre_HTTP_Request(array(
163 'QUERY_STRING' => 'export',
166 $s->httpRequest = $h;
167 $s->httpResponse = new Sabre_HTTP_ResponseMock();
169 $p->beforeMethod('GET','UUID-123467?export');
173 function testACLIntegrationNotBlocked() {
175 if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
176 $cbackend = Sabre_CalDAV_TestUtil::getBackend();
177 $pbackend = new Sabre_DAVACL_MockPrincipalBackend();
180 'uri'=>'UUID-123467',
181 'principaluri' => 'admin',
185 new Sabre_CalDAV_Calendar($pbackend,$cbackend,$props),
186 new Sabre_DAVACL_PrincipalCollection($pbackend),
189 $p = new Sabre_CalDAV_ICSExportPlugin();
191 $s = new Sabre_DAV_Server($tree);
193 $s->addPlugin(new Sabre_CalDAV_Plugin());
194 $s->addPlugin(new Sabre_DAVACL_Plugin());
195 $s->addPlugin(new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(),'SabreDAV'));
198 $s->getPlugin('acl')->adminPrincipals = array('principals/admin');
200 $h = new Sabre_HTTP_Request(array(
201 'QUERY_STRING' => 'export',
202 'REQUEST_URI' => '/UUID-123467',
203 'REQUEST_METHOD' => 'GET',
206 $s->httpRequest = $h;
207 $s->httpResponse = new Sabre_HTTP_ResponseMock();
211 $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
212 $this->assertEquals(array(
213 'Content-Type' => 'text/calendar',
214 ), $s->httpResponse->headers);
216 $obj = VObject\Reader::read($s->httpResponse->body);
218 $this->assertEquals(5,count($obj->children()));
219 $this->assertEquals(1,count($obj->VERSION));
220 $this->assertEquals(1,count($obj->CALSCALE));
221 $this->assertEquals(1,count($obj->PRODID));
222 $this->assertEquals(1,count($obj->VTIMEZONE));
223 $this->assertEquals(1,count($obj->VEVENT));