[Pkg-owncloud-commits] [php-sabredav] 13/40: Added tests.

David Prévot taffit at moszumanska.debian.org
Sat Sep 5 15:24:07 UTC 2015


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

taffit pushed a commit to tag 3.1.0-alpha2
in repository php-sabredav.

commit ed46a5bc40708ab5369be3bb257826a964a2b0a7
Author: Evert Pot <me at evertpot.com>
Date:   Mon Jul 27 18:42:16 2015 -0400

    Added tests.
---
 lib/CalDAV/Schedule/Plugin.php                     | 96 +++++++++++-----------
 .../Sabre/CalDAV/Schedule/PluginPropertiesTest.php | 67 +++++++++++----
 tests/Sabre/DAVServerTest.php                      | 35 +++++---
 3 files changed, 125 insertions(+), 73 deletions(-)

diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index 60486ff..76fba75 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -201,66 +201,76 @@ class Plugin extends ServerPlugin {
      */
     function propFind(PropFind $propFind, INode $node) {
 
-        if (!$node instanceof DAVACL\IPrincipal) return;
+        if ($node instanceof DAVACL\IPrincipal) { 
 
-        $caldavPlugin = $this->server->getPlugin('caldav');
-        $principalUrl = $node->getPrincipalUrl();
+            $caldavPlugin = $this->server->getPlugin('caldav');
+            $principalUrl = $node->getPrincipalUrl();
 
-        // schedule-outbox-URL property
-        $propFind->handle('{' . self::NS_CALDAV . '}schedule-outbox-URL', function() use ($principalUrl, $caldavPlugin) {
+            // schedule-outbox-URL property
+            $propFind->handle('{' . self::NS_CALDAV . '}schedule-outbox-URL', function() use ($principalUrl, $caldavPlugin) {
 
-            $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
-            $outboxPath = $calendarHomePath . '/outbox/';
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+                $outboxPath = $calendarHomePath . '/outbox/';
 
-            return new Href($outboxPath);
+                return new Href($outboxPath);
 
-        });
-        // schedule-inbox-URL property
-        $propFind->handle('{' . self::NS_CALDAV . '}schedule-inbox-URL', function() use ($principalUrl, $caldavPlugin) {
+            });
+            // schedule-inbox-URL property
+            $propFind->handle('{' . self::NS_CALDAV . '}schedule-inbox-URL', function() use ($principalUrl, $caldavPlugin) {
 
-            $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
-            $inboxPath = $calendarHomePath . '/inbox/';
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+                $inboxPath = $calendarHomePath . '/inbox/';
 
-            return new Href($inboxPath);
+                return new Href($inboxPath);
 
-        });
+            });
 
-        $propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($principalUrl, $caldavPlugin) {
+            $propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($principalUrl, $caldavPlugin) {
 
-            // We don't support customizing this property yet, so in the
-            // meantime we just grab the first calendar in the home-set.
-            $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+                // We don't support customizing this property yet, so in the
+                // meantime we just grab the first calendar in the home-set.
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
 
-            $sccs = '{' . self::NS_CALDAV . '}supported-calendar-component-set';
+                $sccs = '{' . self::NS_CALDAV . '}supported-calendar-component-set';
 
-            $result = $this->server->getPropertiesForPath($calendarHomePath, [
-                '{DAV:}resourcetype',
-                $sccs,
-            ], 1);
+                $result = $this->server->getPropertiesForPath($calendarHomePath, [
+                    '{DAV:}resourcetype',
+                    $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.
-                    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.
-                    return new Href($child['href']);
+                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.
+                        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.
+                        return new Href($child['href']);
+                    }
                 }
-            }
 
-        });
+            });
+
+            // The server currently reports every principal to be of type
+            // 'INDIVIDUAL'
+            $propFind->handle('{' . self::NS_CALDAV . '}calendar-user-type', function() {
+
+                return 'INDIVIDUAL';
+
+            });
+
+        }
 
         // Mapping the old property to the new property.
