[Pkg-owncloud-commits] [php-sabredav] 140/275: More tests. Found a number of bugs.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:56:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 4cbc48304699a2978c4f0eb4e37a283ce61761d3
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Sat Aug 9 16:26:52 2014 -0400

    More tests. Found a number of bugs.
---
 lib/CalDAV/Backend/PDO.php                     |   5 +-
 lib/CalDAV/Schedule/Inbox.php                  |   2 +-
 tests/Sabre/CalDAV/Backend/AbstractPDOTest.php |  41 ++++++
 tests/Sabre/CalDAV/Backend/AbstractTest.php    |  34 ++++-
 tests/Sabre/CalDAV/Schedule/InboxTest.php      | 171 +++++++++++++++++++++++++
 5 files changed, 246 insertions(+), 7 deletions(-)

diff --git a/lib/CalDAV/Backend/PDO.php b/lib/CalDAV/Backend/PDO.php
index 9f42e21..1037fa0 100755
--- a/lib/CalDAV/Backend/PDO.php
+++ b/lib/CalDAV/Backend/PDO.php
@@ -1095,14 +1095,14 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
      */
     public function getSchedulingObject($principalUri, $objectUri) {
 
-        $stmt = $this->pdo->prepare('SELECT id, calendardata, lastmodified, etag, size FROM '.$this->schedulingObjectTableName.' WHERE principaluri = ? AND uri = ?');
+        $stmt = $this->pdo->prepare('SELECT uri, calendardata, lastmodified, etag, size FROM '.$this->schedulingObjectTableName.' WHERE principaluri = ? AND uri = ?');
         $stmt->execute([$principalUri, $objectUri]);
         $row = $stmt->fetch(\PDO::FETCH_ASSOC);
 
         if(!$row) return null;
 
         return [
-            'id'           => $row['id'],
+            'uri'          => $row['uri'],
             'calendardata' => $row['calendardata'],
             'lastmodified' => $row['lastmodified'],
             'etag'         => '"' . $row['etag'] . '"',
@@ -1130,7 +1130,6 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
         $result = [];
         foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
             $result[] = [
-                'id'           => $row['id'],
                 'calendardata' => $row['calendardata'],
                 'uri'          => $row['uri'],
                 'lastmodified' => $row['lastmodified'],
diff --git a/lib/CalDAV/Schedule/Inbox.php b/lib/CalDAV/Schedule/Inbox.php
index 82edfe0..03f0e4c 100644
--- a/lib/CalDAV/Schedule/Inbox.php
+++ b/lib/CalDAV/Schedule/Inbox.php
@@ -239,7 +239,7 @@ class Inbox extends DAV\Collection implements IInbox {
         $result = [];
         $validator = new CalDAV\CalendarQueryValidator();
 
-        $objects = $this->getChildren();
+        $objects = $this->caldavBackend->getSchedulingObjects($this->principalUri);
         foreach($objects as $object) {
             $vObject = VObject\Reader::read($object['calendardata']);
             if ($validator->validate($vObject, $filters)) {
diff --git a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
index 5cd6f69..13145a3 100644
--- a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
+++ b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
@@ -811,4 +811,45 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
         $subs = $backend->getSubscriptionsForUser('principals/user1');
         $this->assertEquals(0, count($subs));
     }
+
+    function testSchedulingMethods() {
+
+        $backend = new PDO($this->pdo);
+
+        $calData = "BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n";
+
+        $backend->createSchedulingObject(
+            'principals/user1',
+            'schedule1.ics',
+            $calData
+        );
+
+        $expected = [
+            'calendardata' => $calData,
+            'uri' => 'schedule1.ics',
+            'etag' => '"' . md5($calData) . '"',
+            'size' => strlen($calData)
+        ];
+
+        $result = $backend->getSchedulingObject('principals/user1', 'schedule1.ics');
+        foreach($expected as $k=>$v) {
+            $this->assertArrayHasKey($k, $result);
+            $this->assertEquals($v, $result[$k]);
+        }
+
+        $results = $backend->getSchedulingObjects('principals/user1');
+
+        $this->assertEquals(1, count($results));
+        $result = $results[0];
+        foreach($expected as $k=>$v) {
+            $this->assertEquals($v, $result[$k]);
+        }
+
+        $backend->deleteSchedulingObject('principals/user1', 'schedule1.ics');
+        $result = $backend->getSchedulingObject('principals/user1', 'schedule1.ics');
+
+        $this->assertNull($result);
+
+    }
+
 }
diff --git a/tests/Sabre/CalDAV/Backend/AbstractTest.php b/tests/Sabre/CalDAV/Backend/AbstractTest.php
index e71c0e9..2bf3046 100644
--- a/tests/Sabre/CalDAV/Backend/AbstractTest.php
+++ b/tests/Sabre/CalDAV/Backend/AbstractTest.php
@@ -60,6 +60,34 @@ class AbstractTest extends \PHPUnit_Framework_TestCase {
 
     }
 
+    function testGetMultipleCalendarObjects() {
+
+        $abstract = new AbstractMock();
+        $result = $abstract->getMultipleCalendarObjects(1, [
+            'event1.ics',
+            'task1.ics',
+        ]);
+
+        $expected = [
+            array(
+                'id' => 1,
+                'calendarid' => 1,
+                'uri' => 'event1.ics',
+                'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
+            ),
+            array(
+                'id' => 2,
+                'calendarid' => 1,
+                'uri' => 'task1.ics',
+                'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n",
+            ),
+        ];
+
+        $this->assertEquals($expected, $result);
+
+
+    }
+
 }
 
 class AbstractMock extends AbstractBackend {
@@ -93,7 +121,7 @@ class AbstractMock extends AbstractBackend {
         );
 
     }
-    function getCalendarObject($calendarId,$objectUri) {
+    function getCalendarObject($calendarId, $objectUri) {
 
         switch($objectUri) {
 
@@ -106,9 +134,9 @@ class AbstractMock extends AbstractBackend {
                 );
             case 'task1.ics' :
                 return array(
-                    'id' => 1,
+                    'id' => 2,
                     'calendarid' => 1,
-                    'uri' => 'event1.ics',
+                    'uri' => 'task1.ics',
                     'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n",
                 );
 
diff --git a/tests/Sabre/CalDAV/Schedule/InboxTest.php b/tests/Sabre/CalDAV/Schedule/InboxTest.php
new file mode 100644
index 0000000..c704f2c
--- /dev/null
+++ b/tests/Sabre/CalDAV/Schedule/InboxTest.php
@@ -0,0 +1,171 @@
+<?php
+
+namespace Sabre\CalDAV\Schedule;
+use Sabre\CalDAV;
+use Sabre\DAV;
+
+class InboxTest extends \PHPUnit_Framework_TestCase {
+
+    function testSetup() {
+
+        $inbox = new Inbox(
+            new CalDAV\Backend\MockScheduling(),
+            'principals/user1'
+        );
+        $this->assertEquals('inbox', $inbox->getName());
+        $this->assertEquals(array(), $inbox->getChildren());
+        $this->assertEquals('principals/user1', $inbox->getOwner());
+        $this->assertEquals(null, $inbox->getGroup());
+
+        $this->assertEquals(array(
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}write-properties',
+                'principal' => 'principals/user1',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1/calendar-proxy-read',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1/calendar-proxy-write',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver-invite',
+                'principal' => '{DAV:}authenticated',
+                'protected' => true,
+            ),
+        ), $inbox->getACL());
+
+        $ok = false;
+        try {
+            $inbox->setACL(array());
+        } catch (DAV\Exception\MethodNotAllowed $e) {
+            $ok = true;
+        }
+        if (!$ok) {
+            $this->fail('Exception was not emitted');
+        }
+
+    }
+
+    function testGetSupportedPrivilegeSet() {
+
+        $inbox = new Inbox(
+            new CalDAV\Backend\MockScheduling(),
+            'principals/user1'
+        );
+        $r = $inbox->getSupportedPrivilegeSet();
+
+        $ok = 0;
+        foreach($r['aggregates'] as $priv) {
+
+            if ($priv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver') {
+                $ok++;
+                foreach($priv['aggregates'] as $subpriv) {
+                    if ($subpriv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver-invite') {
+                        $ok++;
+                    }
+                    if ($subpriv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver-reply') {
+                        $ok++;
+                    }
+                }
+            }
+        }
+
+        $this->assertEquals(3, $ok, "We're missing one or more privileges");
+
+    }
+
+    /**
+     * @depends testSetup
+     */
+    function testGetChildren() {
+
+        $backend = new CalDAV\Backend\MockScheduling();
+        $inbox = new Inbox(
+            $backend,
+            'principals/user1'
+        );
+
+        $this->assertEquals(
+            0,
+            count($inbox->getChildren())
+        );
+        $backend->createSchedulingObject('principals/user1', 'schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
+        $this->assertEquals(
+            1,
+            count($inbox->getChildren())
+        );
+        $this->assertInstanceOf('Sabre\CalDAV\Schedule\SchedulingObject', $inbox->getChildren()[0]);
+        $this->assertEquals(
+            'schedule1.ics',
+            $inbox->getChildren()[0]->getName()
+        );
+
+    }
+
+    /**
+     * @depends testGetChildren
+     */
+    function testCreateFile() {
+
+        $backend = new CalDAV\Backend\MockScheduling();
+        $inbox = new Inbox(
+            $backend,
+            'principals/user1'
+        );
+
+        $this->assertEquals(
+            0,
+            count($inbox->getChildren())
+        );
+        $inbox->createFile('schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
+        $this->assertEquals(
+            1,
+            count($inbox->getChildren())
+        );
+        $this->assertInstanceOf('Sabre\CalDAV\Schedule\SchedulingObject', $inbox->getChildren()[0]);
+        $this->assertEquals(
+            'schedule1.ics',
+            $inbox->getChildren()[0]->getName()
+        );
+
+    }
+
+    /**
+     * @depends testSetup
+     */
+    function testCalendarQuery() {
+
+        $backend = new CalDAV\Backend\MockScheduling();
+        $inbox = new Inbox(
+            $backend,
+            'principals/user1'
+        );
+
+        $this->assertEquals(
+            0,
+            count($inbox->getChildren())
+        );
+        $backend->createSchedulingObject('principals/user1', 'schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
+        $this->assertEquals(
+            ['schedule1.ics'],
+            $inbox->calendarQuery([
+                'name' => 'VCALENDAR',
+                'comp-filters' => [],
+                'prop-filters' => [],
+                'is-not-defined' => false
+            ])
+        );
+
+    }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list