Exemple #1
0
 function setup()
 {
     $this->caldavBackend = new Backend\Mock(array(array('id' => 1, 'uri' => 'UUID-123467', 'principaluri' => 'principals/user1', '{DAV:}displayname' => 'user1 calendar', '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description', '{http://apple.com/ns/ical/}calendar-order' => '1', '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet(array('VEVENT', 'VTODO'))), array('id' => 2, 'uri' => 'UUID-123468', 'principaluri' => 'principals/user1', '{DAV:}displayname' => 'user1 calendar2', '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description', '{http://apple.com/ns/ical/}calendar-order' => '1', '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet(array('VEVENT', 'VTODO')))), array(1 => array('UUID-2345' => array('calendardata' => TestUtil::getTestCalendarData()))));
     $principalBackend = new DAVACL\PrincipalBackend\Mock();
     $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-read', array('principals/user1'));
     $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-write', array('principals/user1'));
     $principalBackend->addPrincipal(array('uri' => 'principals/admin/calendar-proxy-read'));
     $principalBackend->addPrincipal(array('uri' => 'principals/admin/calendar-proxy-write'));
     $calendars = new CalendarRootNode($principalBackend, $this->caldavBackend);
     $principals = new Principal\Collection($principalBackend);
     $root = new DAV\SimpleCollection('root');
     $root->addChild($calendars);
     $root->addChild($principals);
     $objectTree = new DAV\ObjectTree($root);
     $this->server = new DAV\Server($objectTree);
     $this->server->debugExceptions = true;
     $this->server->setBaseUri('/');
     $this->plugin = new Plugin();
     $this->server->addPlugin($this->plugin);
     // Adding ACL plugin
     $this->server->addPlugin(new DAVACL\Plugin());
     // Adding Auth plugin, and ensuring that we are logged in.
     $authBackend = new DAV\Auth\Backend\Mock();
     $authBackend->defaultUser = '******';
     $authPlugin = new DAV\Auth\Plugin($authBackend, 'SabreDAV');
     $this->server->addPlugin($authPlugin);
     $authPlugin->beforeMethod('GET', '/');
     $this->response = new HTTP\ResponseMock();
     $this->server->httpResponse = $this->response;
 }
Exemple #2
0
 function setup()
 {
     if (!SABRE_HASSQLITE) {
         $this->markTestSkipped('SQLite driver is not available');
     }
     $this->pdo = CalDAV\TestUtil::getSQLiteDB();
 }
 function setup()
 {
     if (!SABRE_HASSQLITE) {
         $this->markTestSkipped('SQLite driver is not available');
     }
     $this->backend = TestUtil::getBackend();
     $this->usercalendars = new CalendarHome($this->backend, ['uri' => 'principals/user1']);
 }
 /**
  * @depends testSetup
  */
 function testPutStream()
 {
     $children = $this->calendar->getChildren();
     $this->assertTrue($children[0] instanceof CalendarObject);
     $newData = TestUtil::getTestCalendarData();
     $stream = fopen('php://temp', 'r+');
     fwrite($stream, $newData);
     rewind($stream);
     $children[0]->put($stream);
     $this->assertEquals($newData, $children[0]->get());
 }
 function setup()
 {
     $this->backend = TestUtil::getBackend();
     $this->usercalendars = new CalendarHome($this->backend, ['uri' => 'principals/user1']);
 }
 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 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));
 }
Exemple #8
0
    /**
     * @depends testSupportedReportSetProperty
     * @depends testCalendarMultiGetReport
     */
    function testCalendarQueryReport1Object()
    {
        $body = '<?xml version="1.0"?>' . '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' . '<d:prop>' . '  <c:calendar-data>' . '     <c:expand start="20000101T000000Z" end="20101231T235959Z" />' . '  </c:calendar-data>' . '  <d:getetag />' . '</d:prop>' . '<c:filter>' . '  <c:comp-filter name="VCALENDAR">' . '    <c:comp-filter name="VEVENT" />' . '  </c:comp-filter>' . '</c:filter>' . '</c:calendar-query>';
        $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467/UUID-2345', ['Depth' => '0']);
        $request->setBody($body);
        $this->server->httpRequest = $request;
        $this->server->exec();
        $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body);
        $expectedIcal = TestUtil::getTestCalendarData();
        $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
        $expectedIcal = $expectedIcal->expand(new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')), new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC')));
        $expectedIcal = str_replace("\r\n", "&#xD;\n", $expectedIcal->serialize());
        $expected = <<<XML
<?xml version="1.0"?>
<d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<d:response>
  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
  <d:propstat>
    <d:prop>
      <cal:calendar-data>{$expectedIcal}</cal:calendar-data>
      <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
    </d:prop>
    <d:status>HTTP/1.1 200 OK</d:status>
  </d:propstat>
</d:response>
</d:multistatus>
XML;
        $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
    }
Exemple #9
0
 function testCreateFileNoSupportedComponents()
 {
     $file = fopen('php://memory', 'r+');
     fwrite($file, TestUtil::getTestCalendarData());
     rewind($file);
     $calendar = new Calendar($this->backend, $this->calendars[1]);
     $calendar->createFile('hello', $file);
     $file = $calendar->getChild('hello');
     $this->assertTrue($file instanceof CalendarObject);
 }
 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);
 }