2 require_once 'modules/Import/Forms.php';
3 require_once 'include/Sugar_Smarty.php';
5 class ImportFormsTest extends Sugar_PHPUnit_Framework_TestCase
7 public function setUp()
10 require('include/modules.php');
11 $GLOBALS['beanList'] = $beanList;
12 $GLOBALS['beanFiles'] = $beanFiles;
13 $mod_strings = array();
14 require('modules/Import/language/en_us.lang.php');
15 $GLOBALS['mod_strings'] = $mod_strings;
16 $_SESSION['developerMode'] = true;
17 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
20 public function tearDown()
22 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
23 unset($GLOBALS['current_user']);
24 unset($_SESSION['developerMode']);
25 unset($GLOBALS['beanFiles']);
26 unset($GLOBALS['beanList']);
27 unset($GLOBALS['mod_strings']);
30 public function testLoadImportBean()
32 $oldisadmin = $GLOBALS['current_user']->is_admin;
33 $GLOBALS['current_user']->is_admin = '1';
35 $focus = loadImportBean('Accounts');
37 $this->assertEquals($focus->object_name, 'Account');
39 $GLOBALS['current_user']->is_admin = $oldisadmin;
42 public function testLoadImportBeanNotImportable()
44 $this->assertFalse(loadImportBean('vCals'));
47 public function testLoadImportBeanUserNotAdmin()
49 $this->assertFalse(loadImportBean('Users'));
52 public function testShowImportError()
55 showImportError('Error Message','ErrorModule','ErrorAction');
56 $output = ob_get_clean();
58 $this->assertRegExp('/<p class="error">Error Message<\/p>/',$output);
59 $this->assertRegExp('/<input type="hidden" name="import_module" value="ErrorModule">/',$output);
60 $this->assertRegExp('/<input type="hidden" name="action" value="ErrorAction">/',$output);
63 public function testHandleImportErrors()
65 $old_error_reporting = error_reporting(E_ALL);
68 array(E_USER_WARNING,'sample E_USER_WARNING','test12.php',4),
69 array(E_WARNING,'sample E_WARNING','test4.php',2232),
70 array(E_USER_NOTICE,'sample E_USER_NOTICE','test8.php',932),
71 array(E_NOTICE,'sample E_NOTICE','12test.php',39),
72 array(E_STRICT,'sample E_STRICT','t12est.php',42),
73 array(12121212121,'sample unknown error','te43st.php',334),
76 foreach ( $errors as $error ) {
77 list($errno, $errstr, $errfile, $errline) = $error;
80 handleImportErrors($errno, $errstr, $errfile, $errline);
81 $output = ob_get_clean();
82 $output = trim($output);
87 //$this->assertEquals("WARNING: [$errno] $errstr on line $errline in file $errfile<br />",$output);
91 //$this->assertEquals("NOTICE: [$errno] $errstr on line $errline in file $errfile<br />",$output);
94 //$this->assertEquals('',$output);
98 "Unknown error type: [$errno] $errstr on line $errline in file $errfile<br />",$output);
103 error_reporting($old_error_reporting);
106 public function testGetControlIdField()
108 $html = getControl('Contacts','assigned_user_id');
110 $this->assertRegExp('/name=\'assigned_user_id\'/',$html);
111 $this->assertRegExp('/id=\'assigned_user_id\'/',$html);
112 $this->assertRegExp('/type=\'text\'/',$html);
115 public function testGetControlEmail()
117 $html = getControl('Contacts','email1');
119 $this->assertRegExp('/name=\'email1\'/',$html);
120 $this->assertRegExp('/id=\'email1\'/',$html);
121 $this->assertRegExp('/type=\'text\'/',$html);
124 public function testGetControlCurrencyList()
128 $html = getControl('Opportunities','currency_id');
130 $focus = loadBean('Opportunities');
132 require_once('modules/Opportunities/Opportunity.php');
134 $string = str_ireplace('</select>','<option value="">'.$app_strings['LBL_NONE'].'</option></select>',getCurrencyDropDown($focus, 'currency_id', '', 'EditView'));
135 $this->assertContains($string,$html,"Failed to find string '$string' in '$html'");
137 $string = "<script>function CurrencyConvertAll() { return; }</script>";
138 $this->assertContains($string,$html,"Failed to find string '$string' in '$html'");
141 public function testGetControlVardef()
143 VardefManager::loadVardef(
146 $vardef = $GLOBALS['dictionary']['Contact']['fields']['assigned_user_id'];
148 $html = getControl('Contacts','assigned_user_id',$vardef);
150 $this->assertRegExp('/name=\'assigned_user_id\'/',$html);
151 $this->assertRegExp('/id=\'assigned_user_id\'/',$html);
152 $this->assertRegExp('/type=\'text\'/',$html);
155 public function testGetControlValue()
157 $html = getControl('Contacts','email1',null,'poo');
159 $this->assertRegExp('/name=\'email1\'/',$html);
160 $this->assertRegExp('/id=\'email1\'/',$html);
161 $this->assertRegExp('/type=\'text\'/',$html);
162 $this->assertRegExp('/value=\'poo\'/',$html);
168 public function testGetControlDatetimecombo()
170 $html = getControl('Calls','date_start');
173 $string = '", "' . $timedate->get_user_time_format() . '", "';
175 $this->assertContains($string, $html);