[Pkg-owncloud-commits] [php-sabredav] 126/275: Lots of new tests.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:55:59 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 bcf781e98e9292d9893bb8382f54a306f1b4fe18
Author: Evert Pot <me at evertpot.com>
Date:   Thu Jul 31 19:57:34 2014 -0400

    Lots of new tests.
---
 lib/CalDAV/Schedule/Plugin.php                     |  13 +-
 lib/CalDAV/Schedule/SchedulingObject.php           |   3 +
 tests/Sabre/CalDAV/Backend/MockScheduling.php      |  38 ---
 .../Sabre/CalDAV/Schedule/ScheduleDeliverTest.php  |  67 +++-
 .../Sabre/CalDAV/Schedule/SchedulingObjectTest.php | 358 +++++++++++++++++++++
 5 files changed, 429 insertions(+), 50 deletions(-)

diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index fb938c3..ba77324 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -486,9 +486,6 @@ class Plugin extends ServerPlugin {
             $objectPath = $homePath . '/' . $result;
             $objectNode = $this->server->tree->getNodeForPath($objectPath);
             $oldICalendarData = $objectNode->get();
-            if (is_resource($oldICalendarData)) {
-                $oldICalendarData = stream_get_contents($oldICalendarData);
-            }
             $currentObject = Reader::read($oldICalendarData);
         } else {
             $isNewNode = true;
@@ -517,12 +514,12 @@ class Plugin extends ServerPlugin {
             // If the message was a reply, we may have to inform other
             // attendees of this attendees status. Therefore we're shooting off
             // another itipMessage.
-            if ($message->itipMessage->method === 'REPLY') {
+            if ($iTipMessage->method === 'REPLY') {
                 $this->processICalendarChange(
                     $oldICalendarData,
                     $newObject,
-                    [$message->recipient],
-                    [$message->sender]
+                    [$iTipMessage->recipient],
+                    [$iTipMessage->sender]
                 );
             }
             $objectNode->put($newObject->serialize());
@@ -541,13 +538,13 @@ class Plugin extends ServerPlugin {
      *
      * This method may update $newObject to add any status changes.
      *
-     * @param VCalendar $oldObject
+     * @param VCalendar|string $oldObject
      * @param VCalendar $newObject
      * @param array $addresses
      * @param array $ignore Any addresses to not send messages to.
      * @return void
      */
-    protected function processICalendarChange(VCalendar $oldObject = null, VCalendar $newObject, array $addresses, array $ignore = []) {
+    protected function processICalendarChange($oldObject = null, VCalendar $newObject, array $addresses, array $ignore = []) {
 
         $broker = new ITip\Broker();
         $messages = $broker->parseEvent($newObject, $addresses, $oldObject);
diff --git a/lib/CalDAV/Schedule/SchedulingObject.php b/lib/CalDAV/Schedule/SchedulingObject.php
index d786139..be1d2b1 100644
--- a/lib/CalDAV/Schedule/SchedulingObject.php
+++ b/lib/CalDAV/Schedule/SchedulingObject.php
@@ -3,6 +3,7 @@
 namespace Sabre\CalDAV\Schedule;
 
 use Sabre\CalDAV\Backend;
+use Sabre\DAV\Exception\MethodNotAllowed;
 
 /**
  * The SchedulingObject represents a scheduling object in the Inbox collection
@@ -91,6 +92,8 @@ class SchedulingObject extends \Sabre\DAV\File implements ISchedulingObject, \Sa
      */
     public function put($calendarData) {
 
+        throw new MethodNotAllowed('Updating scheduling objects is not supported');
+
     }
 
     /**
diff --git a/tests/Sabre/CalDAV/Backend/MockScheduling.php b/tests/Sabre/CalDAV/Backend/MockScheduling.php
index 020ad5b..52aad32 100644
--- a/tests/Sabre/CalDAV/Backend/MockScheduling.php
+++ b/tests/Sabre/CalDAV/Backend/MockScheduling.php
@@ -90,42 +90,4 @@ class MockScheduling extends Mock implements SchedulingSupport {
 
     }
 
-    /**
-     * Searches through all of a users calendars and calendar objects to find
-     * an object with a specific UID.
-     *
-     * The returned data should contain all the information getCalendarObject
-     * also returns, but also include a 'calendarUri' property. This property
-     * should *just* be the basename of the calendar.
-     *
-     * Return false if the object cannot be found.
-     *
-     * @param string $principalUri
-     * @param string $uid
-     * @return array|bool
-     */
-    public function getCalendarObjectByUID($principalUri, $uid) {
-
-        // Super slow mode...
-        foreach($this->getCalendarsForUser($principalUri) as $calendar) {
-            foreach($this->getCalendarObjects($calendar['id']) as $calendarObject) {
-                $vobj = \Sabre\VObject\Reader::read($calendarObject['calendardata']);
-                foreach($vobj->children as $child) {
-                    if (!$child instanceof \Sabre\VObject\Component) {
-                        continue;
-                    }
-                    if (!isset($child->UID)) {
-                        continue;
-                    }
-                    if ($child->UID->getValue() !== $uid) {
-                        continue 2;
-                    }
-                    $calendarObject['calendarUri'] = $calendar['uri'];
-                    return $calendarObject;
-                }
-            }
-        }
-
-    }
-
 }
diff --git a/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php b/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php
index 49da040..9764569 100644
--- a/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php
+++ b/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php
@@ -46,6 +46,7 @@ ICS;
         $this->assertItemsInInbox('user2', 1);
 
     }
+
     function testNewOnWrongCollection() {
 
         $newObject = <<<ICS
@@ -212,6 +213,41 @@ ICS;
 
     }
 
+    function testReply() {
+
+        $oldObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user2.sabredav at sabredav.org
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav at sabredav.org
+ATTENDEE:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user3.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user2.sabredav at sabredav.org
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav at sabredav.org
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user3.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $this->putPath('calendars/user2/cal/foo.ics', $oldObject);
+
+        $this->deliver($oldObject, $newObject);
+        $this->assertItemsInInbox('user2', 1);
+        $this->assertItemsInInbox('user1', 0);
+
+    }
+
+
     protected $calendarObjectUri;
 
     function deliver($oldObject, $newObject, $disableScheduling = false) {
@@ -222,8 +258,7 @@ ICS;
 
         if ($oldObject && $newObject) {
             // update
-            $parent = $this->server->tree->getNodeForPath(dirname($this->calendarObjectUri));
-            $parent->createFile(basename($this->calendarObjectUri), $oldObject);
+            $this->putPath($this->calendarObjectUri, $oldObject);
 
             $stream = fopen('php://memory','r+');
             fwrite($stream, $newObject);
@@ -239,8 +274,7 @@ ICS;
 
         } elseif ($oldObject && !$newObject) {
             // delete
-            $parent = $this->server->tree->getNodeForPath(dirname($this->calendarObjectUri));
-            $parent->createFile(basename($this->calendarObjectUri), $oldObject);
+            $this->putPath($this->calendarObjectUri, $oldObject);
 
             $this->caldavSchedulePlugin->beforeUnbind(
                 $this->calendarObjectUri
@@ -261,6 +295,31 @@ ICS;
 
     }
 
+    /**
+     * Creates or updates a node at the specified path.
+     *
+     * This circumvents sabredav's internal server apis, so all events and
+     * access control is skipped.
+     *
+     * @param string $path
+     * @param string $data
+     * @return void
+     */
+    function putPath($path, $data) {
+
+        list($parent, $base) = \Sabre\HTTP\UrlUtil::splitPath($path);
+        $parentNode = $this->server->tree->getNodeForPath($parent);
+
+        /*
+        if ($parentNode->childExists($base)) {
+            $childNode = $parentNode->getChild($base);
+            $childNode->put($data);
+        } else {*/
+            $parentNode->createFile($base, $data);
+        //}
+
+    }
+
     function assertItemsInInbox($user, $count) {
 
         $inboxNode = $this->server->tree->getNodeForPath('calendars/'.$user.'/inbox');
diff --git a/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php b/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
new file mode 100644
index 0000000..3345463
--- /dev/null
+++ b/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
@@ -0,0 +1,358 @@
+<?php
+
+namespace Sabre\CalDAV\Schedule;
+use Sabre\DAVACL;
+use Sabre\CalDAV\Backend;
+
+class SchedulingObjectTest extends \PHPUnit_Framework_TestCase {
+
+    /**
+     * @var Sabre\CalDAV\Backend_PDO
+     */
+    protected $backend;
+    /**
+     * @var Sabre\CalDAV\Calendar
+     */
+    protected $calendar;
+    protected $principalBackend;
+
+    protected $data;
+    protected $data2;
+
+    function setup() {
+
+        if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
+        $this->backend = new Backend\MockScheduling();
+
+        $this->data = <<<ICS
+BEGIN:VCALENDAR
+METHOD:REQUEST
+BEGIN:VEVENT
+SEQUENCE:1
+END:VEVENT
+END:VCALENDAR
+ICS;
+        $this->data = <<<ICS
+BEGIN:VCALENDAR
+METHOD:REQUEST
+BEGIN:VEVENT
+SEQUENCE:2
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $this->inbox = new Inbox($this->backend, 'principals/user1');
+        $this->inbox->createFile('item1.ics', $this->data);
+
+    }
+
+    function teardown() {
+
+        unset($this->inbox);
+        unset($this->backend);
+
+    }
+
+    function testSetup() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $this->assertInternalType('string',$children[0]->getName());
+        $this->assertInternalType('string',$children[0]->get());
+        $this->assertInternalType('string',$children[0]->getETag());
+        $this->assertEquals('text/calendar; charset=utf-8', $children[0]->getContentType());
+
+    }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    function testInvalidArg1() {
+
+        $obj = new SchedulingObject(
+            new Backend\MockScheduling(array(),array()),
+            array(),
+            array()
+        );
+
+    }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    function testInvalidArg2() {
+
+        $obj = new SchedulingObject(
+            new Backend\MockScheduling(array(),array()),
+            array(),
+            array('calendarid' => '1')
+        );
+
+    }
+
+    /**
+     * @depends testSetup
+     * @expectedException \Sabre\DAV\Exception\MethodNotAllowed
+     */
+    function testPut() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $children[0]->put('');
+
+    }
+
+    /**
+     * @depends testSetup
+     */
+    function testDelete() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $obj = $children[0];
+        $obj->delete();
+
+        $children2 =  $this->inbox->getChildren();
+        $this->assertEquals(count($children)-1, count($children2));
+
+    }
+
+    /**
+     * @depends testSetup
+     */
+    function testGetLastModified() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $obj = $children[0];
+
+        $lastMod = $obj->getLastModified();
+        $this->assertTrue(is_int($lastMod) || ctype_digit($lastMod) || is_null($lastMod));
+
+    }
+
+    /**
+     * @depends testSetup
+     */
+    function testGetSize() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $obj = $children[0];
+
+        $size = $obj->getSize();
+        $this->assertInternalType('int', $size);
+
+    }
+
+    function testGetOwner() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $obj = $children[0];
+        $this->assertEquals('principals/user1', $obj->getOwner());
+
+    }
+
+    function testGetGroup() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $obj = $children[0];
+        $this->assertNull($obj->getGroup());
+
+    }
+
+    function testGetACL() {
+
+        $expected = array(
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}write',
+                'principal' => 'principals/user1',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1/calendar-proxy-write',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}write',
+                'principal' => 'principals/user1/calendar-proxy-write',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1/calendar-proxy-read',
+                'protected' => true,
+            ),
+        );
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $obj = $children[0];
+        $this->assertEquals($expected, $obj->getACL());
+
+    }
+
+    function testDefaultACL() {
+
+        $backend = new Backend\MockScheduling([], []);
+        $calendarObject = new SchedulingObject($backend, ['calendarid' => 1, 'uri' => 'foo', 'principaluri' => 'principals/user1' ]);
+        $expected = array(
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}write',
+                'principal' => 'principals/user1',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1/calendar-proxy-write',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}write',
+                'principal' => 'principals/user1/calendar-proxy-write',
+                'protected' => true,
+            ),
+            array(
+                'privilege' => '{DAV:}read',
+                'principal' => 'principals/user1/calendar-proxy-read',
+                'protected' => true,
+            ),
+        );
+        $this->assertEquals($expected, $calendarObject->getACL());
+
+
+    }
+
+    /**
+     * @expectedException Sabre\DAV\Exception\MethodNotAllowed
+     */
+    function testSetACL() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $obj = $children[0];
+        $obj->setACL(array());
+
+    }
+
+    function testGet() {
+
+        $children = $this->inbox->getChildren();
+        $this->assertTrue($children[0] instanceof SchedulingObject);
+
+        $obj = $children[0];
+
+        $this->assertEquals($this->data, $obj->get());
+
+    }
+
+    function testGetRefetch() {
+
+        $backend = new Backend\MockScheduling();
+        $backend->createSchedulingObject('principals/user1', 'foo', 'foo'); 
+
+        $obj = new SchedulingObject($backend, array( 
+            'calendarid' => 1,
+            'uri' => 'foo',
+            'principaluri' => 'principals/user1',
+        ));
+
+        $this->assertEquals('foo', $obj->get());
+
+    }
+
+    function testGetEtag1() {
+
+        $objectInfo = array(
+            'calendardata' => 'foo',
+            'uri' => 'foo',
+            'etag' => 'bar',
+            'calendarid' => 1
+        );
+
+        $backend = new Backend\MockScheduling(array(), array());
+        $obj = new SchedulingObject($backend, $objectInfo);
+
+        $this->assertEquals('bar', $obj->getETag());
+
+    }
+
+    function testGetEtag2() {
+
+        $objectInfo = array(
+            'calendardata' => 'foo',
+            'uri' => 'foo',
+            'calendarid' => 1
+        );
+
+        $backend = new Backend\MockScheduling(array(), array());
+        $obj = new SchedulingObject($backend, $objectInfo);
+
+        $this->assertEquals('"' . md5('foo') . '"', $obj->getETag());
+
+    }
+
+    function testGetSupportedPrivilegesSet() {
+
+        $objectInfo = array(
+            'calendardata' => 'foo',
+            'uri' => 'foo',
+            'calendarid' => 1
+        );
+
+        $backend = new Backend\MockScheduling(array(), array());
+        $obj = new SchedulingObject($backend, $objectInfo);
+        $this->assertNull($obj->getSupportedPrivilegeSet());
+
+    }
+
+    function testGetSize1() {
+
+        $objectInfo = array(
+            'calendardata' => 'foo',
+            'uri' => 'foo',
+            'calendarid' => 1
+        );
+
+        $backend = new Backend\MockScheduling(array(), array());
+        $obj = new SchedulingObject($backend, $objectInfo);
+        $this->assertEquals(3, $obj->getSize());
+
+    }
+
+    function testGetSize2() {
+
+        $objectInfo = array(
+            'uri' => 'foo',
+            'calendarid' => 1,
+            'size' => 4,
+        );
+
+        $backend = new Backend\MockScheduling(array(), array());
+        $obj = new SchedulingObject($backend, $objectInfo);
+        $this->assertEquals(4, $obj->getSize());
+
+    }
+}

-- 
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