[Pkg-owncloud-commits] [php-sabre-vobject] 06/32: Support for multiple anniversaries in a vCard

David Prévot taffit at moszumanska.debian.org
Fri Nov 28 22:27:08 UTC 2014


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

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

commit 686303ea7ae7d5112fd8e1679319bd60b18c5cf6
Author: Armin Hackmann <armin at fruux.com>
Date:   Tue Nov 4 08:12:02 2014 +0100

    Support for multiple anniversaries in a vCard
---
 lib/VCardConverter.php               | 12 +++++---
 tests/VObject/VCardConverterTest.php | 55 ++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/lib/VCardConverter.php b/lib/VCardConverter.php
index a0966f8..87d6c14 100644
--- a/lib/VCardConverter.php
+++ b/lib/VCardConverter.php
@@ -194,8 +194,10 @@ class VCardConverter {
                     $newProperty->name = 'ANNIVERSARY';
                     // If we already have an anniversary property with the same
                     // value, ignore.
-                    if (isset($output->ANNIVERSARY) && $output->ANNIVERSARY->getValue() === $newProperty->getValue()) {
-                        return;
+                    foreach ($output->select('ANNIVERSARY') as $anniversary) {
+                        if ($anniversary->getValue() === $newProperty->getValue()) {
+                            return;
+                        }
                     }
                     break;
                 case 'X-ABDATE' :
@@ -212,8 +214,10 @@ class VCardConverter {
 
                     // If we already have an anniversary property with the same
                     // value, ignore.
-                    if (isset($output->ANNIVERSARY) && $output->ANNIVERSARY->getValue() === $newProperty->getValue()) {
-                        return;
+                    foreach ($output->select('ANNIVERSARY') as $anniversary) {
+                        if ($anniversary->getValue() === $newProperty->getValue()) {
+                            return;
+                        }
                     }
                     $newProperty->name = 'ANNIVERSARY';
                     break;
diff --git a/tests/VObject/VCardConverterTest.php b/tests/VObject/VCardConverterTest.php
index 3632ccb..c4e40ee 100644
--- a/tests/VObject/VCardConverterTest.php
+++ b/tests/VObject/VCardConverterTest.php
@@ -432,4 +432,59 @@ OUT;
         );
 
     }
+
+    function testMultipleAnniversaries() {
+
+        $input = <<<IN
+BEGIN:VCARD
+VERSION:4.0
+ITEM1.ANNIVERSARY:20081210
+ITEM2.ANNIVERSARY:20091210
+ITEM3.ANNIVERSARY:20101210
+END:VCARD
+
+IN;
+
+        $output = <<<'OUT'
+BEGIN:VCARD
+VERSION:3.0
+ITEM1.X-ABDATE;VALUE=DATE-AND-OR-TIME:20081210
+ITEM1.X-ABLABEL:_$!<Anniversary>!$_
+ITEM1.X-ANNIVERSARY;VALUE=DATE-AND-OR-TIME:20081210
+ITEM2.X-ABDATE;VALUE=DATE-AND-OR-TIME:20091210
+ITEM2.X-ABLABEL:_$!<Anniversary>!$_
+ITEM2.X-ANNIVERSARY;VALUE=DATE-AND-OR-TIME:20091210
+ITEM3.X-ABDATE;VALUE=DATE-AND-OR-TIME:20101210
+ITEM3.X-ABLABEL:_$!<Anniversary>!$_
+ITEM3.X-ANNIVERSARY;VALUE=DATE-AND-OR-TIME:20101210
+END:VCARD
+
+OUT;
+
+        $vcard = Reader::read($input);
+        $vcard = $vcard->convert(Document::VCARD30);
+
+        $this->assertVObjEquals(
+            $output,
+            $vcard
+        );
+
+        // Swapping input and output
+        list(
+            $input,
+            $output
+        ) = array(
+            $output,
+            $input
+        );
+
+        $vcard = Reader::read($input);
+        $vcard = $vcard->convert(Document::VCARD40);
+
+        $this->assertVObjEquals(
+            $output,
+            $vcard
+        );
+
+    }
 }

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



More information about the Pkg-owncloud-commits mailing list