[Pkg-owncloud-commits] [php-sabredav] 175/275: 100% test coverage.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:56:05 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 d328d6d74f93687a82428fa2bf6bc34d1f80c074
Author: Evert Pot <me at evertpot.com>
Date:   Fri Aug 22 18:33:30 2014 -0400

    100% test coverage.
---
 lib/CardDAV/Plugin.php                       | 17 ++++++++---
 tests/Sabre/CardDAV/AddressBookQueryTest.php | 45 ++++++++++++++++++++++++++++
 tests/Sabre/CardDAV/MultiGetTest.php         | 44 +++++++++++++++++++++++++++
 tests/Sabre/CardDAV/PluginTest.php           | 10 +++++++
 4 files changed, 112 insertions(+), 4 deletions(-)

diff --git a/lib/CardDAV/Plugin.php b/lib/CardDAV/Plugin.php
index 0b449b0..047ee1a 100644
--- a/lib/CardDAV/Plugin.php
+++ b/lib/CardDAV/Plugin.php
@@ -792,7 +792,7 @@ class Plugin extends DAV\ServerPlugin {
             return;
         }
 
-        $target = $this->negotiateVCard($request->getHeader('Accept'));
+        $target = $this->negotiateVCard($request->getHeader('Accept'), $mimeType);
 
         $newBody = $this->convertVCard(
             $response->getBody(),
@@ -800,8 +800,8 @@ class Plugin extends DAV\ServerPlugin {
         );
 
         $response->setBody($newBody);
-        $response->setHeader('Content-Type', $result . '; charset=utf-8');
-        $response->setHeader('Content-Length', strlen($body));
+        $response->setHeader('Content-Type', $mimeType . '; charset=utf-8');
+        $response->setHeader('Content-Length', strlen($newBody));
 
     }
 
@@ -839,9 +839,11 @@ class Plugin extends DAV\ServerPlugin {
      *
      * It defaults to vcard3.
      *
+     * @param string $input
+     * @param string $mimeType
      * @return string
      */
-    protected function negotiateVCard($input) {
+    protected function negotiateVCard($input, &$mimeType = null) {
 
         $result = HTTP\Util::negotiate(
             $input,
@@ -860,19 +862,23 @@ class Plugin extends DAV\ServerPlugin {
             ]
         );
 
+        $mimeType = $result;
         switch($result) {
 
             default :
             case 'text/x-vcard' :
             case 'text/vcard' :
             case 'text/vcard; version=3.0' :
+                $mimeType = 'text/vcard';
                 return 'vcard3';
             case 'text/vcard; version=4.0' :
                 return 'vcard4';
             case 'application/vcard+json' :
                 return 'jcard';
 
+        // @codeCoverageIgnoreStart
         }
+        // @codeCoverageIgnoreEnd
 
     }
 
@@ -897,7 +903,10 @@ class Plugin extends DAV\ServerPlugin {
             case 'jcard' :
                 $data = $data->convert(VObject\Document::VCARD40);
                 return json_encode($data->jsonSerialize());
+
+        // @codeCoverageIgnoreStart
         }
+        // @codeCoverageIgnoreEnd
 
     }
 
diff --git a/tests/Sabre/CardDAV/AddressBookQueryTest.php b/tests/Sabre/CardDAV/AddressBookQueryTest.php
index 08d248a..718d390 100644
--- a/tests/Sabre/CardDAV/AddressBookQueryTest.php
+++ b/tests/Sabre/CardDAV/AddressBookQueryTest.php
@@ -232,6 +232,51 @@ class AddressBookQueryTest extends AbstractPluginTest {
 
     }
 
+    function testVCard4() {
+
+        $request = new HTTP\Request(
+            'REPORT',
+            '/addressbooks/user1/book1/card1',
+            ['Depth' => '0']
+        );
+
+        $request->setBody(
+'<?xml version="1.0"?>
+<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
+    <d:prop>
+      <c:address-data content-type="text/vcard" version="4.0" />
+      <d:getetag />
+    </d:prop>
+</c:addressbook-query>'
+            );
+
+        $response = new HTTP\ResponseMock();
+
+        $this->server->httpRequest = $request;
+        $this->server->httpResponse = $response;
+
+        $this->server->exec();
+
+        $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
+
+        // using the client for parsing
+        $client = new DAV\Client(array('baseUri'=>'/'));
+
+        $result = $client->parseMultiStatus($response->body);
+
+        $vobjVersion = \Sabre\VObject\Version::VERSION;
+
+        $this->assertEquals(array(
+            '/addressbooks/user1/book1/card1' => array(
+                200 => array(
+                    '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"',
+                    '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\nPRODID:-//Sabre//Sabre VObject $vobjVersion//EN\r\nUID:12345\r\nEND:VCARD\r\n",
+                ),
+             ),
+        ), $result);
+
+    }
+
     function testAddressBookDepth0() {
 
         $request = new HTTP\Request(
diff --git a/tests/Sabre/CardDAV/MultiGetTest.php b/tests/Sabre/CardDAV/MultiGetTest.php
index 621754e..b0ee458 100644
--- a/tests/Sabre/CardDAV/MultiGetTest.php
+++ b/tests/Sabre/CardDAV/MultiGetTest.php
@@ -52,4 +52,48 @@ class MultiGetTest extends AbstractPluginTest {
 
     }
 
+    function testMultiGetVCard4() {
+
+        $request = HTTP\Sapi::createFromServerArray(array(
+            'REQUEST_METHOD' => 'REPORT',
+            'REQUEST_URI' => '/addressbooks/user1/book1',
+        ));
+
+        $request->setBody(
+'<?xml version="1.0"?>
+<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
+    <d:prop>
+      <d:getetag />
+      <c:address-data content-type="text/vcard" version="4.0" />
+    </d:prop>
+    <d:href>/addressbooks/user1/book1/card1</d:href>
+</c:addressbook-multiget>'
+            );
+
+        $response = new HTTP\ResponseMock();
+
+        $this->server->httpRequest = $request;
+        $this->server->httpResponse = $response;
+
+        $this->server->exec();
+
+        $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
+
+        // using the client for parsing
+        $client = new DAV\Client(array('baseUri'=>'/'));
+
+        $result = $client->parseMultiStatus($response->body);
+
+        $prodId = "PRODID:-//Sabre//Sabre VObject " . \Sabre\VObject\Version::VERSION . "//EN";
+
+        $this->assertEquals(array(
+            '/addressbooks/user1/book1/card1' => array(
+                200 => array(
+                    '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
+                    '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\n$prodId\r\nUID:12345\r\nEND:VCARD\r\n",
+                )
+            )
+        ), $result);
+
+    }
 }
diff --git a/tests/Sabre/CardDAV/PluginTest.php b/tests/Sabre/CardDAV/PluginTest.php
index 4c609da..aadb04c 100644
--- a/tests/Sabre/CardDAV/PluginTest.php
+++ b/tests/Sabre/CardDAV/PluginTest.php
@@ -161,4 +161,14 @@ class PluginTest extends AbstractPluginTest {
 
     }
 
+    function testGetTransform() {
+
+        $request = new \Sabre\HTTP\Request('GET', '/addressbooks/user1/book1/card1', ['Accept: application/vcard+json']);
+        $response = new \Sabre\HTTP\ResponseMock();
+        $this->server->invokeMethod($request, $response);
+
+        $this->assertEquals(200, $response->getStatus());
+
+    }
+
 }

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