0012448: handle empty ADR TYPE property
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 20 Dec 2016 12:47:56 +0000 (13:47 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 22 Dec 2016 10:30:51 +0000 (11:30 +0100)
https://forge.tine20.org/view.php?id=12448

Change-Id: I086955224c4db9ef4f3669463592ba12aaefcfd8
Reviewed-on: http://gerrit.tine20.com/customers/3986
Tested-by: Philipp Schüle <p.schuele@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Addressbook/Convert/Contact/VCard/GenericTest.php
tests/tine20/Addressbook/Import/files/without_adr_type.vcf [new file with mode: 0644]
tine20/Addressbook/Convert/Contact/VCard/Abstract.php

index 360e438..6e67baa 100644 (file)
@@ -110,7 +110,28 @@ class Addressbook_Convert_Contact_VCard_GenericTest extends PHPUnit_Framework_Te
         
         return $contact;
     }
-    
+
+    /**
+     * test converting vcard from sogo connector to Addressbook_Model_Contact
+     *
+     * @return Addressbook_Model_Contact
+     */
+    public function testConvertToTine20ModelWithoutAddressType()
+    {
+        $vcardStream = fopen(dirname(__FILE__) . '/../../../Import/files/without_adr_type.vcf', 'r');
+
+        $converter = Addressbook_Convert_Contact_VCard_Factory::factory(Addressbook_Convert_Contact_VCard_Factory::CLIENT_GENERIC);
+
+        $contact = $converter->toTine20Model($vcardStream);
+
+        $this->assertEquals(null,          $contact->adr_one_countryname, 'no address should be set');
+        $this->assertEquals(null,          $contact->adr_two_countryname, 'no address should be set');
+    }
+
+    /**
+     * @throws Tinebase_Exception_InvalidArgument
+     * @throws Tinebase_Exception_NotFound
+     */
     public function testConvertToVCard()
     {
         $contact = $this->testConvertToTine20Model();
diff --git a/tests/tine20/Addressbook/Import/files/without_adr_type.vcf b/tests/tine20/Addressbook/Import/files/without_adr_type.vcf
new file mode 100644 (file)
index 0000000..e5b0f2b
--- /dev/null
@@ -0,0 +1,24 @@
+BEGIN:VCARD
+VERSION:3.0
+PRODID:-//Inverse inc.//SOGo Connector 1.0//EN
+UID:0134ac4e9974ee39937eb08659f774e4c6d6f061.vcf
+N:Kneschke;Lars
+FN:Lars Kneschke
+ORG:Organisation;Business Unit
+CATEGORIES:CATEGORY 1,CATEGORY 2
+ADR:Address Privat 2;Address Privat 1;City Privat;Region Privat;
+ 12345;Country Privat
+TEL;TYPE=work:+49 BUSINESS
+TEL;TYPE=home:+49 PRIVAT
+TEL;TYPE=cell:+49 MOBIL
+TEL;TYPE=fax:+49 FAX
+TEL;TYPE=pager:+49 PAGER
+X-MOZILLA-HTML:FALSE
+EMAIL;TYPE=work:l.kneschke@metaways.de
+EMAIL;TYPE=home:lars@kneschke.de
+URL;TYPE=work:http\://www.tine20.com
+URL;TYPE=home:http\://www.tine20.org
+TITLE:Titel
+BDAY:1975-01-16
+NOTE:Notes\nwith\nLine Break
+END:VCARD
\ No newline at end of file
index 7d37e46..18f2dc8 100644 (file)
@@ -88,35 +88,34 @@ abstract class Addressbook_Convert_Contact_VCard_Abstract implements Tinebase_Co
                     
                 case 'ADR':
                     $type = null;
-                    
-                    foreach ($property['TYPE'] as $typeProperty) {
-                        $typeProperty = strtolower($typeProperty);
-                        
-                        if (in_array($typeProperty, array('home','work'))) {
-                            $type = $typeProperty;
-                            break;
+
+                    if (isset($property['TYPE']) && (is_array($property['TYPE']) || $property['TYPE'] instanceof Traversable)) {
+                        foreach ($property['TYPE'] as $typeProperty) {
+                            $typeProperty = strtolower($typeProperty);
+
+                            if (in_array($typeProperty, array('home', 'work'))) {
+                                $type = $typeProperty;
+                                break;
+                            }
                         }
                     }
-                    
-                    $parts = $property->getParts();
 
-                    if ($type == 'home') {
-                        // home address
-                        $data['adr_two_street2']     = $parts[1];
-                        $data['adr_two_street']      = $parts[2];
-                        $data['adr_two_locality']    = $parts[3];
-                        $data['adr_two_region']      = $parts[4];
-                        $data['adr_two_postalcode']  = $parts[5];
-                        $data['adr_two_countryname'] = $parts[6];
-                    } elseif ($type == 'work') {
-                        // work address
-                        $data['adr_one_street2']     = $parts[1];
-                        $data['adr_one_street']      = $parts[2];
-                        $data['adr_one_locality']    = $parts[3];
-                        $data['adr_one_region']      = $parts[4];
-                        $data['adr_one_postalcode']  = $parts[5];
-                        $data['adr_one_countryname'] = $parts[6];
+                    if ($type) {
+                        $parts = $property->getParts();
+                        $partsIndex = 1;
+
+                        if ($type == 'home') {
+                            // home address
+                            $addressFields = array('adr_two_street2', 'adr_two_street', 'adr_two_locality', 'adr_two_region', 'adr_two_postalcode', 'adr_two_countryname');
+                        } elseif ($type == 'work') {
+                            // work address
+                            $addressFields = array('adr_one_street2', 'adr_one_street', 'adr_one_locality', 'adr_one_region', 'adr_one_postalcode', 'adr_one_countryname');
+                        }
+                        foreach ($addressFields as $field) {
+                            $data[$field] = $parts[$partsIndex++];
+                        }
                     }
+
                     break;
                     
                 case 'CATEGORIES':