]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Import/ImportFormsTest.php
Release 6.4.1
[Github/sugarcrm.git] / tests / modules / Import / ImportFormsTest.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 'modules/Import/Forms.php';
39 require_once 'include/Sugar_Smarty.php';
40 require_once 'modules/Import/controller.php';
41 require_once 'modules/Import/views/view.step3.php';
42 require_once 'modules/Import/views/view.step4.php';
43 require_once 'modules/Import/Importer.php';
44
45 class ImportFormsTest extends Sugar_PHPUnit_Framework_OutputTestCase
46 {
47     public function setUp()
48     {
49         $beanList = array();
50         require('include/modules.php');
51         $GLOBALS['beanList'] = $beanList;
52         $GLOBALS['beanFiles'] = $beanFiles;
53         $mod_strings = array();
54         require('modules/Import/language/en_us.lang.php');
55         $GLOBALS['mod_strings'] = $mod_strings;
56         $_SESSION['developerMode'] = true;
57         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
58     }
59
60     public function tearDown()
61     {
62         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
63         unset($GLOBALS['current_user']);
64         unset($_SESSION['developerMode']);
65         unset($GLOBALS['beanFiles']);
66         unset($GLOBALS['beanList']);
67         unset($GLOBALS['mod_strings']);
68
69         restore_error_handler();
70     }
71
72     public function testLoadImportBean()
73     {
74         $oldisadmin = $GLOBALS['current_user']->is_admin;
75         $GLOBALS['current_user']->is_admin = '1';
76
77         $controller = new ImportController;
78         $_REQUEST['import_module'] = 'Accounts';
79         $controller->loadBean();
80
81         $this->assertEquals($controller->bean->object_name, 'Account');
82
83         $GLOBALS['current_user']->is_admin = $oldisadmin;
84     }
85
86     public function testLoadImportBeanNotImportable()
87     {
88         $controller = new ImportController;
89         $_REQUEST['import_module'] = 'vCals';
90         $controller->loadBean();
91         
92         $this->assertFalse($controller->bean);
93     }
94
95     public function testLoadImportBeanUserNotAdmin()
96     {
97         $controller = new ImportController;
98         $_REQUEST['import_module'] = 'Users';
99         $controller->loadBean();
100         
101         $this->assertFalse($controller->bean);
102     }
103
104     public function errorSet()
105     {
106          return array(
107             array(E_USER_WARNING,'sample E_USER_WARNING','test12.php',4),
108             array(E_WARNING,'sample E_WARNING','test4.php',2232),
109             array(E_USER_NOTICE,'sample E_USER_NOTICE','test8.php',932),
110             array(E_NOTICE,'sample E_NOTICE','12test.php',39),
111             array(E_STRICT,'sample E_STRICT','t12est.php',42),
112             array(12121212121,'sample unknown error','te43st.php',334),
113             );
114     }
115
116     /**
117      * @dataProvider errorSet
118      */
119     public function testHandleImportErrors($errno, $errstr, $errfile, $errline)
120     {
121         $old_error_reporting = error_reporting(E_ALL);
122
123         Importer::handleImportErrors($errno, $errstr, $errfile, $errline);
124
125         switch ($errno) {
126             case E_USER_WARNING:
127             case E_WARNING:
128                 //$this->assertEquals("WARNING: [$errno] $errstr on line $errline in file $errfile<br />",$output);
129                 break;
130             case E_USER_NOTICE:
131             case E_NOTICE:
132                 //$this->assertEquals("NOTICE: [$errno] $errstr on line $errline in file $errfile<br />",$output);
133                 break;
134             case E_STRICT:    
135                 //$this->assertEquals('',$output);
136                 break;
137             default:
138                 $this->expectOutputString("Unknown error type: [$errno] $errstr on line $errline in file $errfile<br />\n");
139                 break;
140             }
141         error_reporting($old_error_reporting);
142     }
143
144     public function testGetControlIdField()
145     {
146         $html = getControl('Contacts','assigned_user_id');
147
148         $this->assertRegExp('/name=\'assigned_user_id\'/',$html);
149         $this->assertRegExp('/id=\'assigned_user_id\'/',$html);
150         $this->assertRegExp('/type=\'text\'/',$html);
151     }
152
153     public function testGetControlEmail()
154     {
155         $html = getControl('Contacts','email1');
156
157         $this->assertRegExp('/name=\'email1\'/',$html);
158         $this->assertRegExp('/id=\'email1\'/',$html);
159         $this->assertRegExp('/type=\'text\'/',$html);
160     }
161
162     public function testGetControlCurrencyList()
163     {
164         global $app_strings;
165
166         $html = getControl('Opportunities','currency_id');
167
168         $focus = loadBean('Opportunities');
169
170         require_once('modules/Opportunities/Opportunity.php');
171
172         $string = str_ireplace('</select>','<option value="">'.$app_strings['LBL_NONE'].'</option></select>',getCurrencyDropDown($focus, 'currency_id', '', 'EditView'));
173         $this->assertContains($string,$html,"Failed to find string '$string' in '$html'");
174
175         $string = "<script>function CurrencyConvertAll() { return; }</script>";
176         $this->assertContains($string,$html,"Failed to find string '$string' in '$html'");
177     }
178
179     public function testGetControlVardef()
180     {
181         VardefManager::loadVardef(
182                 'Contacts',
183                 'Contact');
184         $vardef = $GLOBALS['dictionary']['Contact']['fields']['assigned_user_id'];
185
186         $html = getControl('Contacts','assigned_user_id',$vardef);
187
188         $this->assertRegExp('/name=\'assigned_user_id\'/',$html);
189         $this->assertRegExp('/id=\'assigned_user_id\'/',$html);
190         $this->assertRegExp('/type=\'text\'/',$html);
191     }
192
193     public function testGetControlValue()
194     {
195         $html = getControl('Contacts','email1',null,'poo');
196
197         $this->assertRegExp('/name=\'email1\'/',$html);
198         $this->assertRegExp('/id=\'email1\'/',$html);
199         $this->assertRegExp('/type=\'text\'/',$html);
200         $this->assertRegExp('/value=\'poo\'/',$html);
201     }
202
203     /**
204      * @group bug41447
205      */
206     public function testGetControlDatetimecombo()
207     {
208         $html = getControl('Calls','date_start');
209
210         global $timedate;
211         $string = '", "' . $timedate->get_user_time_format() . '", "';
212
213         $this->assertContains($string, $html);
214     }
215 }