-        $propFind->handle('{https://calendarserver.org/ns/}calendar-availability', function() use ($propFind, $node) {
+        $propFind->handle('{http://calendarserver.org/ns/}calendar-availability', function() use ($propFind, $node) {
 
              // In case it wasn't clear, the only difference is that we map the
             // old property to a different namespace.
              $availProp = '{' . self::NS_CALDAV . '}calendar-availability';
              $subPropFind = new PropFind(
                  $propFind->getPath(),
-                 $availProp
+                 [$availProp]
              );
 
              $this->server->getPropertiesByNode(
@@ -269,21 +279,13 @@ class Plugin extends ServerPlugin {
              );
 
              $propFind->set(
-                 '{https://calendarserver.org/ns/}calendar-availability',
+                 '{http://calendarserver.org/ns/}calendar-availability',
                  $subPropFind->get($availProp),
                  $subPropFind->getStatus($availProp)
              );
 
         });
 
-        // The server currently reports every principal to be of type
-        // 'INDIVIDUAL'
-        $propFind->handle('{' . self::NS_CALDAV . '}calendar-user-type', function() {
-
-            return 'INDIVIDUAL';
-
-        });
-
     }
 
     /**
@@ -296,7 +298,7 @@ class Plugin extends ServerPlugin {
     function propPatch($path, PropPatch $propPatch) {
 
         // Mapping the old property to the new property.
-        $propPatch->handle('{https://calendarserver.org/ns/}calendar-availability', function($value) use ($path) {
+        $propPatch->handle('{http://calendarserver.org/ns/}calendar-availability', function($value) use ($path) {
 
             $availProp = '{' . self::NS_CALDAV . '}calendar-availability';
             $subPropPatch = new PropPatch([$availProp => $value]);
diff --git a/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php b/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
index b9a2e6c..aa2b9eb 100644
--- a/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
+++ b/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
@@ -2,14 +2,13 @@
 
 namespace Sabre\CalDAV\Schedule;
 
-use Sabre\DAVACL;
 use Sabre\DAV;
-use Sabre\HTTP;
 
 class PluginPropertiesTest extends \Sabre\DAVServerTest {
 
     protected $setupCalDAV = true;
     protected $setupCalDAVScheduling = true;
+    protected $setupPropertyStorage = true;
 
     function setUp() {
 
@@ -26,39 +25,75 @@ class PluginPropertiesTest 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());
+
+    }
+
+    /**
+     * There are two properties for availability. The server should
+     * automatically map the old property to the standard property.
+     */
+    function testAvailabilityMapping() {
+
+        $path = 'calendars/user1/inbox';
+        $oldProp = '{http://calendarserver.org/ns/}calendar-availability';
+        $newProp = '{urn:ietf:params:xml:ns:caldav}calendar-availability';
+        $value1 = 'first value';
+        $value2 = 'second value';
+
+        // Storing with the old name
+        $this->server->updateProperties($path, [
+            $oldProp => $value1
+        ]);
+
+        // Retrieving with the new name
+        $this->assertEquals(
+            [$newProp => $value1],
+            $this->server->getProperties($path, [$newProp])
+        );
+
+        // Storing with the new name
+        $this->server->updateProperties($path, [
+            $newProp => $value2
+        ]);
+
+        // Retrieving with the old name
+        $this->assertEquals(
+            [$oldProp => $value2],
+            $this->server->getProperties($path, [$oldProp])
+        );
 
     }
 
diff --git a/tests/Sabre/DAVServerTest.php b/tests/Sabre/DAVServerTest.php
index 6c79650..473e467 100644
--- a/tests/Sabre/DAVServerTest.php
+++ b/tests/Sabre/DAVServerTest.php
@@ -2,10 +2,9 @@
 
 namespace Sabre;
 
-use
-    Sabre\HTTP\Request,
-    Sabre\HTTP\Response,
-    Sabre\HTTP\Sapi;
+use Sabre\HTTP\Request;
+use Sabre\HTTP\Response;
+use Sabre\HTTP\Sapi;
 
 /**
  * This class may be used as a basis for other webdav-related unittests.
@@ -28,28 +27,30 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
     protected $setupCalDAVICSExport = false;
     protected $setupLocks = false;
     protected $setupFiles = false;
+    protected $setupPropertyStorage = false;
 
     /**
      * An array with calendars. Every calendar should have
      *   - principaluri
      *   - uri
      */
-    protected $caldavCalendars = array();
-    protected $caldavCalendarObjects = array();
+    protected $caldavCalendars = [];
+    protected $caldavCalendarObjects = [];
 
-    protected $carddavAddressBooks = array();
-    protected $carddavCards = array();
+    protected $carddavAddressBooks = [];
+    protected $carddavCards = [];
 
     /**
      * @var Sabre\DAV\Server
      */
     protected $server;
-    protected $tree = array();
+    protected $tree = [];
 
     protected $caldavBackend;
     protected $carddavBackend;
     protected $principalBackend;
     protected $locksBackend;
+    protected $propertyStorageBackend;
 
     /**
      * @var Sabre\CalDAV\Plugin
@@ -89,6 +90,11 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
     protected $locksPlugin;
 
     /**
+     * @var Sabre\DAV\PropertyStorage\Plugin
+     */
+    protected $propertyStoragePlugin;
+
+    /**
      * If this string is set, we will automatically log in the user with this
      * name.
      */
@@ -136,6 +142,12 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
             );
             $this->server->addPlugin($this->locksPlugin);
         }
+        if ($this->setupPropertyStorage) {
+            $this->propertyStoragePlugin = new DAV\PropertyStorage\Plugin(
+                $this->propertyStorageBackend
+            );
+            $this->server->addPlugin($this->propertyStoragePlugin);
+        }
         if ($this->autoLogin) {
             $authBackend = new DAV\Auth\Backend\Mock();
             $authBackend->setPrincipal('principals/' . $this->autoLogin);
@@ -225,6 +237,9 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
         if ($this->setupLocks) {
             $this->locksBackend = new DAV\Locks\Backend\Mock();
         }
+        if ($this->setupPropertyStorage)  {
+            $this->propertyStorageBackend = new DAV\PropertyStorage\Backend\Mock();
+        }
 
     }
 
@@ -232,7 +247,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
     function assertHTTPStatus($expectedStatus, HTTP\Request $req) {
 
         $resp = $this->request($req);
-        $this->assertEquals((int)$expectedStatus, (int)$resp->status,'Incorrect HTTP status received: ' . $resp->body);
+        $this->assertEquals((int)$expectedStatus, (int)$resp->status, 'Incorrect HTTP status received: ' . $resp->body);
 
     }
 

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