]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Import/Bug46411Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / modules / Import / Bug46411Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 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('modules/Import/Importer.php');
39 require_once('modules/Calls/Call.php');
40 /**
41  * Bug #46411
42  * Importing Calls will not populate Leads or Contacts Subpanel
43  *
44  * @author adetskin@sugarcrm.com
45  * @ticket 46411
46  */
47 class Bug46411Test extends Sugar_PHPUnit_Framework_TestCase
48 {
49     /**
50      * Importing Calls will not populate Leads or Contacts Subpanel
51      *
52      * @group 46411
53      */
54     public function setUp()
55     {
56         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
57         
58         $this->importSource = new stdClass();
59         $this->importSource->columncount = 2;
60         $this->importSource->colnum_0 = 'date_entered';
61         $this->importSource->colnum_1 = 'last_name';
62         $this->importSource->import_module = 'Calls';
63         $this->importSource->importlocale_charset = 'UTF-8';
64         $this->importSource->importlocale_dateformat = 'm/d/Y';
65         $this->importSource->importlocale_timeformat = 'h:i a';
66         $this->importSource->importlocale_timezone = 'GMT';
67         $this->importSource->importlocale_default_currency_significant_digits = '2';
68         $this->importSource->importlocale_currency = '-99';
69         $this->importSource->importlocale_dec_sep = '.';
70         $this->importSource->importlocale_currency = '-99';
71         $this->importSource->importlocale_default_locale_name_format = 's f l';
72         $this->importSource->importlocale_num_grp_sep = ',';
73     }
74
75     public function tearDown()
76     {
77         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
78         unset($GLOBALS['current_user']);
79         SugarTestLeadUtilities::removeAllCreatedLeads();
80     }
81
82     public function testMissingFields()
83     {
84         $bean = $this->getMock('Call',array(
85             'get_importable_fields',
86             'populateDefaultValues',
87             'beforeImportSave',
88             'save',
89             'afterImportSave',
90             'writeRowToLastImport'));
91
92         $bean->expects($this->any())
93             ->method('get_importable_fields')
94             ->will($this->returnValue(array(
95             'account_id'                => 'accounts',
96             'opportunity_id'    => 'opportunities',
97             'contact_id'                => 'contacts',
98             'case_id'                   => 'cases',
99             'user_id'                   => 'users',
100             'assigned_user_id'  => 'users',
101             'note_id'                   => 'notes',
102             'lead_id'                   => 'leads',
103         )));
104
105         $bean->expects($this->any())
106             ->method('populateDefaultValues')
107             ->will($this->returnValue('foo'));
108
109         $bean->expects($this->any())
110             ->method('beforeImportSave')
111             ->will($this->returnValue('foo'));
112
113         $bean->expects($this->any())
114             ->method('save')
115             ->will($this->returnValue('foo'));
116
117         $bean->expects($this->any())
118             ->method('afterImportSave')
119             ->will($this->returnValue('foo'));
120
121         $bean->expects($this->any())
122             ->method('writeRowToLastImport')
123             ->will($this->returnValue('foo'));
124
125         $bean->date_modified = 'true';
126         $bean->fetched_row = array('date_modified' => '');
127         $bean->object_name = '';
128
129         $lead = SugarTestLeadUtilities::createLead();
130         $a = new bug46411_Importer_mock($this->importSource, $bean);
131 //        $b = new Call();
132
133         $bean->parent_type = 'leads';
134         $bean->parent_id = $lead->id;
135 //        $bean->relationship_fields = $b->relationship_fields;
136
137         $a->saveImportBean($bean, false);
138         $this->assertEquals($bean->parent_id, $bean->lead_id);
139     }
140 }
141
142 class bug46411_Importer_mock extends Importer
143 {
144     public function saveImportBean($focus, $newRecord)
145     {
146         return parent::saveImportBean($focus, $newRecord);
147     }
148
149 }
150
151