aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-10-21 15:46:31 -0700
committerfriendica <info@friendica.com>2013-10-21 15:46:31 -0700
commitb35122f7a6ad42756c35bb60ba1f06c3dcd45c77 (patch)
treeccdf373ce6475d264778523259cc32899b732fe7 /vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php
parente3504df514d306cfe6b83e44a11f550664564af4 (diff)
downloadvolse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.tar.gz
volse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.tar.bz2
volse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.zip
add sabre (1.8.x) via composer in the !@#$ place it wants to be
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php227
1 files changed, 227 insertions, 0 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php
new file mode 100644
index 000000000..be21796dd
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php
@@ -0,0 +1,227 @@
+<?php
+
+namespace Sabre\CalDAV;
+
+use Sabre\DAV;
+use Sabre\HTTP;
+use Sabre\VObject;
+use Sabre\DAVACL;
+
+require_once 'Sabre/CalDAV/TestUtil.php';
+require_once 'Sabre/HTTP/ResponseMock.php';
+
+class ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
+
+ function testInit() {
+
+ $p = new ICSExportPlugin();
+ $s = new DAV\Server();
+ $s->addPlugin($p);
+
+ }
+
+ function testBeforeMethod() {
+
+ if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
+ $cbackend = TestUtil::getBackend();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = new HTTP\Request(array(
+ 'QUERY_STRING' => 'export',
+ ));
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $this->assertFalse($p->beforeMethod('GET','UUID-123467?export'));
+
+ $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status);
+ $this->assertEquals(array(
+ 'Content-Type' => 'text/calendar',
+ ), $s->httpResponse->headers);
+
+ $obj = VObject\Reader::read($s->httpResponse->body);
+
+ $this->assertEquals(5,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));
+
+ }
+ function testBeforeMethodNoVersion() {
+
+ if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
+ $cbackend = TestUtil::getBackend();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+
+ $h = new HTTP\Request(array(
+ 'QUERY_STRING' => 'export',
+ ));
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ DAV\Server::$exposeVersion = false;
+ $this->assertFalse($p->beforeMethod('GET','UUID-123467?export'));
+ DAV\Server::$exposeVersion = true;
+
+ $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status);
+ $this->assertEquals(array(
+ 'Content-Type' => 'text/calendar',
+ ), $s->httpResponse->headers);
+
+ $obj = VObject\Reader::read($s->httpResponse->body);
+
+ $this->assertEquals(5,count($obj->children()));
+ $this->assertEquals(1,count($obj->VERSION));
+ $this->assertEquals(1,count($obj->CALSCALE));
+ $this->assertEquals(1,count($obj->PRODID));
+ $this->assertFalse(strpos((string)$obj->PRODID, DAV\Version::VERSION)!==false);
+ $this->assertEquals(1,count($obj->VTIMEZONE));
+ $this->assertEquals(1,count($obj->VEVENT));
+
+ }
+
+ 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();
+
+ $s = new DAV\Server();
+ $s->addPlugin($p);
+
+ $this->assertNull($p->beforeMethod('GET','UUID-123467'));
+
+ }
+
+ /**
+ * @expectedException Sabre\DAVACL\Exception\NeedPrivileges
+ */
+ function testACLIntegrationBlocked() {
+
+ if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
+ $cbackend = TestUtil::getBackend();
+
+ $props = array(
+ 'uri'=>'UUID-123467',
+ 'principaluri' => 'admin',
+ 'id' => 1,
+ );
+ $tree = array(
+ new Calendar($cbackend,$props),
+ );
+
+ $p = new ICSExportPlugin();
+
+ $s = new DAV\Server($tree);
+ $s->addPlugin($p);
+ $s->addPlugin(new Plugin());
+ $s->addPlugin(new DAVACL\Plugin());
+
+ $h = new HTTP\Request(array(
+ 'QUERY_STRING' => 'export',
+ ));
+
+ $s->httpRequest = $h;
+ $s->httpResponse = new HTTP\ResponseMock();
+
+ $p->beforeMethod('GET','UUID-123467?export');
+
+ }
+
+ function testACLIntegrationNotBlocked() {
+
+ if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
+ $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->addPlugin($p);
+ $s->addPlugin(new Plugin());
+ $s->addPlugin(new DAVACL\Plugin());
+ $s->addPlugin(new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'));
+
+ // Forcing login
+ $s->getPlugin('acl')->adminPrincipals = array('principals/admin');
+
+ $h = new HTTP\Request(array(
+ 'QUERY_STRING' => 'export',
+ 'REQUEST_URI' => '/UUID-123467',
+ '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(array(
+ 'Content-Type' => 'text/calendar',
+ ), $s->httpResponse->headers);
+
+ $obj = VObject\Reader::read($s->httpResponse->body);
+
+ $this->assertEquals(5,count($obj->children()));
+ $this->assertEquals(1,count($obj->VERSION));
+ $this->assertEquals(1,count($obj->CALSCALE));
+ $this->assertEquals(1,count($obj->PRODID));
+ $this->assertEquals(1,count($obj->VTIMEZONE));
+ $this->assertEquals(1,count($obj->VEVENT));
+
+ }
+}