[Pkg-owncloud-commits] [php-sabredav] 25/220: Many tests work again. A few left though

David Prévot taffit at moszumanska.debian.org
Thu May 12 01:21:03 UTC 2016


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

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

commit 9be1cfda0d6de1d1729ff03e4e6c4d8f81cc762f
Author: Evert Pot <me at evertpot.com>
Date:   Tue Oct 20 01:01:47 2015 -0400

    Many tests work again. A few left though
---
 lib/CalDAV/Schedule/Plugin.php                     | 15 +++-
 lib/CalDAV/SharedCalendar.php                      |  2 +-
 lib/DAV/Xml/Property/ShareAccess.php               | 98 ++++++++++++++++++++++
 tests/Sabre/CalDAV/Backend/Mock.php                |  4 +-
 tests/Sabre/CalDAV/CalendarTest.php                | 59 +++++++------
 .../PluginPropertiesWithSharedCalendarTest.php     | 34 ++++----
 tests/Sabre/CalDAV/SharedCalendarTest.php          | 36 ++++----
 7 files changed, 174 insertions(+), 74 deletions(-)

diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index 8fc96d6..2cfc942 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -5,6 +5,7 @@ namespace Sabre\CalDAV\Schedule;
 use DateTimeZone;
 use Sabre\DAV\Server;
 use Sabre\DAV\ServerPlugin;
+use Sabre\DAV\Sharing;
 use Sabre\DAV\PropFind;
 use Sabre\DAV\PropPatch;
 use Sabre\DAV\INode;
