2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
38 require_once 'include/vCard.php';
40 class vCardTest extends Sugar_PHPUnit_Framework_TestCase
42 public function setUp()
44 SugarTestHelper::setUp('beanFiles');
45 SugarTestHelper::setUp('beanList');
46 SugarTestHelper::setUp('current_user');
47 SugarTestHelper::setUp('app_list_strings');
48 $GLOBALS['beanList']['vCardMockModule'] = 'vCardMockModule';
49 $GLOBALS['beanFiles']['vCardMockModule'] = 'tests/include/vCard/vCardTest.php';
52 public function tearDown()
54 SugarTestHelper::tearDown();
60 public function testImportedVcardWithDifferentCharsetIsTranslatedToTheDefaultCharset()
62 $filename = dirname(__FILE__)."/ISO88591SampleFile.vcf";
63 $module = "vCardMockModule";
66 $record = $vcard->importVCard($filename,$module);
68 $bean = new vCardMockModule;
69 $bean = $bean->retrieve($record);
71 $this->assertEquals('Hans Müster',$bean->first_name.' '.$bean->last_name);
74 public function testImportedVcardWithSameCharsetIsNotTranslated()
76 $filename = dirname(__FILE__)."/UTF8SampleFile.vcf";
77 $module = "vCardMockModule";
80 $record = $vcard->importVCard($filename,$module);
82 $bean = new vCardMockModule;
83 $bean = $bean->retrieve($record);
85 $this->assertEquals('Hans Müster',$bean->first_name.' '.$bean->last_name);
88 public function vCardNames()
91 array('', "Last Name"),
92 array('First Name', "Last Name"),
93 array("Иван", "Č, Ć ŐŐŐ Lastname"),
99 * @dataProvider vCardNames
101 public function testExportVcard($fname, $lname)
103 $vcard = new vCard();
105 $data = new vCardMockModule();
106 $data->first_name = $fname;
107 $data->last_name = $lname;
108 $GLOBALS['current_user']->setPreference('default_export_charset', 'UTF-8');
111 $vcard->loadContact($id, 'vCardMockModule');
112 $cardtext = $vcard->toString();
114 $this->assertContains("N;CHARSET=utf-8:$lname;$fname", $cardtext, "Cannot find N name", true);
115 $this->assertContains("FN;CHARSET=utf-8: $fname $lname", $cardtext, "Cannot find FN name", true);
118 public function testClear()
120 $vcard = new vCard();
121 $vcard->setProperty('dog','cat');
124 $this->assertNull($vcard->getProperty('dog'));
127 public function testSetProperty()
129 $vcard = new vCard();
130 $vcard->setProperty('dog','cat');
132 $this->assertEquals('cat',$vcard->getProperty('dog'));
135 public function testGetPropertyThatDoesNotExist()
137 $vcard = new vCard();
139 $this->assertNull($vcard->getProperty('dog'));
142 public function testSetTitle()
144 $vcard = new vCard();
145 $vcard->setTitle('cat');
147 $this->assertEquals('cat',$vcard->getProperty('TITLE'));
150 public function testSetORG()
152 $vcard = new vCard();
153 $vcard->setORG('foo','bar');
155 $this->assertEquals('foo;bar',$vcard->getProperty('ORG'));
159 class vCardMockModule extends Person
161 public static $_savedObjects = array();
168 public $phone_mobile;
171 public $primary_address_street;
172 public $primary_address_city;
173 public $primary_address_state;
174 public $primary_address_postalcode;
175 public $primary_address_country;
179 public function save()
181 $this->id = create_guid();
183 self::$_savedObjects[$this->id] = $this;
188 public function retrieve($id = -1, $encode=true,$deleted=true)
190 if ( isset(self::$_savedObjects[$id]) ) {
191 foreach(get_object_vars(self::$_savedObjects[$id]) as $var => $val) {
194 return self::$_savedObjects[$id];
200 public function ACLFilterFields()