]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/database/Bug43466Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / include / database / Bug43466Test.php
1 <?php
2
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 require_once 'include/database/DBManagerFactory.php';
40
41 class Bug43466 extends Sugar_PHPUnit_Framework_TestCase
42 {
43     private $_db;
44
45
46 /*
47         public static function setUpBeforeClass()
48         {
49         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
50
51         }
52
53         public static function tearDownAfterClass()
54         {
55             SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
56         unset($GLOBALS['current_user']);
57         }
58 */
59         public function setUp()
60     {
61             $this->_db = DBManagerFactory::getInstance();
62         $this->useOutputBuffering = false;
63         }
64
65         public function tearDown()
66         {
67             SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
68         unset($GLOBALS['current_user']);
69         SugarTestContactUtilities::removeAllCreatedContacts();
70         }
71
72     /*
73      * @group bug43466
74      */
75
76         public function providerRepairTableParams()
77         {
78                 $fieldDefs = array (
79                         'name' =>
80                                 array (
81                                         'name' => 'name',
82                                         'vname' => 'LBL_SUBJECT',
83                                         'dbType' => 'varchar',
84                                         'type' => 'name',
85                                         'len' => '50',
86                                         'comment' => 'Brief description of the call',
87                                         'unified_search' => true,
88                                         'required'=>true,
89                                         'importable' => 'required',
90                                   ),
91
92                         'duration_hours' =>
93                                 array (
94                                         'name' => 'duration_hours',
95                                         'vname' => 'LBL_DURATION_HOURS',
96                                         'type' => 'int',
97                                         'len' => '2',
98                                         'comment' => 'Call duration, hours portion',
99                                         'required' => true,
100                                 ),
101                         'duration_minutes' =>
102                                 array (
103                                         'name' => 'duration_minutes',
104                                         'vname' => 'LBL_DURATION_MINUTES',
105                                         'type' => 'int',
106                                         'function' => array('name'=>'getDurationMinutesOptions', 'returns'=>'html', 'include'=>'modules/Calls/CallHelper.php'),
107                                         'len' => '2',
108                                         'group'=>'duration_hours',
109                                         'importable' => 'required',
110                                         'comment' => 'Call duration, minutes portion'
111                                 ),
112
113                         'date_start' =>
114                                 array (
115                                         'name' => 'date_start',
116                                         'vname' => 'LBL_DATE',
117                                         'type' => 'datetimecombo',
118                                         'dbType' => 'datetime',
119                                         'comment' => 'Date in which call is schedule to (or did) start',
120                                         'importable' => 'required',
121                                         'required' => true,
122                                         'enable_range_search' => true,
123                                         'options' => 'date_range_search_dom',
124                                   ),
125
126                         'date_end' =>
127                                 array (
128                                         'name' => 'date_end',
129                                         'vname' => 'LBL_DATE_END',
130                                         'type' => 'datetime',
131                                         'massupdate'=>false,
132                                         'comment' => 'Date is which call is scheduled to (or did) end',
133                                         'enable_range_search' => true,
134                                         'options' => 'date_range_search_dom',
135                                 ),
136
137                         'parent_type'=>
138                                 array(
139                                         'name'=>'parent_type',
140                                         'vname'=>'LBL_PARENT_TYPE',
141                                         'type' => 'parent_type',
142                                         'dbType'=>'varchar',
143                                         'required'=>false,
144                                         'group'=>'parent_name',
145                                         'options'=> 'parent_type_display',
146                                         'len'=>255,
147                                           'comment' => 'The Sugar object to which the call is related'
148                                 ),
149
150                         'parent_name'=>
151                                 array(
152                                         'name'=> 'parent_name',
153                                         'parent_type'=>'record_type_display' ,
154                                         'type_name'=>'parent_type',
155                                         'id_name'=>'parent_id',
156                                         'vname'=>'LBL_LIST_RELATED_TO',
157                                         'type'=>'parent',
158                                         'group'=>'parent_name',
159                                         'source'=>'non-db',
160                                         'options'=> 'parent_type_display',
161                                 ),
162                         'status' =>
163                                 array (
164                                         'name' => 'status',
165                                         'vname' => 'LBL_STATUS',
166                                         'type' => 'enum',
167                                         'len' => 100,
168                                         'options' => 'call_status_dom',
169                                         'comment' => 'The status of the call (Held, Not Held, etc.)',
170                                         'required' => true,
171                                         'importable' => 'required',
172                                         'default' => 'Planned',
173                                 ),
174                         'direction' =>
175                                 array (
176                                         'name' => 'direction',
177                                         'vname' => 'LBL_DIRECTION',
178                                         'type' => 'enum',
179                                         'len' => 100,
180                                         'options' => 'call_direction_dom',
181                                         'comment' => 'Indicates whether call is inbound or outbound'
182                                 ),
183                         'parent_id'=>
184                                 array(
185                                         'name'=>'parent_id',
186                                         'vname'=>'LBL_LIST_RELATED_TO_ID',
187                                         'type'=>'id',
188                                         'group'=>'parent_name',
189                                                 'reportable'=>false,
190                                           'comment' => 'The ID of the parent Sugar object identified by parent_type'
191                                 ),
192                         'reminder_checked'=>
193                                 array(
194                                         'name' => 'reminder_checked',
195                                         'vname' => 'LBL_REMINDER',
196                                         'type' => 'bool',
197                                         'source' => 'non-db',
198                                         'comment' => 'checkbox indicating whether or not the reminder value is set (Meta-data only)',
199                                         'massupdate'=>false,
200                                 ),
201                         'reminder_time'=>
202                                 array (
203                                         'name' => 'reminder_time',
204                                         'vname' => 'LBL_REMINDER_TIME',
205                                         'type' => 'int',
206                                         'function' => array('name'=>'getReminderTime', 'returns'=>'html', 'include'=>'modules/Calls/CallHelper.php', 'onListView'=>true),
207                                         'required' => false,
208                                         'reportable' => false,
209                                         'default' => -1,
210                                         'len' => '4',
211                                         'comment' => 'Specifies when a reminder alert should be issued; -1 means no alert; otherwise the number of seconds prior to the start'
212                                 ),
213
214                         'outlook_id' =>
215                                 array (
216                                         'name' => 'outlook_id',
217                                         'vname' => 'LBL_OUTLOOK_ID',
218                                         'type' => 'varchar',
219                                         'len' => '255',
220                                         'reportable' => false,
221                                         'comment' => 'When the Sugar Plug-in for Microsoft Outlook syncs an Outlook appointment, this is the Outlook appointment item ID'
222                                 ),
223                         'accept_status' =>
224                                 array (
225                                         'name' => 'accept_status',
226                                         'vname' => 'LBL_SUBJECT',
227                                         'dbType' => 'varchar',
228                                         'type' => 'varchar',
229                                         'len' => '20',
230                                         'source'=>'non-db',
231                                  ),
232
233                         'set_accept_links' =>
234                                 array (
235                                         'name' => 'accept_status',
236                                         'vname' => 'LBL_SUBJECT',
237                                         'dbType' => 'varchar',
238                                         'type' => 'varchar',
239                                         'len' => '20',
240                                         'source'=>'non-db',
241                                 ),
242                         'contact_name' =>
243                                 array (
244                                         'name' => 'contact_name',
245                                         'rname' => 'last_name',
246                                         'db_concat_fields'=> array(0=>'first_name', 1=>'last_name'),
247                                         'id_name' => 'contact_id',
248                                         'massupdate' => false,
249                                         'vname' => 'LBL_CONTACT_NAME',
250                                         'type' => 'relate',
251                                         'link'=>'contacts',
252                                         'table' => 'contacts',
253                                         'isnull' => 'true',
254                                         'module' => 'Contacts',
255                                         'join_name' => 'contacts',
256                                         'dbType' => 'varchar',
257                                         'source'=>'non-db',
258                                         'len' => 36,
259                                         'importable' => 'false',
260                                         'studio' => array('required' => false, 'listview'=>true, 'visible' => false),
261                                 ),
262                         'account' =>
263                                 array (
264                                         'name' => 'account',
265                                         'type' => 'link',
266                                         'relationship' => 'account_calls',
267                                                 'link_type'=>'one',
268                                         'source'=>'non-db',
269                                                 'vname'=>'LBL_OLD_ACCOUNT_LINK',
270                                 ),
271                         'opportunity' =>
272                                 array (
273                                         'name' => 'opportunity',
274                                         'type' => 'link',
275                                         'relationship' => 'opportunity_calls',
276                                         'source'=>'non-db',
277                                                 'link_type'=>'one',
278                                                 'vname'=>'LBL_OPPORTUNITY',
279                                 ),
280                         'leads' =>
281                                  array (
282                                         'name' => 'leads',
283                                         'type' => 'link',
284                                         'relationship' => 'calls_leads',
285                                         'source'=>'non-db',
286                                                 'vname'=>'LBL_LEADS',
287                                 ),
288                         'case' =>
289                                 array (
290                                         'name' => 'case',
291                                         'type' => 'link',
292                                         'relationship' => 'case_calls',
293                                         'source'=>'non-db',
294                                                 'link_type'=>'one',
295                                                 'vname'=>'LBL_CASE',
296                                 ),
297                         'accounts' =>
298                                 array (
299                                         'name' => 'accounts',
300                                         'type' => 'link',
301                                         'relationship' => 'account_calls',
302                                         'module'=>'Accounts',
303                                         'bean_name'=>'Account',
304                                         'source'=>'non-db',
305                                         'vname'=>'LBL_ACCOUNT',
306                                 ),
307                         'contacts' =>
308                                 array (
309                                         'name' => 'contacts',
310                                         'type' => 'link',
311                                         'relationship' => 'calls_contacts',
312                                         'source'=>'non-db',
313                                                 'vname'=>'LBL_CONTACTS',
314                                 ),
315                         'users' =>
316                                 array (
317                                         'name' => 'users',
318                                         'type' => 'link',
319                                         'relationship' => 'calls_users',
320                                         'source'=>'non-db',
321                                                 'vname'=>'LBL_USERS',
322                                 ),
323                         'notes' =>
324                                 array (
325                                         'name' => 'notes',
326                                         'type' => 'link',
327                                         'relationship' => 'calls_notes',
328                                         'module'=>'Notes',
329                                         'bean_name'=>'Note',
330                                         'source'=>'non-db',
331                                                 'vname'=>'LBL_NOTES',
332                                 ),
333                         'created_by_link' =>
334                                 array (
335                                                 'name' => 'created_by_link',
336                                         'type' => 'link',
337                                         'relationship' => 'calls_created_by',
338                                         'vname' => 'LBL_CREATED_BY_USER',
339                                         'link_type' => 'one',
340                                         'module'=>'Users',
341                                         'bean_name'=>'User',
342                                         'source'=>'non-db',
343                                 ),
344                         'modified_user_link' =>
345                                 array (
346                                                 'name' => 'modified_user_link',
347                                         'type' => 'link',
348                                         'relationship' => 'calls_modified_user',
349                                         'vname' => 'LBL_MODIFIED_BY_USER',
350                                         'link_type' => 'one',
351                                         'module'=>'Users',
352                                         'bean_name'=>'User',
353                                         'source'=>'non-db',
354                                 ),
355                         'assigned_user_link' =>
356                                 array (
357                                         'name' => 'assigned_user_link',
358                                         'type' => 'link',
359                                         'relationship' => 'calls_assigned_user',
360                                         'vname' => 'LBL_ASSIGNED_TO_USER',
361                                         'link_type' => 'one',
362                                         'module'=>'Users',
363                                         'bean_name'=>'User',
364                                         'source'=>'non-db',
365                                 ),
366                         'contact_id' =>
367                                 array(
368                                         'name' => 'contact_id',
369                                         'type' => 'id',
370                                         'source' => 'non-db',
371                                         'importable' => false,
372                                 )
373                         );
374
375
376                 $returnArray = array (
377                         array(
378                                 "calls",
379                                 $fieldDefs,
380                                 array(
381                                         array(
382                                                 'name' => 'idx_call_name',
383                                                 'type' => 'index',
384                                                 'fields'=> array('name'),
385                                         ),
386                                         array(
387                                                 'name' => 'idx_status',
388                                                 'type' => 'index',
389                                                 'fields'=> array('status'),
390                                         ),
391                                         array(
392                                                 'name' => 'idx_CALLS_date_Start',
393                                                 'type' => 'index',
394                                                 'fields' => array('date_start'),
395                                         )
396                                 ),
397                                 true
398                         ),
399                         array(
400                                 "calls",
401                                 $fieldDefs,
402                                 array(
403                                         array(
404                                                 'name' => 'idx_call_name2',
405                                                 'type' => 'index',
406                                                 'fields'=> array('name'),
407                                         ),
408                                         array(
409                                                 'name' => 'idx_status',
410                                                 'type' => 'index',
411                                                 'fields'=> array('status'),
412                                         ),
413                                         array(
414                                                 'name' => 'idx_CALLS_date_Start',
415                                                 'type' => 'index',
416                                                 'fields' => array('date_start'),
417                                         )
418                                 ),
419                                 false
420                         ),
421                         array(
422                                 "calls",
423                                 $fieldDefs,
424                                 array(
425                                         array(
426                                                 'name' => 'iDX_cAll_NAMe',
427                                                 'type' => 'index',
428                                                 'fields'=> array('name'),
429                                         ),
430                                         array(
431                                                 'name' => 'idx_STAtus',
432                                                 'type' => 'index',
433                                                 'fields'=> array('status'),
434                                         ),
435                                         array(
436                                                 'name' => 'idx_CALLS_date_Start',
437                                                 'type' => 'index',
438                                                 'fields' => array('date_start'),
439                                         )
440                                 ),
441                                 true
442                         ),
443                         array(
444                                 "calls",
445                                 $fieldDefs,
446                                 array(
447                                         array(
448                                                 'name' => 'idx_call_name',
449                                                 'type' => 'index',
450                                                 'fields'=> array('name'),
451                                         ),
452                                         array(
453                                                 'name' => 'idx_status',
454                                                 'type' => 'index',
455                                                 'fields'=> array('status'),
456                                         ),
457                                         array(
458                                                 'name' => 'idx_calls_date_start2',
459                                                 'type' => 'index',
460                                                 'fields' => array('date_start'),
461                                         )
462                                 ),
463                                 false
464                         )
465
466                 );
467         return $returnArray;
468         }
469
470         static function isEmpty($result){
471                 if(trim($result) == ""){
472                         return true;
473                 }
474                 return false;
475         }
476
477         /**
478      * @dataProvider providerRepairTableParams
479      */
480
481
482     public function testRepairTableParams(
483             $tablename,
484         $fielddefs,
485         $indices,
486                 $expectedResult
487                 )
488     {
489
490                 if ( $expectedResult ) {
491             $this->assertTrue($this->isEmpty($this->_db->repairTableParams($tablename, $fielddefs, $indices, false)));
492         }
493         else {
494             $this->assertFalse($this->isEmpty($this->_db->repairTableParams($tablename, $fielddefs, $indices, false)));
495         }
496     }
497
498
499         public function providerCompareVardefs()
500     {
501         $returnArray = array(
502             array(
503                 array(
504                     'name' => 'foo',
505                     'type' => 'varchar',
506                     'len' => '255',
507                     ),
508                 array(
509                     'name' => 'foo',
510                     'type' => 'varchar',
511                     'len' => '255',
512                     ),
513                 true),
514             array(
515                 array(
516                     'name' => 'foo',
517                     'type' => 'varchar',
518                     'len' => '255',
519                     ),
520                 array(
521                     'name' => 'Foo',
522                     'type' => 'varchar',
523                     'len' => '255',
524                     ),
525                 true),
526             array(
527                 array(
528                     'name' => 'foo',
529                     'type' => 'varchar',
530                     'len' => '255',
531                     ),
532                 array(
533                     'name' => 'foo2',
534                     'type' => 'varchar',
535                     'len' => '255',
536                     ),
537                 false),
538             array(
539                 array(
540                     'name' => 'foo',
541                     'type' => 'varchar',
542                     'len' => '255',
543                     ),
544                 array(
545                     'name' => 'foo',
546                     'type' => 'varchar',
547                     'len' => '123',
548                     ),
549                 false),
550                         array(
551                 array(
552                     'name' => 'foo',
553                     'type' => 'varchar',
554                     'len' => '255',
555                     ),
556                 array(
557                     'name' => 'Foo',
558                     'type' => 'varchar',
559                     'len' => '123',
560                     ),
561                 false)
562            );
563
564         return $returnArray;
565     }
566
567     /**
568      * @dataProvider providerCompareVarDefs
569      */
570
571     public function testCompareVarDefs($fieldDef1,$fieldDef2,$expectedResult)
572     {
573         if($this->_db->dbType=="oci8" && $fieldDef1['len'] > $fieldDef2['len']) {
574             $this->markTestSkipped("Oracle does not allow shrinking columns");
575         }
576         if ( $expectedResult ) {
577             $this->assertTrue($this->_db->compareVarDefs($fieldDef1,$fieldDef2));
578         }
579         else {
580             $this->assertFalse($this->_db->compareVarDefs($fieldDef1,$fieldDef2));
581         }
582     }
583 }