]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/vCard/vCardTest.php
Release 6.2.0
[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-2011 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         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
45         $beanList = array();
46         $beanFiles = array();
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';
52     }
53
54     public function tearDown()
55     {
56         unset($GLOBALS['current_user']);
57         unset($GLOBALS['beanList']);
58         unset($GLOBALS['beanFiles']);
59         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
60     }
61
62     /**
63      * @ticket 10419
64      */
65         public function testImportedVcardWithDifferentCharsetIsTranslatedToTheDefaultCharset()
66     {
67         $filename  = dirname(__FILE__)."/ISO88591SampleFile.vcf";
68         $module = "vCardMockModule";
69
70         $vcard = new vCard();
71         $record = $vcard->importVCard($filename,$module);
72
73         $bean = new vCardMockModule;
74         $bean = $bean->retrieve($record);
75
76         $this->assertEquals('Hans Müster',$bean->first_name.' '.$bean->last_name);
77     }
78
79     public function testImportedVcardWithSameCharsetIsNotTranslated()
80     {
81         $filename  = dirname(__FILE__)."/UTF8SampleFile.vcf";
82         $module = "vCardMockModule";
83
84         $vcard = new vCard();
85         $record = $vcard->importVCard($filename,$module);
86
87         $bean = new vCardMockModule;
88         $bean = $bean->retrieve($record);
89
90         $this->assertEquals('Hans Müster',$bean->first_name.' '.$bean->last_name);
91     }
92
93     public function vCardNames()
94     {
95         return array(
96             array('', "Last Name"),
97             array('First Name', "Last Name"),
98             array("Иван", "Č, Ć ŐŐŐ Lastname"),
99         );
100     }
101
102     /**
103      * @ticket 24487
104          * @dataProvider vCardNames
105      */
106     public function testExportVcard($fname, $lname)
107     {
108         $vcard = new vCard();
109
110         $data = new vCardMockModule();
111         $data->first_name = $fname;
112         $data->last_name = $lname;
113         $GLOBALS['current_user']->setPreference('default_export_charset', 'UTF-8');
114         $id = $data->save();
115
116         $vcard->loadContact($id, 'vCardMockModule');
117         $cardtext = $vcard->toString();
118
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);
121     }
122     
123     public function testClear()
124     {
125         $vcard = new vCard();
126         $vcard->setProperty('dog','cat');
127         $vcard->clear();
128         
129         $this->assertNull($vcard->getProperty('dog'));
130     }
131     
132     public function testSetProperty()
133     {
134         $vcard = new vCard();
135         $vcard->setProperty('dog','cat');
136         
137         $this->assertEquals('cat',$vcard->getProperty('dog'));
138     }
139     
140     public function testGetPropertyThatDoesNotExist()
141     {
142         $vcard = new vCard();
143         
144         $this->assertNull($vcard->getProperty('dog'));
145     }
146     
147     public function testSetTitle()
148     {
149         $vcard = new vCard();
150         $vcard->setTitle('cat');
151         
152         $this->assertEquals('cat',$vcard->getProperty('TITLE'));
153     }
154     
155     public function testSetORG()
156     {
157         $vcard = new vCard();
158         $vcard->setORG('foo','bar');
159         
160         $this->assertEquals('foo;bar',$vcard->getProperty('ORG'));
161     }
162 }
163
164 class vCardMockModule extends Person
165 {
166     public static $_savedObjects = array();
167     
168     public $first_name;
169     public $last_name;
170     public $salutation;
171     public $phone_fax;
172     public $phone_home;
173     public $phone_mobile;
174     public $phone_work;
175     public $email1;
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;
181     public $department;
182     public $title;
183
184     public function save()
185     {
186         $this->id = create_guid();
187
188         self::$_savedObjects[$this->id] = $this;
189
190         return $this->id;
191     }
192
193     public function retrieve($id = -1, $encode=true,$deleted=true)
194         {
195         if ( isset(self::$_savedObjects[$id]) ) {
196             foreach(get_object_vars(self::$_savedObjects[$id]) as $var => $val) {
197                 $this->$var = $val;
198             }
199             return self::$_savedObjects[$id];
200         }
201
202         return null;
203     }
204
205     public function ACLFilterFields()
206     {
207     }
208 }