aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php544
1 files changed, 490 insertions, 54 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php
index be21796dd..c123bd0c1 100644
--- a/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php
+++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php
@@ -12,27 +12,36 @@ require_once 'Sabre/HTTP/ResponseMock.php';
class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
+ function setUp() {
+
+ if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
+
+ }
+
function testInit() {
$p = new ICSExportPlugin();
$s = new DAV\Server();
$s->addPlugin($p);
+ $this->assertEquals($p, $s->getPlugin('ics-export'));
+ $this->assertEquals('ics-export', $p->getPluginInfo()['name']);
}
function testBeforeMethod() {
- if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
$cbackend = TestUtil::getBackend();
- $props = array(
+ $props = [
'uri'=>'UUID-123467',
'principaluri' => 'admin',
'id' => 1,
- );
- $tree = array(
+ '{DAV:}displayname' => 'Hello!',
+ '{http://apple.com/ns/ical/}calendar-color' => '#AA0000FF',
+ ];
+ $tree = [
new Calendar($cbackend,$props),
- );
+ ];
$p = new ICSExportPlugin();
@@ -40,29 +49,32 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
$s->addPlugin($p);
$s->addPlugin(new Plugin());
- $h = new HTTP\Request(array(
- 'QUERY_STRING' => 'export',
- ));
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
$s->httpRequest = $h;
$s->httpResponse = new HTTP\ResponseMock();
- $this->assertFalse($p->beforeMethod('GET','UUID-123467?export'));
+ $this->assertFalse($p->httpGet($h, $s->httpResponse));
- $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status);
- $this->assertEquals(array(
- 'Content-Type' => 'text/calendar',
- ), $s->httpResponse->headers);
+ $this->assertEquals(200, $s->httpResponse->status);
+ $this->assertEquals([
+ 'Content-Type' => ['text/calendar'],
+ ], $s->httpResponse->getHeaders());
$obj = VObject\Reader::read($s->httpResponse->body);
- $this->assertEquals(5,count($obj->children()));
+ $this->assertEquals(7,count($obj->children()));
$this->assertEquals(1,count($obj->VERSION));
$this->assertEquals(1,count($obj->CALSCALE));
$this->assertEquals(1,count($obj->PRODID));
$this->assertTrue(strpos((string)$obj->PRODID, DAV\Version::VERSION)!==false);
$this->assertEquals(1,count($obj->VTIMEZONE));
$this->assertEquals(1,count($obj->VEVENT));
+ $this->assertEquals("Hello!", $obj->{"X-WR-CALNAME"});
+ $this->assertEquals("#AA0000FF", $obj->{"X-APPLE-CALENDAR-COLOR"});
}
function testBeforeMethodNoVersion() {
@@ -70,14 +82,14 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
$cbackend = TestUtil::getBackend();
- $props = array(
+ $props = [
'uri'=>'UUID-123467',
'principaluri' => 'admin',
'id' => 1,
- );
- $tree = array(
+ ];
+ $tree = [
new Calendar($cbackend,$props),
- );
+ ];
$p = new ICSExportPlugin();
@@ -86,21 +98,22 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
$s->addPlugin($p);
$s->addPlugin(new Plugin());
- $h = new HTTP\Request(array(
- 'QUERY_STRING' => 'export',
- ));
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
$s->httpRequest = $h;
$s->httpResponse = new HTTP\ResponseMock();
DAV\Server::$exposeVersion = false;
- $this->assertFalse($p->beforeMethod('GET','UUID-123467?export'));
+ $this->assertFalse($p->httpGet($h, $s->httpResponse));
DAV\Server::$exposeVersion = true;
- $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status);
- $this->assertEquals(array(
- 'Content-Type' => 'text/calendar',
- ), $s->httpResponse->headers);
+ $this->assertEquals(200, $s->httpResponse->status);
+ $this->assertEquals([
+ 'Content-Type' => ['text/calendar'],
+ ], $s->httpResponse->getHeaders());
$obj = VObject\Reader::read($s->httpResponse->body);
@@ -114,17 +127,6 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
}
- function testBeforeMethodNoGET() {
-
- $p = new ICSExportPlugin();
-
- $s = new DAV\Server();
- $s->addPlugin($p);
-
- $this->assertNull($p->beforeMethod('POST','UUID-123467?export'));
-
- }
-
function testBeforeMethodNoExport() {
$p = new ICSExportPlugin();
@@ -132,16 +134,16 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
$s = new DAV\Server();
$s->addPlugin($p);
- $this->assertNull($p->beforeMethod('GET','UUID-123467'));
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+ $this->assertNull($p->httpGet($h, $s->httpResponse));
}
- /**
- * @expectedException Sabre\DAVACL\Exception\NeedPrivileges
- */
function testACLIntegrationBlocked() {
- if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
$cbackend = TestUtil::getBackend();
$props = array(
@@ -160,20 +162,24 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
$s->addPlugin(new Plugin());
$s->addPlugin(new DAVACL\Plugin());
- $h = new HTTP\Request(array(
- 'QUERY_STRING' => 'export',
- ));
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export',
+ ]);
$s->httpRequest = $h;
$s->httpResponse = new HTTP\ResponseMock();
- $p->beforeMethod('GET','UUID-123467?export');
+ $p->httpGet($h, $s->httpResponse);
+
+ // If the ACL system blocked this request, the effect will be that
+ // there's no response, because the calendar information could not be
+ // fetched.
+ $this->assertNull($s->httpResponse->getStatus());
}
function testACLIntegrationNotBlocked() {
- if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
$cbackend = TestUtil::getBackend();
$pbackend = new DAVACL\PrincipalBackend\Mock();
@@ -190,6 +196,7 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
$p = new ICSExportPlugin();
$s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
$s->addPlugin($p);
$s->addPlugin(new Plugin());
$s->addPlugin(new DAVACL\Plugin());
@@ -198,21 +205,22 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
// Forcing login
$s->getPlugin('acl')->adminPrincipals = array('principals/admin');
- $h = new HTTP\Request(array(
- 'QUERY_STRING' => 'export',
- 'REQUEST_URI' => '/UUID-123467',
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export',
'REQUEST_METHOD' => 'GET',
- ));
+ ]);
$s->httpRequest = $h;
$s->httpResponse = new HTTP\ResponseMock();
$s->exec();
- $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+ $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
$this->assertEquals(array(
- 'Content-Type' => 'text/calendar',
- ), $s->httpResponse->headers);
+ 'X-Sabre-Version' => [DAV\Version::VERSION],
+ 'Content-Type' => ['text/calendar'],
+ ), $s->httpResponse->getHeaders());
$obj = VObject\Reader::read($s->httpResponse->body);
@@ -224,4 +232,432 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(1,count($obj->VEVENT));
}
+
+ function testBadStartParam() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&start=foo',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+
+ }
+
+ function testBadEndParam() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&end=foo',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+
+ }
+
+ function testFilterStartEnd() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&start=1&end=2',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+ $obj = VObject\Reader::read($s->httpResponse->body);
+
+ $this->assertEquals(0,count($obj->VTIMEZONE));
+ $this->assertEquals(0,count($obj->VEVENT));
+
+ }
+
+ function testExpandNoStart() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&expand=1&end=1',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+
+ }
+
+ function testExpand() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&start=1&end=2000000000&expand=1',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+ $obj = VObject\Reader::read($s->httpResponse->body);
+
+ $this->assertEquals(0,count($obj->VTIMEZONE));
+ $this->assertEquals(1,count($obj->VEVENT));
+
+ }
+
+ function testJCal() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export',
+ 'REQUEST_METHOD' => 'GET',
+ 'HTTP_ACCEPT' => 'application/calendar+json',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+ $this->assertEquals('application/calendar+json', $s->httpResponse->getHeader('Content-Type'));
+
+ }
+
+ function testJCalInUrl() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&accept=jcal',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+ $this->assertEquals('application/calendar+json', $s->httpResponse->getHeader('Content-Type'));
+
+ }
+
+ function testNegotiateDefault() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export',
+ 'REQUEST_METHOD' => 'GET',
+ 'HTTP_ACCEPT' => 'text/plain',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+ $this->assertEquals('text/calendar', $s->httpResponse->getHeader('Content-Type'));
+
+ }
+
+ function testFilterComponentVEVENT() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ // add a todo to the calendar (see /tests/Sabre/TestUtil)
+ $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO());
+
+ $tree = array(
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&componentType=VEVENT',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+ $obj = VObject\Reader::read($s->httpResponse->body);
+
+ $this->assertEquals(1,count($obj->VTIMEZONE));
+ $this->assertEquals(1,count($obj->VEVENT));
+ $this->assertEquals(0,count($obj->VTODO));
+
+ }
+
+ function testFilterComponentVTODO() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = [
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ ];
+ // add a todo to the calendar (see /tests/Sabre/TestUtil)
+ $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO());
+
+ $tree = [
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ ];
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&componentType=VTODO',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+ $obj = VObject\Reader::read($s->httpResponse->body);
+
+ $this->assertEquals(0,count($obj->VTIMEZONE));
+ $this->assertEquals(0,count($obj->VEVENT));
+ $this->assertEquals(1,count($obj->VTODO));
+
+ }
+
+ function testFilterComponentBadComponent() {
+
+ $cbackend = TestUtil::getBackend();
+ $pbackend = new DAVACL\PrincipalBackend\Mock();
+
+ $props = [
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ ];
+ // add a todo to the calendar (see /tests/Sabre/TestUtil)
+ $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO());
+
+ $tree = [
+ new Calendar($cbackend,$props),
+ new DAVACL\PrincipalCollection($pbackend),
+ ];
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->sapi = new HTTP\SapiMock();
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = HTTP\Sapi::createFromServerArray([
+ 'REQUEST_URI' => '/UUID-123467?export&componentType=VVOODOO',
+ 'REQUEST_METHOD' => 'GET',
+ ]);
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $s->exec();
+
+ $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
+
+ }
}