2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
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';
44 class ImportFormsTest extends Sugar_PHPUnit_Framework_OutputTestCase
46 public function setUp()
49 require('include/modules.php');
50 $GLOBALS['beanList'] = $beanList;
51 $GLOBALS['beanFiles'] = $beanFiles;
52 $mod_strings = array();
53 require('modules/Import/language/en_us.lang.php');
54 $GLOBALS['mod_strings'] = $mod_strings;
55 $_SESSION['developerMode'] = true;
56 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
59 public function tearDown()
61 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
62 unset($GLOBALS['current_user']);
63 unset($_SESSION['developerMode']);
64 unset($GLOBALS['beanFiles']);
65 unset($GLOBALS['beanList']);
66 unset($GLOBALS['mod_strings']);
69 public function testLoadImportBean()
71 $oldisadmin = $GLOBALS['current_user']->is_admin;
72 $GLOBALS['current_user']->is_admin = '1';
74 $controller = new ImportController;
75 $_REQUEST['import_module'] = 'Accounts';
76 $controller->loadBean();
78 $this->assertEquals($controller->bean->object_name, 'Account');
80 $GLOBALS['current_user']->is_admin = $oldisadmin;
83 public function testLoadImportBeanNotImportable()
85 $controller = new ImportController;
86 $_REQUEST['import_module'] = 'vCals';
87 $controller->loadBean();
89 $this->assertFalse($controller->bean);
92 public function testLoadImportBeanUserNotAdmin()
94 $controller = new ImportController;
95 $_REQUEST['import_module'] = 'Users';
96 $controller->loadBean();
98 $this->assertFalse($controller->bean);
101 public function errorSet()
104 array(E_USER_WARNING,'sample E_USER_WARNING','test12.php',4),
105 array(E_WARNING,'sample E_WARNING','test4.php',2232),
106 array(E_USER_NOTICE,'sample E_USER_NOTICE','test8.php',932),
107 array(E_NOTICE,'sample E_NOTICE','12test.php',39),
108 array(E_STRICT,'sample E_STRICT','t12est.php',42),
109 array(12121212121,'sample unknown error','te43st.php',334),
114 * @dataProvider errorSet
116 public function testHandleImportErrors($errno, $errstr, $errfile, $errline)
118 $old_error_reporting = error_reporting(E_ALL);
120 ImportViewStep4::handleImportErrors($errno, $errstr, $errfile, $errline);
125 //$this->assertEquals("WARNING: [$errno] $errstr on line $errline in file $errfile<br />",$output);
129 //$this->assertEquals("NOTICE: [$errno] $errstr on line $errline in file $errfile<br />",$output);
132 //$this->assertEquals('',$output);
135 $this->expectOutputString("Unknown error type: [$errno] $errstr on line $errline in file $errfile<br />\n");
138 error_reporting($old_error_reporting);
141 public function testGetControlIdField()
143 $html = getControl('Contacts','assigned_user_id');
145 $this->assertRegExp('/name=\'assigned_user_id\'/',$html);
146 $this->assertRegExp('/id=\'assigned_user_id\'/',$html);
147 $this->assertRegExp('/type=\'text\'/',$html);
150 public function testGetControlEmail()
152 $html = getControl('Contacts','email1');
154 $this->assertRegExp('/name=\'email1\'/',$html);
155 $this->assertRegExp('/id=\'email1\'/',$html);
156 $this->assertRegExp('/type=\'text\'/',$html);
159 public function testGetControlCurrencyList()
163 $html = getControl('Opportunities','currency_id');
165 $focus = loadBean('Opportunities');
167 require_once('modules/Opportunities/Opportunity.php');
169 $string = str_ireplace('</select>','<option value="">'.$app_strings['LBL_NONE'].'</option></select>',getCurrencyDropDown($focus, 'currency_id', '', 'EditView'));
170 $this->assertContains($string,$html,"Failed to find string '$string' in '$html'");
172 $string = "<script>function CurrencyConvertAll() { return; }</script>";
173 $this->assertContains($string,$html,"Failed to find string '$string' in '$html'");
176 public function testGetControlVardef()
178 VardefManager::loadVardef(
181 $vardef = $GLOBALS['dictionary']['Contact']['fields']['assigned_user_id'];
183 $html = getControl('Contacts','assigned_user_id',$vardef);
185 $this->assertRegExp('/name=\'assigned_user_id\'/',$html);
186 $this->assertRegExp('/id=\'assigned_user_id\'/',$html);
187 $this->assertRegExp('/type=\'text\'/',$html);
190 public function testGetControlValue()
192 $html = getControl('Contacts','email1',null,'poo');
194 $this->assertRegExp('/name=\'email1\'/',$html);
195 $this->assertRegExp('/id=\'email1\'/',$html);
196 $this->assertRegExp('/type=\'text\'/',$html);
197 $this->assertRegExp('/value=\'poo\'/',$html);
203 public function testGetControlDatetimecombo()
205 $html = getControl('Calls','date_start');
208 $string = '", "' . $timedate->get_user_time_format() . '", "';
210 $this->assertContains($string, $html);