2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
47 require('include/modules.php');
48 $GLOBALS['beanList'] = $beanList;
49 $GLOBALS['beanFiles'] = $beanFiles;
50 $GLOBALS['beanList']['vCardMockModule'] = 'vCardMockModule';
51 $GLOBALS['beanFiles']['vCardMockModule'] = 'tests/include/vCard/vCardTest.php';
54 public function tearDown()
56 unset($GLOBALS['current_user']);
57 unset($GLOBALS['beanList']);
58 unset($GLOBALS['beanFiles']);
59 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
65 public function testImportedVcardWithDifferentCharsetIsTranslatedToTheDefaultCharset()
67 $filename = dirname(__FILE__)."/ISO88591SampleFile.vcf";
68 $module = "vCardMockModule";
71 $record = $vcard->importVCard($filename,$module);
73 $bean = new vCardMockModule;
74 $bean = $bean->retrieve($record);
76 $this->assertEquals('Hans Müster',$bean->first_name.' '.$bean->last_name);
79 public function testImportedVcardWithSameCharsetIsNotTranslated()
81 $filename = dirname(__FILE__)."/UTF8SampleFile.vcf";
82 $module = "vCardMockModule";
85 $record = $vcard->importVCard($filename,$module);
87 $bean = new vCardMockModule;
88 $bean = $bean->retrieve($record);
90 $this->assertEquals('Hans Müster',$bean->first_name.' '.$bean->last_name);
93 public function vCardNames()
96 array('', "Last Name"),
97 array('First Name', "Last Name"),
98 array("Иван", "Č, Ć ŐŐŐ Lastname"),
104 * @dataProvider vCardNames
106 public function testExportVcard($fname, $lname)
108 $vcard = new vCard();
110 $data = new vCardMockModule();
111 $data->first_name = $fname;
112 $data->last_name = $lname;
113 $GLOBALS['current_user']->setPreference('default_export_charset', 'UTF-8');
116 $vcard->loadContact($id, 'vCardMockModule');
117 $cardtext = $vcard->toString();
119 $this->assertContains("N;CHARSET=utf-8:$lname;$fname", $cardtext, "Cannot find N name", true);
120 $this->assertContains("FN;CHARSET=utf-8: $fname $lname", $cardtext, "Cannot find FN name", true);
123 public function testClear()
125 $vcard = new vCard();
126 $vcard->setProperty('dog','cat');
129 $this->assertNull($vcard->getProperty('dog'));
132 public function testSetProperty()
134 $vcard = new vCard();
135 $vcard->setProperty('dog','cat');
137 $this->assertEquals('cat',$vcard->getProperty('dog'));
140 public function testGetPropertyThatDoesNotExist()
142 $vcard = new vCard();
144 $this->assertNull($vcard->getProperty('dog'));
147 public function testSetTitle()
149 $vcard = new vCard();
150 $vcard->setTitle('cat');
152 $this->assertEquals('cat',$vcard->getProperty('TITLE'));
155 public function testSetORG()
157 $vcard = new vCard();
158 $vcard->setORG('foo','bar');
160 $this->assertEquals('foo;bar',$vcard->getProperty('ORG'));
164 class vCardMockModule extends Person
166 public static $_savedObjects = array();
173 public $phone_mobile;
176 public $primary_address_street;
177 public $primary_address_city;
178 public $primary_address_state;
179 public $primary_address_postalcode;
180 public $primary_address_country;
184 public function save()
186 $this->id = create_guid();
188 self::$_savedObjects[$this->id] = $this;
193 public function retrieve($id = -1, $encode=true,$deleted=true)
195 if ( isset(self::$_savedObjects[$id]) ) {
196 foreach(get_object_vars(self::$_savedObjects[$id]) as $var => $val) {
199 return self::$_savedObjects[$id];
205 public function ACLFilterFields()