]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/vCard/vCardTest.php
Release 6.5.3
[Github/sugarcrm.git] / tests / include / vCard / vCardTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37  
38 require_once 'include/vCard.php';
39
40 class vCardTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42     public function setUp()
43     {
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';
50     }
51
52     public function tearDown()
53     {
54         SugarTestHelper::tearDown();
55     }
56
57     /**
58      * @ticket 10419
59      */
60         public function testImportedVcardWithDifferentCharsetIsTranslatedToTheDefaultCharset()
61     {
62         $filename  = dirname(__FILE__)."/ISO88591SampleFile.vcf";
63         $module = "vCardMockModule";
64
65         $vcard = new vCard();
66         $record = $vcard->importVCard($filename,$module);
67
68         $bean = new vCardMockModule;
69         $bean = $bean->retrieve($record);
70
71         $this->assertEquals('Hans Müster',$bean->first_name.' '.$bean->last_name);
72     }
73
74     public function testImportedVcardWithSameCharsetIsNotTranslated()
75     {
76         $filename  = dirname(__FILE__)."/UTF8SampleFile.vcf";
77         $module = "vCardMockModule";
78
79         $vcard = new vCard();
80         $record = $vcard->importVCard($filename,$module);
81
82         $bean = new vCardMockModule;
83         $bean = $bean->retrieve($record);
84
85         $this->assertEquals('Hans Müster',$bean->first_name.' '.$bean->last_name);
86     }
87
88     public function vCardNames()
89     {
90         return array(
91             array('', "Last Name"),
92             array('First Name', "Last Name"),
93             array("Иван", "Č, Ć ŐŐŐ Lastname"),
94         );
95     }
96
97     /**
98      * @ticket 24487
99          * @dataProvider vCardNames
100      */
101     public function testExportVcard($fname, $lname)
102     {
103         $vcard = new vCard();
104
105         $data = new vCardMockModule();
106         $data->first_name = $fname;
107         $data->last_name = $lname;
108         $GLOBALS['current_user']->setPreference('default_export_charset', 'UTF-8');
109         $id = $data->save();
110
111         $vcard->loadContact($id, 'vCardMockModule');
112         $cardtext = $vcard->toString();
113
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);
116     }
117     
118     public function testClear()
119     {
120         $vcard = new vCard();
121         $vcard->setProperty('dog','cat');
122         $vcard->clear();
123         
124         $this->assertNull($vcard->getProperty('dog'));
125     }
126     
127     public function testSetProperty()
128     {
129         $vcard = new vCard();
130         $vcard->setProperty('dog','cat');
131         
132         $this->assertEquals('cat',$vcard->getProperty('dog'));
133     }
134     
135     public function testGetPropertyThatDoesNotExist()
136     {
137         $vcard = new vCard();
138         
139         $this->assertNull($vcard->getProperty('dog'));
140     }
141     
142     public function testSetTitle()
143     {
144         $vcard = new vCard();
145         $vcard->setTitle('cat');
146         
147         $this->assertEquals('cat',$vcard->getProperty('TITLE'));
148     }
149     
150     public function testSetORG()
151     {
152         $vcard = new vCard();
153         $vcard->setORG('foo','bar');
154         
155         $this->assertEquals('foo;bar',$vcard->getProperty('ORG'));
156     }
157 }
158
159 class vCardMockModule extends Person
160 {
161     public static $_savedObjects = array();
162     
163     public $first_name;
164     public $last_name;
165     public $salutation;
166     public $phone_fax;
167     public $phone_home;
168     public $phone_mobile;
169     public $phone_work;
170     public $email1;
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;
176     public $department;
177     public $title;
178
179     public function save()
180     {
181         $this->id = create_guid();
182
183         self::$_savedObjects[$this->id] = $this;
184
185         return $this->id;
186     }
187
188     public function retrieve($id = -1, $encode=true,$deleted=true)
189         {
190         if ( isset(self::$_savedObjects[$id]) ) {
191             foreach(get_object_vars(self::$_savedObjects[$id]) as $var => $val) {
192                 $this->$var = $val;
193             }
194             return self::$_savedObjects[$id];
195         }
196
197         return null;
198     }
199
200     public function ACLFilterFields()
201     {
202     }
203 }