[Pkg-owncloud-commits] [php-sabredav] 16/34: Testing the share request parser, and fixing a few bugs.

David Prévot taffit at moszumanska.debian.org
Wed May 27 13:57:09 UTC 2015


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

taffit pushed a commit to tag 3.0.0-beta1
in repository php-sabredav.

commit 8176aca0f4d13e2599c54cca4a3934cbcb20c872
Author: Evert Pot <me at evertpot.com>
Date:   Wed May 20 17:52:18 2015 +0300

    Testing the share request parser, and fixing a few bugs.
    
    Fixes #662
---
 lib/CalDAV/Xml/Request/Share.php                   |  5 +-
 .../CalDAV/Xml/Request/CalendarQueryReportTest.php | 90 +++++++++++-----------
 tests/Sabre/CalDAV/Xml/Request/ShareTest.php       | 86 +++++++++++++++++++++
 3 files changed, 134 insertions(+), 47 deletions(-)

diff --git a/lib/CalDAV/Xml/Request/Share.php b/lib/CalDAV/Xml/Request/Share.php
index 0dcda9b..1159d88 100644
--- a/lib/CalDAV/Xml/Request/Share.php
+++ b/lib/CalDAV/Xml/Request/Share.php
@@ -92,12 +92,13 @@ class Share implements XmlDeserializable {
                     $sharee = $elem['value'];
 
                     $sumElem = '{' . Plugin::NS_CALENDARSERVER . '}summary';
+                    $commonName = '{' . Plugin::NS_CALENDARSERVER . '}common-name';
 
                     $set[] = [
                         'href'       => $sharee['{DAV:}href'],
-                        'commonName' => $sharee['{' . Plugin::NS_CALENDARSERVER . '}common-name'],
+                        'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null,
                         'summary'    => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
-                        'readOnly'   => isset($sharee['{' . Plugin::NS_CALENDARSERVER . '}readOnly']),
+                        'readOnly'   => !array_key_exists('{' . Plugin::NS_CALENDARSERVER . '}read-write', $sharee),
                     ];
                     break;
 
diff --git a/tests/Sabre/CalDAV/Xml/Request/CalendarQueryReportTest.php b/tests/Sabre/CalDAV/Xml/Request/CalendarQueryReportTest.php
index b7ca01f..05e91e5 100644
--- a/tests/Sabre/CalDAV/Xml/Request/CalendarQueryReportTest.php
+++ b/tests/Sabre/CalDAV/Xml/Request/CalendarQueryReportTest.php
@@ -30,11 +30,11 @@ XML;
             '{DAV:}getetag',
         ];
         $calendarQueryReport->filters = [
-            'name' => 'VCALENDAR',
+            'name'           => 'VCALENDAR',
             'is-not-defined' => false,
-            'comp-filters' => [],
-            'prop-filters' => [],
-            'time-range' => false,
+            'comp-filters'   => [],
+            'prop-filters'   => [],
+            'time-range'     => false,
         ];
 
         $this->assertEquals(
@@ -115,96 +115,96 @@ XML;
         ];
         $calendarQueryReport->expand = [
             'start' => new \DateTime('2015-01-01 00:00:00', new \DateTimeZone('UTC')),
-            'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
+            'end'   => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
         ];
         $calendarQueryReport->filters = [
-            'name' => 'VCALENDAR',
+            'name'           => 'VCALENDAR',
             'is-not-defined' => false,
-            'comp-filters' => [
+            'comp-filters'   => [
                 [
-                    'name' => 'VEVENT',
+                    'name'           => 'VEVENT',
                     'is-not-defined' => false,
-                    'comp-filters' => [
+                    'comp-filters'   => [
                         [
-                            'name' => 'VALARM',
+                            'name'           => 'VALARM',
                             'is-not-defined' => true,
-                            'comp-filters' => [],
-                            'prop-filters' => [],
-                            'time-range' => false,
+                            'comp-filters'   => [],
+                            'prop-filters'   => [],
+                            'time-range'     => false,
                         ],
                     ],
                     'prop-filters' => [
                         [
-                            'name' => 'UID',
+                            'name'           => 'UID',
                             'is-not-defined' => false,
-                            'time-range' => false,
-                            'text-match' => null,
-                            'param-filters' => [],
+                            'time-range'     => false,
+                            'text-match'     => null,
+                            'param-filters'  => [],
                         ],
                         [
-                            'name' => 'X-PROP',
+                            'name'           => 'X-PROP',
                             'is-not-defined' => false,
-                            'time-range' => false,
-                            'text-match' => null,
-                            'param-filters' => [
+                            'time-range'     => false,
+                            'text-match'     => null,
+                            'param-filters'  => [
                                 [
-                                    'name' => 'X-PARAM',
+                                    'name'           => 'X-PARAM',
                                     'is-not-defined' => false,
-                                    'text-match' => null,
+                                    'text-match'     => null,
                                 ],
                                 [
-                                    'name' => 'X-PARAM2',
+                                    'name'           => 'X-PARAM2',
                                     'is-not-defined' => true,
-                                    'text-match' => null,
+                                    'text-match'     => null,
                                 ],
                                 [
-                                    'name' => 'X-PARAM3',
+                                    'name'           => 'X-PARAM3',
                                     'is-not-defined' => false,
-                                    'text-match' => [
+                                    'text-match'     => [
                                         'negate-condition' => true,
-                                        'collation' => 'i;ascii-casemap',
-                                        'value' => 'hi',    
+                                        'collation'        => 'i;ascii-casemap',
+                                        'value'            => 'hi',
                                     ],
                                 ],
                             ],
                         ],
                         [
-                            'name' => 'X-PROP2',
+                            'name'           => 'X-PROP2',
                             'is-not-defined' => true,
-                            'time-range' => false,
-                            'text-match' => null,
-                            'param-filters' => [],
+                            'time-range'     => false,
+                            'text-match'     => null,
+                            'param-filters'  => [],
                         ],
                         [
-                            'name' => 'X-PROP3',
+                            'name'           => 'X-PROP3',
                             'is-not-defined' => false,
-                            'time-range' => [
+                            'time-range'     => [
                                 'start' => new \DateTime('2015-01-01 00:00:00', new \DateTimeZone('UTC')),
-                                'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
-                            ], 
-                            'text-match' => null,
+                                'end'   => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
+                            ],
+                            'text-match'    => null,
                             'param-filters' => [],
                         ],
                         [
-                            'name' => 'X-PROP4',
+                            'name'           => 'X-PROP4',
                             'is-not-defined' => false,
-                            'time-range' => false, 
-                            'text-match' => [
+                            'time-range'     => false,
+                            'text-match'     => [
                                 'negate-condition' => false,
-                                'collation' => 'i;ascii-casemap',
-                                'value' => 'Hello',
+                                'collation'        => 'i;ascii-casemap',
+                                'value'            => 'Hello',
                             ],
                             'param-filters' => [],
                         ],
                     ],
                     'time-range' => [
                         'start' => new \DateTime('2015-01-01 00:00:00', new \DateTimeZone('UTC')),
-                        'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
+                        'end'   => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
                     ]
                 ],
             ],
             'prop-filters' => [],
-            'time-range' => false,
+            'time-range'   => false,
         ];
 
         $this->assertEquals(
diff --git a/tests/Sabre/CalDAV/Xml/Request/ShareTest.php b/tests/Sabre/CalDAV/Xml/Request/ShareTest.php
new file mode 100644
index 0000000..ad9e130
--- /dev/null
+++ b/tests/Sabre/CalDAV/Xml/Request/ShareTest.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace Sabre\CalDAV\Xml\Request;
+
+use Sabre\DAV\Xml\XmlTest;
+
+class ShareTest extends XmlTest {
+
+    protected $elementMap = [
+        '{http://calendarserver.org/ns/}share' => 'Sabre\\CalDAV\\Xml\\Request\\Share',
+    ];
+
+    function testDeserialize() {
+
+        $xml = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+   <CS:share xmlns:D="DAV:"
+                 xmlns:CS="http://calendarserver.org/ns/">
+     <CS:set>
+       <D:href>mailto:eric at example.com</D:href>
+       <CS:common-name>Eric York</CS:common-name>
+       <CS:summary>Shared workspace</CS:summary>
+       <CS:read-write />
+     </CS:set>
+     <CS:remove>
+       <D:href>mailto:foo at bar</D:href>
+     </CS:remove>
+   </CS:share>
+XML;
+
+        $result = $this->parse($xml);
+        $share = new Share(
+            [
+                [
+                    'href'       => 'mailto:eric at example.com',
+                    'commonName' => 'Eric York',
+                    'summary'    => 'Shared workspace',
+                    'readOnly'   => false,
+                ]
+            ],
+            [
+                'mailto:foo at bar',
+            ]
+        );
+
+        $this->assertEquals(
+            $share,
+            $result['value']
+        );
+
+    }
+
+    function testDeserializeMininal() {
+
+        $xml = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+   <CS:share xmlns:D="DAV:"
+                 xmlns:CS="http://calendarserver.org/ns/">
+     <CS:set>
+       <D:href>mailto:eric at example.com</D:href>
+        <CS:read />
+     </CS:set>
+   </CS:share>
+XML;
+
+        $result = $this->parse($xml);
+        $share = new Share(
+            [
+                [
+                    'href'       => 'mailto:eric at example.com',
+                    'commonName' => null,
+                    'summary'    => null,
+                    'readOnly'   => true,
+                ]
+            ],
+            []
+        );
+
+        $this->assertEquals(
+            $share,
+            $result['value']
+        );
+
+    }
+
+}

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