]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Import/Bug50438Test.php
Release 6.4.2
[Github/sugarcrm.git] / tests / modules / Import / Bug50438Test.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
39 /*
40  * This tests whether a relationship with parent bean is saved during import.  We simulate a call being imported with
41  * parent_id and parent_type columns filled out, which should save the relationship even during import
42  * @ticket 50438
43  */
44
45 require_once('modules/Import/Importer.php');
46 require_once('modules/Import/sources/ImportFile.php');
47
48 class Bug50438Test extends Sugar_PHPUnit_Framework_TestCase
49 {
50
51     var $contact;
52     var $fileArr;
53     var $call_id;
54     public function setUp()
55     {
56         global $currentModule ;
57         $this->call_id = create_guid();
58                 $mod_strings = return_module_language($GLOBALS['current_language'], "Contacts");
59         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
60
61         //create a contact
62         $this->contact = new Contact();
63         $this->contact->first_name = 'Joe UT ';
64         $this->contact->last_name = 'Smith UT 50438';
65         $this->contact->disable_custom_fields = true;
66         $this->contact->save();
67
68         //create array to output as import file using the new contact as the related parent
69         $this->fileArr = array(
70             0=> "\"{$this->call_id}\",\"Call for Unit Test 50438\",\"Planned\", \"{$this->contact->module_dir}\",\"{$this->contact->id}\""
71         );
72     }
73
74     public function tearDown()
75     {
76
77         $GLOBALS['db']->query("DELETE FROM calls WHERE id='{$this->call_id}'");
78         $GLOBALS['db']->query("DELETE FROM contacts WHERE id='{$this->contact->id}'");
79         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
80         unset($this->call_id);
81         unset($this->contact);
82         unset($this->fileArr);
83         unset( $GLOBALS['current_user']);
84         unset( $GLOBALS['mod_strings']);
85     }
86
87
88
89     public function testParentsAreRelatedDuringImport()
90     {
91
92         //$file = 'upload://test50438.csv';
93         $upload_dir = isset($GLOBALS['sugar_config']['upload_dir']) ? $GLOBALS['sugar_config']['upload_dir'] : 'upload';
94         $file = $upload_dir . '/test50438.csv';
95
96         $ret = file_put_contents($file, $this->fileArr);
97         $this->assertGreaterThan(0, $ret, 'Failed to write to '.$file .' for content '.var_export($this->fileArr,true));
98
99         $importSource = new ImportFile($file, ',', '"');
100
101         $bean = loadBean('Calls');
102
103         $_REQUEST['columncount'] = 5;
104         $_REQUEST['colnum_0'] = 'id';
105         $_REQUEST['colnum_1'] = 'subject';
106         $_REQUEST['colnum_2'] = 'status';
107         $_REQUEST['colnum_3'] = 'parent_type';
108         $_REQUEST['colnum_4'] = 'parent_id';
109         $_REQUEST['import_module'] = 'Contacts';
110         $_REQUEST['importlocale_charset'] = 'UTF-8';
111         $_REQUEST['importlocale_timezone'] = 'GMT';
112         $_REQUEST['importlocale_default_currency_significant_digits'] = '2';
113         $_REQUEST['importlocale_currency'] = '-99';
114         $_REQUEST['importlocale_dec_sep'] = '.';
115         $_REQUEST['importlocale_currency'] = '-99';
116         $_REQUEST['importlocale_default_locale_name_format'] = 's f l';
117         $_REQUEST['importlocale_num_grp_sep'] = ',';
118         $_REQUEST['importlocale_dateformat'] = 'm/d/y';
119         $_REQUEST['importlocale_timeformat'] = 'h:i:s';
120
121         $importer = new Importer($importSource, $bean);
122         $importer->import();
123
124         //fetch the bean using the passed in id and get related contacts
125         require_once('modules/Calls/Call.php');
126         $call = new Call();
127         $call->retrieve($this->call_id);
128         $call->load_relationship('contacts');
129         $related_contacts = $call->contacts->get();
130
131         //test that the contact id is in the array of related contacts.
132         $this->assertContains($this->contact->id, $related_contacts,' Contact was not related during simulated import despite being set in related parent id');
133         unset($call);
134         unlink($file);
135     }
136
137 }