@@ -235,14 +236,24 @@ class Plugin extends ServerPlugin {
 
                 $result = $this->server->getPropertiesForPath($calendarHomePath, [
                     '{DAV:}resourcetype',
+                    '{DAV:}share-access',
                     $sccs,
                 ], 1);
 
                 foreach ($result as $child) {
-                    if (!isset($child[200]['{DAV:}resourcetype']) || !$child[200]['{DAV:}resourcetype']->is('{' . self::NS_CALDAV . '}calendar') || $child[200]['{DAV:}resourcetype']->is('{http://calendarserver.org/ns/}shared')) {
-                        // Node is either not a calendar or a shared instance.
+                    if (!isset($child[200]['{DAV:}resourcetype']) || !$child[200]['{DAV:}resourcetype']->is('{' . self::NS_CALDAV . '}calendar')) {
+                        // Node is either not a calendar
                         continue;
                     }
+                    if (isset($child[200]['{DAV:}share-access']) ) {
+                        $shareAccess = $child[200]['{DAV:}share-access']->getValue();
+                        if ($shareAccess !== Sharing\Plugin::ACCESS_NOTSHARED && $shareAccess !== Sharing\Plugin::ACCESS_OWNER) {
+                            // Node is a shared node, not owned by the relevant
+                            // user.
+                            continue;
+                        }
+
+                    }
                     if (!isset($child[200][$sccs]) || in_array('VEVENT', $child[200][$sccs]->getValue())) {
                         // Either there is no supported-calendar-component-set
                         // (which is fine) or we found one that supports VEVENT.
diff --git a/lib/CalDAV/SharedCalendar.php b/lib/CalDAV/SharedCalendar.php
index a83ffab..e3c04c2 100644
--- a/lib/CalDAV/SharedCalendar.php
+++ b/lib/CalDAV/SharedCalendar.php
@@ -138,7 +138,7 @@ class SharedCalendar extends Calendar implements ISharedCalendar {
                     'protected' => true,
                 ];
                 $acl[] = [
-                    'privilege' => '{DAV:}write',
+                    'privilege' => '{DAV:}read',
                     'principal' => $this->calendarInfo['principaluri'],
                     'protected' => true,
                 ];
diff --git a/lib/DAV/Xml/Property/ShareAccess.php b/lib/DAV/Xml/Property/ShareAccess.php
new file mode 100644
index 0000000..567abb1
--- /dev/null
+++ b/lib/DAV/Xml/Property/ShareAccess.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Sabre\DAV\Xml\Property;
+
+use Sabre\Xml\Writer;
+use Sabre\Xml\XmlSerializable;
+
+use Sabre\DAV\Sharing\Plugin as SharingPlugin;
+
+/**
+ * This class represents the {DAV:}share-access property.
+ *
+ * This property is defined here:
+ * TODO
+ *
+ * This property is used to indicate if a resource is a shared resource, and
+ * whether the instance of the shared resource is the original instance, or
+ * an instance belonging to a sharee.
+ *
+ * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class ShareAccess implements XmlSerializable {
+
+    /**
+     * Either SHARED or SHAREDOWNER
+     *
+     * @var int
+     */
+    protected $value;
+
+    /**
+     * Creates the property.
+     *
+     * The constructor value must be one of the
+     * \Sabre\DAV\Sharing\Plugin::ACCESS_ constants. 
+     *
+     * @param int $shareAccess
+     */
+    function __construct($shareAccess) {
+
+        $this->value = $shareAccess;
+
+    }
+
+    /**
+     * Returns the current value.
+     * 
+     * @return int
+     */
+    function getValue() {
+
+        return $this->value;
+
+    }
+
+    /**
+     * The xmlSerialize method is called during xml writing.
+     *
+     * Use the $writer argument to write its own xml serialization.
+     *
+     * An important note: do _not_ create a parent element. Any element
+     * implementing XmlSerializble should only ever write what's considered
+     * its 'inner xml'.
+     *
+     * The parent of the current element is responsible for writing a
+     * containing element.
+     *
+     * This allows serializers to be re-used for different element names.
+     *
+     * If you are opening new elements, you must also close them again.
+     *
+     * @param Writer $writer
+     * @return void
+     */
+    function xmlSerialize(Writer $writer) {
+
+        switch ($this->value) {
+
+            case SharingPlugin::ACCESS_NOTSHARED :
+                $writer->writeElement('{DAV:}not-shared');
+                break;
+            case SharingPlugin::ACCESS_OWNER :
+                $writer->writeElement('{DAV:}shared-owner');
+                break;
+            case SharingPlugin::ACCESS_READONLY :
+                $writer->writeElement('{DAV:}shared-readonly');
+                break;
+            case SharingPlugin::ACCESS_READWRITE :
+                $writer->writeElement('{DAV:}shared-readwrite');
+                break;
+
+        }
+
+    }
+
+}
diff --git a/tests/Sabre/CalDAV/Backend/Mock.php b/tests/Sabre/CalDAV/Backend/Mock.php
index 8a6d4b4..d4dcc07 100644
--- a/tests/Sabre/CalDAV/Backend/Mock.php
+++ b/tests/Sabre/CalDAV/Backend/Mock.php
@@ -101,10 +101,10 @@ class Mock extends AbstractBackend {
 
         $propPatch->handleRemaining(function($props) use ($calendarId) {
 
-            foreach($this->calendars as $k=>$calendar) {
+            foreach ($this->calendars as $k => $calendar) {
 
                 if ($calendar['id'] === $calendarId) {
-                    foreach($props as $propName=>$propValue) {
+                    foreach ($props as $propName => $propValue) {
                         if (is_null($propValue)) {
                             unset($this->calendars[$k][$propName]);
                         } else {
diff --git a/tests/Sabre/CalDAV/CalendarTest.php b/tests/Sabre/CalDAV/CalendarTest.php
index 989867c..037d329 100644
--- a/tests/Sabre/CalDAV/CalendarTest.php
+++ b/tests/Sabre/CalDAV/CalendarTest.php
@@ -3,7 +3,6 @@
 namespace Sabre\CalDAV;
 
 use Sabre\DAV\PropPatch;
-use Sabre\DAVACL;
 
 require_once 'Sabre/CalDAV/TestUtil.php';
 
@@ -61,7 +60,7 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
         $this->assertEquals(true, $result);
 
         $calendars2 = $this->backend->getCalendarsForUser('principals/user1');
-        $this->assertEquals('NewName',$calendars2[0]['{DAV:}displayname']);
+        $this->assertEquals('NewName', $calendars2[0]['{DAV:}displayname']);
 
     }
 
@@ -70,15 +69,15 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
      */
     function testGetProperties() {
 
-        $question = array(
+        $question = [
             '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set',
-        );
+        ];
 
         $result = $this->calendar->getProperties($question);
 
-        foreach($question as $q) $this->assertArrayHasKey($q,$result);
+        foreach ($question as $q) $this->assertArrayHasKey($q, $result);
 
-        $this->assertEquals(array('VEVENT','VTODO'), $result['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']->getValue());
+        $this->assertEquals(['VEVENT', 'VTODO'], $result['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']->getValue());
 
     }
 
@@ -98,7 +97,7 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
     function testGetChildren() {
 
         $children = $this->calendar->getChildren();
-        $this->assertEquals(1,count($children));
+        $this->assertEquals(1, count($children));
 
         $this->assertTrue($children[0] instanceof CalendarObject);
 
@@ -143,11 +142,11 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
 
     function testCreateFile() {
 
-        $file = fopen('php://memory','r+');
-        fwrite($file,TestUtil::getTestCalendarData());
+        $file = fopen('php://memory', 'r+');
+        fwrite($file, TestUtil::getTestCalendarData());
         rewind($file);
 
-        $this->calendar->createFile('hello',$file);
+        $this->calendar->createFile('hello', $file);
 
         $file = $this->calendar->getChild('hello');
         $this->assertTrue($file instanceof CalendarObject);
@@ -156,12 +155,12 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
 
     function testCreateFileNoSupportedComponents() {
 
-        $file = fopen('php://memory','r+');
-        fwrite($file,TestUtil::getTestCalendarData());
+        $file = fopen('php://memory', 'r+');
+        fwrite($file, TestUtil::getTestCalendarData());
         rewind($file);
 
         $calendar = new Calendar($this->backend, $this->calendars[1]);
-        $calendar->createFile('hello',$file);
+        $calendar->createFile('hello', $file);
 
         $file = $calendar->getChild('hello');
         $this->assertTrue($file instanceof CalendarObject);
@@ -178,7 +177,7 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
 
     function testGetOwner() {
 
-        $this->assertEquals('principals/user1',$this->calendar->getOwner());
+        $this->assertEquals('principals/user1', $this->calendar->getOwner());
 
     }
 
@@ -190,38 +189,38 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
 
     function testGetACL() {
 
-        $expected = array(
-            array(
+        $expected = [
+            [
                 'privilege' => '{DAV:}read',
                 'principal' => 'principals/user1',
                 'protected' => true,
-            ),
-            array(
+            ],
+            [
                 'privilege' => '{DAV:}read',
                 'principal' => 'principals/user1/calendar-proxy-write',
                 'protected' => true,
-            ),
-            array(
+            ],
+            [
                 'privilege' => '{DAV:}read',
                 'principal' => 'principals/user1/calendar-proxy-read',
                 'protected' => true,
-            ),
-            array(
+            ],
+            [
                 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
                 'principal' => '{DAV:}authenticated',
                 'protected' => true,
-            ),
-            array(
+            ],
+            [
                 'privilege' => '{DAV:}write',
                 'principal' => 'principals/user1',
                 'protected' => true,
-            ),
-            array(
+            ],
+            [
                 'privilege' => '{DAV:}write',
                 'principal' => 'principals/user1/calendar-proxy-write',
                 'protected' => true,
-            ),
-        );
+            ],
+        ];
         $this->assertEquals($expected, $this->calendar->getACL());
 
     }
@@ -231,7 +230,7 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
      */
     function testSetACL() {
 
-        $this->calendar->setACL(array());
+        $this->calendar->setACL([]);
 
     }
 
@@ -254,7 +253,7 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
 
     function testGetChanges() {
 
-        $this->assertNull($this->calendar->getChanges(1,1));
+        $this->assertNull($this->calendar->getChanges(1, 1));
 
     }
 
diff --git a/tests/Sabre/CalDAV/Schedule/PluginPropertiesWithSharedCalendarTest.php b/tests/Sabre/CalDAV/Schedule/PluginPropertiesWithSharedCalendarTest.php
index b20d817..870f14c 100644
--- a/tests/Sabre/CalDAV/Schedule/PluginPropertiesWithSharedCalendarTest.php
+++ b/tests/Sabre/CalDAV/Schedule/PluginPropertiesWithSharedCalendarTest.php
@@ -2,9 +2,7 @@
 
 namespace Sabre\CalDAV\Schedule;
 
-use Sabre\DAVACL;
 use Sabre\DAV;
-use Sabre\HTTP;
 
 class PluginPropertiesWithSharedCalendarTest extends \Sabre\DAVServerTest {
 
@@ -19,9 +17,7 @@ class PluginPropertiesWithSharedCalendarTest extends \Sabre\DAVServerTest {
             'principals/user1',
             'shared',
             [
-                '{http://calendarserver.org/ns/}shared-url' => new DAV\Xml\Property\Href('calendars/user2/default/'),
-                '{http://sabredav.org/ns}read-only' => false,
-                '{http://sabredav.org/ns}owner-principal' => 'principals/user2',
+                'share-access' => DAV\Sharing\Plugin::ACCESS_READWRITE
             ]
         );
         $this->caldavBackend->createCalendar(
@@ -36,39 +32,39 @@ class PluginPropertiesWithSharedCalendarTest extends \Sabre\DAVServerTest {
 
     function testPrincipalProperties() {
 
-        $props = $this->server->getPropertiesForPath('/principals/user1',array(
+        $props = $this->server->getPropertiesForPath('/principals/user1', [
             '{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',
             '{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
             '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
             '{urn:ietf:params:xml:ns:caldav}calendar-user-type',
             '{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL',
-        ));
+        ]);
 
-        $this->assertArrayHasKey(0,$props);
-        $this->assertArrayHasKey(200,$props[0]);
+        $this->assertArrayHasKey(0, $props);
+        $this->assertArrayHasKey(200, $props[0]);
 
-        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',$props[0][200]);
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL', $props[0][200]);
         $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL'];
         $this->assertTrue($prop instanceof DAV\Xml\Property\Href);
-        $this->assertEquals('calendars/user1/outbox/',$prop->getHref());
+        $this->assertEquals('calendars/user1/outbox/', $prop->getHref());
 
-        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',$props[0][200]);
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL', $props[0][200]);
         $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL'];
         $this->assertTrue($prop instanceof DAV\Xml\Property\Href);
-        $this->assertEquals('calendars/user1/inbox/',$prop->getHref());
+        $this->assertEquals('calendars/user1/inbox/', $prop->getHref());
 
-        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',$props[0][200]);
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', $props[0][200]);
         $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
         $this->assertTrue($prop instanceof DAV\Xml\Property\Href);
-        $this->assertEquals(array('mailto:user1.sabredav at sabredav.org','/principals/user1/'),$prop->getHrefs());
+        $this->assertEquals(['mailto:user1.sabredav at sabredav.org', '/principals/user1/'], $prop->getHrefs());
 
-        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-type',$props[0][200]);
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-type', $props[0][200]);
         $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-type'];
-        $this->assertEquals('INDIVIDUAL',$prop);
+        $this->assertEquals('INDIVIDUAL', $prop);
 
-        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL',$props[0][200]);
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL', $props[0][200]);
         $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL'];
-        $this->assertEquals('calendars/user1/default/',$prop->getHref());
+        $this->assertEquals('calendars/user1/default/', $prop->getHref());
 
     }
 
diff --git a/tests/Sabre/CalDAV/SharedCalendarTest.php b/tests/Sabre/CalDAV/SharedCalendarTest.php
index d14bd81..cb595d3 100644
--- a/tests/Sabre/CalDAV/SharedCalendarTest.php
+++ b/tests/Sabre/CalDAV/SharedCalendarTest.php
@@ -2,6 +2,8 @@
 
 namespace Sabre\CalDAV;
 
+use Sabre\DAV\Sharing;
+
 class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
 
     protected $backend;
@@ -14,6 +16,7 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
                 '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
                 '{http://sabredav.org/ns}owner-principal'   => 'principals/owner',
                 '{http://sabredav.org/ns}read-only'         => false,
+                'share-access'                              => Sharing\Plugin::ACCESS_READWRITE,
                 'principaluri'                              => 'principals/sharee',
             ];
         }
@@ -85,12 +88,17 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
                 'protected' => true,
             ],
             [
-                'privilege' => '{DAV:}read',
+                'privilege' => '{DAV:}write',
                 'principal' => 'principals/sharee',
                 'protected' => true,
             ],
             [
-                'privilege' => '{DAV:}write',
+                'privilege' => '{DAV:}write-properties',
+                'principal' => 'principals/sharee',
+                'protected' => true,
+            ],
+            [
+                'privilege' => '{DAV:}read',
                 'principal' => 'principals/sharee',
                 'protected' => true,
             ],
@@ -180,23 +188,10 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
 
     }
 
-    /**
-     * @expectedException InvalidArgumentException
-     */
-    function testCreateInstanceMissingArg() {
-
-        $this->getInstance([
-            'id'                                        => 1,
-            '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
-            '{http://sabredav.org/ns}read-only'         => false,
-            'principaluri'                              => 'principals/sharee',
-        ]);
-
-    }
-
     function testUpdateShares() {
 
-        $this->instance->updateShares([
+        $instance = $this->getInstance();
+        $instance->updateShares([
             [
                 'href'       => 'mailto:test at example.org',
                 'commonName' => 'Foo Bar',
@@ -211,14 +206,15 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
             'summary'    => 'Booh',
             'readOnly'   => false,
             'status'     => SharingPlugin::STATUS_NORESPONSE,
-        ]], $this->instance->getShares());
+        ]], $instance->getShares());
 
     }
 
     function testPublish() {
 
-        $this->assertNull($this->instance->setPublishStatus(true));
-        $this->assertNull($this->instance->setPublishStatus(false));
+        $instance = $this->getInstance();
+        $this->assertNull($instance->setPublishStatus(true));
+        $this->assertNull($instance->setPublishStatus(false));
 
     }
 }

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



More information about the Pkg-owncloud-commits mailing list