[Pkg-owncloud-commits] [php-sabredav] 23/29: Added a bunch of tests. Increasing the coverage a bit.

David Prévot taffit at moszumanska.debian.org
Fri Jul 8 00:24:04 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 f74384045932f0a8035a95385f265736d8aaea02
Author: Evert Pot <me at evertpot.com>
Date:   Mon Jun 27 22:27:36 2016 -0400

    Added a bunch of tests. Increasing the coverage a bit.
---
 examples/calendarserver.php                        |  4 ++
 lib/CalDAV/Backend/PDO.php                         |  2 +-
 lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php | 22 ++-----
 lib/DAV/Auth/Backend/File.php                      |  2 +-
 lib/DAV/FSExt/Directory.php                        | 10 +---
 lib/DAV/Xml/Property/ShareAccess.php               |  2 +-
 lib/DAV/Xml/Property/SupportedMethodSet.php        | 11 +---
 tests/Sabre/CalDAV/Backend/AbstractPDOTest.php     | 10 ++++
 tests/Sabre/CalDAV/Xml/Property/InviteTest.php     |  5 +-
 tests/Sabre/DAV/Auth/Backend/FileTest.php          |  3 +-
 tests/Sabre/DAV/Auth/PluginTest.php                | 19 ++++++
 tests/Sabre/DAV/FSExt/DirectoryTest.php            | 30 ++++++++++
 tests/Sabre/DAV/Xml/Property/ShareAccessTest.php   | 68 ++++++++++++++++++++++
 .../DAV/Xml/Property/SupportedMethodSetTest.php    | 63 ++++++++------------
 tests/Sabre/DAV/Xml/XmlTest.php                    |  7 +++
 15 files changed, 178 insertions(+), 80 deletions(-)

