]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Import/ImportFormsTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Import / ImportFormsTest.php
1 <?php
2 require_once 'modules/Import/Forms.php';
3 require_once 'include/Sugar_Smarty.php';
4
5 class ImportFormsTest extends Sugar_PHPUnit_Framework_TestCase
6 {
7     public function setUp()
8     {
9         $beanList = array();
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();
18     }
19     
20     public function tearDown()
21     {
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']);
28     }
29     
30     public function testLoadImportBean()
31     {
32         $oldisadmin = $GLOBALS['current_user']->is_admin;
33         $GLOBALS['current_user']->is_admin = '1';
34         
35         $focus = loadImportBean('Accounts');
36         
37         $this->assertEquals($focus->object_name, 'Account');
38         
39         $GLOBALS['current_user']->is_admin = $oldisadmin;
40     }
41     
42     public function testLoadImportBeanNotImportable()
43     {
44         $this->assertFalse(loadImportBean('vCals'));
45     }
46     
47     public function testLoadImportBeanUserNotAdmin()
48     {
49         $this->assertFalse(loadImportBean('Users'));
50     }
51     
52     public function testShowImportError()
53     {
54         ob_start();
55         showImportError('Error Message','ErrorModule','ErrorAction');
56         $output = ob_get_clean();
57         
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);
61     }
62     
63     public function testHandleImportErrors()
64     {
65         $old_error_reporting = error_reporting(E_ALL);
66         
67         $errors = array(
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),
74             );
75         
76         foreach ( $errors as $error ) {
77             list($errno, $errstr, $errfile, $errline) = $error;
78             
79             ob_start();
80             handleImportErrors($errno, $errstr, $errfile, $errline);
81             $output = ob_get_clean();
82             $output = trim($output);
83             
84             switch ($errno) {
85             case E_USER_WARNING:
86             case E_WARNING:
87                 //$this->assertEquals("WARNING: [$errno] $errstr on line $errline in file $errfile<br />",$output);
88                 break;
89             case E_USER_NOTICE:
90             case E_NOTICE:
91                 //$this->assertEquals("NOTICE: [$errno] $errstr on line $errline in file $errfile<br />",$output);
92                 break;
93             case E_STRICT:    
94                 //$this->assertEquals('',$output);
95                 break;
96             default:
97                 $this->assertEquals(
98                     "Unknown error type: [$errno] $errstr on line $errline in file $errfile<br />",$output);
99                 break;
100             }
101         }
102         
103         error_reporting($old_error_reporting);
104     }
105     
106     public function testGetControlIdField()
107     {
108         $html = getControl('Contacts','assigned_user_id');
109         
110         $this->assertRegExp('/name=\'assigned_user_id\'/',$html);
111         $this->assertRegExp('/id=\'assigned_user_id\'/',$html);
112         $this->assertRegExp('/type=\'text\'/',$html);
113     }
114     
115     public function testGetControlEmail()
116     {
117         $html = getControl('Contacts','email1');
118         
119         $this->assertRegExp('/name=\'email1\'/',$html);
120         $this->assertRegExp('/id=\'email1\'/',$html);
121         $this->assertRegExp('/type=\'text\'/',$html);
122     }
123     
124     public function testGetControlCurrencyList()
125     {
126         global $app_strings;
127         
128         $html = getControl('Opportunities','currency_id');
129         
130         $focus = loadBean('Opportunities');
131         
132         require_once('modules/Opportunities/Opportunity.php');
133         
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'");
136         
137         $string = "<script>function CurrencyConvertAll() { return; }</script>";
138         $this->assertContains($string,$html,"Failed to find string '$string' in '$html'");
139     }
140     
141     public function testGetControlVardef()
142     {
143         VardefManager::loadVardef(
144                 'Contacts', 
145                 'Contact');
146         $vardef = $GLOBALS['dictionary']['Contact']['fields']['assigned_user_id'];
147         
148         $html = getControl('Contacts','assigned_user_id',$vardef);
149         
150         $this->assertRegExp('/name=\'assigned_user_id\'/',$html);
151         $this->assertRegExp('/id=\'assigned_user_id\'/',$html);
152         $this->assertRegExp('/type=\'text\'/',$html);
153     }
154     
155     public function testGetControlValue()
156     {
157         $html = getControl('Contacts','email1',null,'poo');
158         
159         $this->assertRegExp('/name=\'email1\'/',$html);
160         $this->assertRegExp('/id=\'email1\'/',$html);
161         $this->assertRegExp('/type=\'text\'/',$html);
162         $this->assertRegExp('/value=\'poo\'/',$html);
163     }
164
165     /**
166      * @group bug41447
167      */
168     public function testGetControlDatetimecombo()
169     {
170         $html = getControl('Calls','date_start');
171
172         global $timedate;
173         $string = '", "' . $timedate->get_user_time_format() . '", "';
174
175         $this->assertContains($string, $html);
176     }
177 }