diff --git a/examples/calendarserver.php b/examples/calendarserver.php
index e5f9f33..c5dd029 100644
--- a/examples/calendarserver.php
+++ b/examples/calendarserver.php
@@ -68,6 +68,10 @@ $server->addPlugin(
 /* WebDAV-Sync plugin */
 $server->addPlugin(new Sabre\DAV\Sync\Plugin());
 
+/* CalDAV Sharing support */
+$server->addPlugin(new Sabre\DAV\Sharing\Plugin());
+$server->addPlugin(new Sabre\CalDAV\SharingPlugin());
+
 // Support for html frontend
 $browser = new Sabre\DAV\Browser\Plugin();
 $server->addPlugin($browser);
diff --git a/lib/CalDAV/Backend/PDO.php b/lib/CalDAV/Backend/PDO.php
index b1c013d..95f1d49 100644
--- a/lib/CalDAV/Backend/PDO.php
+++ b/lib/CalDAV/Backend/PDO.php
@@ -1502,7 +1502,7 @@ SQL;
      */
     function setPublishStatus($calendarId, $value) {
 
-        throw new \Exception('Not implemented');
+        throw new \Sabre\DAV\Exception\NotImplemented('Not implemented');
 
     }
 
diff --git a/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php b/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php
index 4a253e0..a82b8ef 100644
--- a/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php
+++ b/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php
@@ -4,8 +4,8 @@ namespace Sabre\CalDAV\Xml\Property;
 
 use Sabre\Xml\Element;
 use Sabre\Xml\Reader;
+use Sabre\Xml\Deserializer;
 use Sabre\Xml\Writer;
-use Sabre\Xml\Element\Elements;
 use Sabre\CalDAV\Plugin;
 
 /**
@@ -116,23 +116,13 @@ class ScheduleCalendarTransp implements Element {
      */
     static function xmlDeserialize(Reader $reader) {
 
-        $elems = Elements::xmlDeserialize($reader);
+        $elems = Deserializer\enum($reader, Plugin::NS_CALDAV);
 
-        $value = null;
-
-        foreach ($elems as $elem) {
-            switch ($elem) {
-                case '{' . Plugin::NS_CALDAV . '}opaque' :
-                    $value = self::OPAQUE;
-                    break;
-                case '{' . Plugin::NS_CALDAV . '}transparent' :
-                    $value = self::TRANSPARENT;
-                    break;
-            }
+        if (in_array('transparent', $elems)) {
+            $value = self::TRANSPARENT;
+        } else {
+            $value = self::OPAQUE;
         }
-        if (is_null($value))
-           return null;
-
         return new self($value);
 
     }
diff --git a/lib/DAV/Auth/Backend/File.php b/lib/DAV/Auth/Backend/File.php
index 6756e68..3a687d7 100644
--- a/lib/DAV/Auth/Backend/File.php
+++ b/lib/DAV/Auth/Backend/File.php
@@ -25,7 +25,7 @@ class File extends AbstractDigest {
     /**
      * Creates the backend object.
      *
-     * If the filename argument is passed in, it will parse out the specified file fist.
+     * If the filename argument is passed in, it will parse out the specified file first.
      *
      * @param string|null $filename
      */
diff --git a/lib/DAV/FSExt/Directory.php b/lib/DAV/FSExt/Directory.php
index 648079e..dd5f992 100644
--- a/lib/DAV/FSExt/Directory.php
+++ b/lib/DAV/FSExt/Directory.php
@@ -131,12 +131,7 @@ class Directory extends Node implements DAV\ICollection, DAV\IQuota, DAV\IMoveTa
 
         foreach ($iterator as $entry) {
 
-            $node = $entry->getFilename();
-
-            if ($node === '.sabredav')
-                continue;
-
-            $nodes[] = $this->getChild($node);
+            $nodes[] = $this->getChild($entry->getFilename());
 
         }
         return $nodes;
@@ -153,9 +148,6 @@ class Directory extends Node implements DAV\ICollection, DAV\IQuota, DAV\IMoveTa
         // Deleting all children
         foreach ($this->getChildren() as $child) $child->delete();
 
-        // Removing resource info, if its still around
-        if (file_exists($this->path . '/.sabredav')) unlink($this->path . '/.sabredav');
-
         // Removing the directory itself
         rmdir($this->path);
 
diff --git a/lib/DAV/Xml/Property/ShareAccess.php b/lib/DAV/Xml/Property/ShareAccess.php
index f27af54..a3fc6b0 100644
--- a/lib/DAV/Xml/Property/ShareAccess.php
+++ b/lib/DAV/Xml/Property/ShareAccess.php
@@ -127,7 +127,7 @@ class ShareAccess implements Element {
             switch ($elem['name']) {
                 case '{DAV:}not-shared' :
                     return new self(SharingPlugin::ACCESS_NOTSHARED);
-                case '{DAV:}sharedowner' :
+                case '{DAV:}shared-owner' :
                     return new self(SharingPlugin::ACCESS_SHAREDOWNER);
                 case '{DAV:}read' :
                     return new self(SharingPlugin::ACCESS_READ);
diff --git a/lib/DAV/Xml/Property/SupportedMethodSet.php b/lib/DAV/Xml/Property/SupportedMethodSet.php
index 56b418d..7641f37 100644
--- a/lib/DAV/Xml/Property/SupportedMethodSet.php
+++ b/lib/DAV/Xml/Property/SupportedMethodSet.php
@@ -32,16 +32,11 @@ class SupportedMethodSet implements XmlSerializable, HtmlOutput {
     /**
      * Creates the property
      *
-     * Any reports passed in the constructor
-     * should be valid report-types in clark-notation.
-     *
-     * Either a string or an array of strings must be passed.
-     *
-     * @param string|string[] $methods
+     * @param string[] $methods
      */
-    function __construct($methods = null) {
+    function __construct(array $methods) {
 
-        $this->methods = (array)$methods;
+        $this->methods = $methods;
 
     }
 
diff --git a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
index 35d6da3..2a00f79 100644
--- a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
+++ b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
@@ -1418,4 +1418,14 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
 
     }
 
+    /**
+     * @expectedException \Sabre\DAV\Exception\NotImplemented
+     */
+    function testSetPublishStatus() {
+
+        $backend = new PDO($this->pdo);
+        $backend->setPublishStatus([1, 1], true);
+
+    }
+
 }
diff --git a/tests/Sabre/CalDAV/Xml/Property/InviteTest.php b/tests/Sabre/CalDAV/Xml/Property/InviteTest.php
index 647139a..485f012 100644
--- a/tests/Sabre/CalDAV/Xml/Property/InviteTest.php
+++ b/tests/Sabre/CalDAV/Xml/Property/InviteTest.php
@@ -19,8 +19,9 @@ class InviteTest extends DAV\Xml\XmlTest {
 
     function testSimple() {
 
-        $sccs = new Invite([]);
-        $this->assertInstanceOf('Sabre\CalDAV\Xml\Property\Invite', $sccs);
+        $invite = new Invite([]);
+        $this->assertInstanceOf('Sabre\CalDAV\Xml\Property\Invite', $invite);
+        $this->assertEquals([], $invite->getValue());
 
     }
 
diff --git a/tests/Sabre/DAV/Auth/Backend/FileTest.php b/tests/Sabre/DAV/Auth/Backend/FileTest.php
index 9b66d64..f694f48 100644
--- a/tests/Sabre/DAV/Auth/Backend/FileTest.php
+++ b/tests/Sabre/DAV/Auth/Backend/FileTest.php
@@ -23,8 +23,7 @@ class FileTest extends \PHPUnit_Framework_TestCase {
     function testLoadFileBroken() {
 
         file_put_contents(SABRE_TEMPDIR . '/backend', 'user:realm:hash');
-        $file = new File();
-        $file->loadFile(SABRE_TEMPDIR . '/backend');
+        $file = new File(SABRE_TEMPDIR . '/backend');
 
     }
 
diff --git a/tests/Sabre/DAV/Auth/PluginTest.php b/tests/Sabre/DAV/Auth/PluginTest.php
index 3ed79a7..b566dd7 100644
--- a/tests/Sabre/DAV/Auth/PluginTest.php
+++ b/tests/Sabre/DAV/Auth/PluginTest.php
@@ -49,6 +49,25 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
     }
 
     /**
+     * @depends testAuthenticateFail
+     */
+    function testAuthenticateFailDontAutoRequire() {
+
+        $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
+        $backend = new Backend\Mock();
+        $backend->fail = true;
+
+        $plugin = new Plugin($backend);
+        $plugin->autoRequireLogin = false;
+        $fakeServer->addPlugin($plugin);
+        $this->assertTrue(
+            $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()])
+        );
+        $this->assertEquals(1, count($plugin->getLoginFailedReasons()));
+
+    }
+
+    /**
      * @depends testAuthenticate
      */
     function testMultipleBackend() {
diff --git a/tests/Sabre/DAV/FSExt/DirectoryTest.php b/tests/Sabre/DAV/FSExt/DirectoryTest.php
new file mode 100644
index 0000000..097ebd2
--- /dev/null
+++ b/tests/Sabre/DAV/FSExt/DirectoryTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Sabre\DAV\FSExt;
+
+class DirectoryTest extends \PHPUnit_Framework_TestCase {
+
+    function create() {
+
+        return new Directory(SABRE_TEMPDIR);
+
+    }
+
+    function testCreate() {
+
+        $dir = $this->create();
+        $this->assertEquals(basename(SABRE_TEMPDIR), $dir->getName());
+
+    }
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\Forbidden
+     */
+    function testChildExistDot() {
+
+        $dir = $this->create();
+        $dir->childExists('..');
+
+    }
+
+}
diff --git a/tests/Sabre/DAV/Xml/Property/ShareAccessTest.php b/tests/Sabre/DAV/Xml/Property/ShareAccessTest.php
index 526329a..17190a5 100644
--- a/tests/Sabre/DAV/Xml/Property/ShareAccessTest.php
+++ b/tests/Sabre/DAV/Xml/Property/ShareAccessTest.php
@@ -50,4 +50,72 @@ XML;
 
     }
 
+    function testDeserialize() {
+
+        $input = <<<XML
+<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+  <d:share-access><d:read /></d:share-access>
+  <d:share-access><d:read-write /></d:share-access>
+  <d:share-access><d:not-shared /></d:share-access>
+  <d:share-access><d:no-access /></d:share-access>
+  <d:share-access><d:shared-owner /></d:share-access>
+</d:root>
+XML;
+
+        $data = [
+            [
+                'name'       => '{DAV:}share-access',
+                'value'      => new ShareAccess(Plugin::ACCESS_READ),
+                'attributes' => [],
+            ],
+            [
+                'name'       => '{DAV:}share-access',
+                'value'      => new ShareAccess(Plugin::ACCESS_READWRITE),
+                'attributes' => [],
+            ],
+            [
+                'name'       => '{DAV:}share-access',
+                'value'      => new ShareAccess(Plugin::ACCESS_NOTSHARED),
+                'attributes' => [],
+            ],
+            [
+                'name'       => '{DAV:}share-access',
+                'value'      => new ShareAccess(Plugin::ACCESS_NOACCESS),
+                'attributes' => [],
+            ],
+            [
+                'name'       => '{DAV:}share-access',
+                'value'      => new ShareAccess(Plugin::ACCESS_SHAREDOWNER),
+                'attributes' => [],
+            ],
+
+        ];
+
+        $this->assertParsedValue(
+            $data,
+            $input,
+            ['{DAV:}share-access' => ShareAccess::class]
+        );
+
+    }
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\BadRequest
+     */
+    function testDeserializeInvalid() {
+
+        $input = <<<XML
+<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+  <d:share-access><d:foo /></d:share-access>
+</d:root>
+XML;
+
+        $this->parse(
+            $input,
+            ['{DAV:}share-access' => ShareAccess::class]
+        );
+
+    }
 }
diff --git a/tests/Sabre/DAV/Xml/Property/SupportedMethodSetTest.php b/tests/Sabre/DAV/Xml/Property/SupportedMethodSetTest.php
index f5fa330..429af42 100644
--- a/tests/Sabre/DAV/Xml/Property/SupportedMethodSetTest.php
+++ b/tests/Sabre/DAV/Xml/Property/SupportedMethodSetTest.php
@@ -2,60 +2,43 @@
 
 namespace Sabre\DAV\Xml\Property;
 
-use Sabre\DAV;
-use Sabre\HTTP;
+use Sabre\DAV\Xml\XmlTest;
 
-require_once 'Sabre/HTTP/ResponseMock.php';
-require_once 'Sabre/DAV/AbstractServer.php';
+class SupportedMethodSetTest extends XmlTest {
 
-class SupportedMethodSetTest extends DAV\AbstractServer {
+    function testSimple() {
 
-    function sendPROPFIND($body) {
+        $cus = new SupportedMethodSet(['GET', 'PUT']);
+        $this->assertEquals(['GET', 'PUT'], $cus->getValue());
 
-        $request = new HTTP\Request('PROPFIND', '/', ['Depth' => '0' ]);
-        $request->setBody($body);
-
-        $this->server->httpRequest = $request;
-        $this->server->exec();
+        $this->assertTrue($cus->has('GET'));
+        $this->assertFalse($cus->has('HEAD'));
 
     }
 
-    /**
-     */
-    function testMethods() {
-
-        $xml = '<?xml version="1.0"?>
-<d:propfind xmlns:d="DAV:">
-  <d:prop>
-    <d:supported-method-set />
-  </d:prop>
-</d:propfind>';
-
-        $this->sendPROPFIND($xml);
-
-        $this->assertEquals(207, $this->response->status, 'We expected a multi-status response. Full response body: ' . $this->response->body);
+    function testSerialize() {
 
-        $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
-        $xml = simplexml_load_string($body);
-        $xml->registerXPathNamespace('d', 'urn:DAV');
+        $cus = new SupportedMethodSet(['GET', 'PUT']);
+        $xml = $this->write(['{DAV:}foo' => $cus]);
 
-        $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
-        $this->assertEquals(1, count($data), 'We expected 1 \'d:prop\' element');
+        $expected = '<?xml version="1.0"?>
+<d:foo xmlns:d="DAV:">
+    <d:supported-method name="GET"/>
+    <d:supported-method name="PUT"/>
+</d:foo>';
 
-        $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-method-set');
-        $this->assertEquals(1, count($data), 'We expected 1 \'d:supported-method-set\' element');
-
-        $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
-        $this->assertEquals(1, count($data), 'We expected 1 \'d:status\' element');
-
-        $this->assertEquals('HTTP/1.1 200 OK', (string)$data[0], 'The status for this property should have been 200');
+        $this->assertXmlStringEqualsXmlString($expected, $xml);
 
     }
 
-    function testGetObj() {
+    function testSerializeHtml() {
+
+        $cus = new SupportedMethodSet(['GET', 'PUT']);
+        $result  = $cus->toHtml(
+            new \Sabre\DAV\Browser\HtmlOutputHelper('/', [])
+        );
 
-        $result = $this->server->getProperties('/', ['{DAV:}supported-method-set']);
-        $this->assertTrue($result['{DAV:}supported-method-set']->has('PROPFIND'));
+        $this->assertEquals('GET, PUT', $result);
 
     }
 
diff --git a/tests/Sabre/DAV/Xml/XmlTest.php b/tests/Sabre/DAV/Xml/XmlTest.php
index 9867011..5b25b7f 100644
--- a/tests/Sabre/DAV/Xml/XmlTest.php
+++ b/tests/Sabre/DAV/Xml/XmlTest.php
@@ -32,6 +32,13 @@ abstract class XmlTest extends \PHPUnit_Framework_TestCase {
 
     }
 
+    function assertParsedValue($expected, $xml, array $elementMap = []) {
+
+        $result = $this->parse($xml, $elementMap);
+        $this->assertEquals($expected, $result['value']);
+
+    }
+
     function cleanUp() {
 
         libxml_clear_errors();

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