]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/database/Bug43466Test.php
Release 6.5.10
[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-2013 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' => 'datetimecombo',
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' => 'enum',
206                     'dbType' => 'int',
207                     'options' => 'reminder_time_options',
208                     'reportable' => false,
209                     'massupdate' => false,
210                     'default'=> -1,
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             'email_reminder_checked' => array(
214                     'name' => 'email_reminder_checked',
215                     'vname' => 'LBL_EMAIL_REMINDER',
216                     'type' => 'bool',
217                     'source' => 'non-db',
218                     'comment' => 'checkbox indicating whether or not the email reminder value is set (Meta-data only)',
219                     'massupdate' => false,
220                 ),
221             'email_reminder_time' =>
222             array (
223                     'name' => 'email_reminder_time',
224                     'vname' => 'LBL_EMAIL_REMINDER_TIME',
225                     'type' => 'enum',
226                     'dbType' => 'int',
227                     'options' => 'reminder_time_options',
228                     'reportable' => false,
229                     'massupdate' => false,
230                     'default'=> -1,
231                     'comment' => 'Specifies when a email reminder alert should be issued; -1 means no alert; otherwise the number of seconds prior to the start'
232                 ),
233             'email_reminder_sent' => array(
234                     'name' => 'email_reminder_sent',
235                     'vname' => 'LBL_EMAIL_REMINDER_SENT',
236                     'default' => 0,
237                     'type' => 'bool',
238                     'comment' => 'Whether email reminder is already sent',
239                     'studio' => false,
240                     'massupdate'=> false,
241                 ),
242
243                         'outlook_id' =>
244                                 array (
245                                         'name' => 'outlook_id',
246                                         'vname' => 'LBL_OUTLOOK_ID',
247                                         'type' => 'varchar',
248                                         'len' => '255',
249                                         'reportable' => false,
250                                         'comment' => 'When the Sugar Plug-in for Microsoft Outlook syncs an Outlook appointment, this is the Outlook appointment item ID'
251                                 ),
252                         'accept_status' =>
253                                 array (
254                                         'name' => 'accept_status',
255                                         'vname' => 'LBL_SUBJECT',
256                                         'dbType' => 'varchar',
257                                         'type' => 'varchar',
258                                         'len' => '20',
259                                         'source'=>'non-db',
260                                  ),
261
262                         'set_accept_links' =>
263                                 array (
264                                         'name' => 'accept_status',
265                                         'vname' => 'LBL_SUBJECT',
266                                         'dbType' => 'varchar',
267                                         'type' => 'varchar',
268                                         'len' => '20',
269                                         'source'=>'non-db',
270                                 ),
271                         'contact_name' =>
272                                 array (
273                                         'name' => 'contact_name',
274                                         'rname' => 'last_name',
275                                         'db_concat_fields'=> array(0=>'first_name', 1=>'last_name'),
276                                         'id_name' => 'contact_id',
277                                         'massupdate' => false,
278                                         'vname' => 'LBL_CONTACT_NAME',
279                                         'type' => 'relate',
280                                         'link'=>'contacts',
281                                         'table' => 'contacts',
282                                         'isnull' => 'true',
283                                         'module' => 'Contacts',
284                                         'join_name' => 'contacts',
285                                         'dbType' => 'varchar',
286                                         'source'=>'non-db',
287                                         'len' => 36,
288                                         'importable' => 'false',
289                                         'studio' => array('required' => false, 'listview'=>true, 'visible' => false),
290                                 ),
291                         'account' =>
292                                 array (
293                                         'name' => 'account',
294                                         'type' => 'link',
295                                         'relationship' => 'account_calls',
296                                                 'link_type'=>'one',
297                                         'source'=>'non-db',
298                                                 'vname'=>'LBL_OLD_ACCOUNT_LINK',
299                                 ),
300                         'opportunity' =>
301                                 array (
302                                         'name' => 'opportunity',
303                                         'type' => 'link',
304                                         'relationship' => 'opportunity_calls',
305                                         'source'=>'non-db',
306                                                 'link_type'=>'one',
307                                                 'vname'=>'LBL_OPPORTUNITY',
308                                 ),
309                         'leads' =>
310                                  array (
311                                         'name' => 'leads',
312                                         'type' => 'link',
313                                         'relationship' => 'calls_leads',
314                                         'source'=>'non-db',
315                                                 'vname'=>'LBL_LEADS',
316                                 ),
317                         'case' =>
318                                 array (
319                                         'name' => 'case',
320                                         'type' => 'link',
321                                         'relationship' => 'case_calls',
322                                         'source'=>'non-db',
323                                                 'link_type'=>'one',
324                                                 'vname'=>'LBL_CASE',
325                                 ),
326                         'accounts' =>
327                                 array (
328                                         'name' => 'accounts',
329                                         'type' => 'link',
330                                         'relationship' => 'account_calls',
331                                         'module'=>'Accounts',
332                                         'bean_name'=>'Account',
333                                         'source'=>'non-db',
334                                         'vname'=>'LBL_ACCOUNT',
335                                 ),
336                         'contacts' =>
337                                 array (
338                                         'name' => 'contacts',
339                                         'type' => 'link',
340                                         'relationship' => 'calls_contacts',
341                                         'source'=>'non-db',
342                                                 'vname'=>'LBL_CONTACTS',
343                                 ),
344                         'users' =>
345                                 array (
346                                         'name' => 'users',
347                                         'type' => 'link',
348                                         'relationship' => 'calls_users',
349                                         'source'=>'non-db',
350                                                 'vname'=>'LBL_USERS',
351                                 ),
352                         'notes' =>
353                                 array (
354                                         'name' => 'notes',
355                                         'type' => 'link',
356                                         'relationship' => 'calls_notes',
357                                         'module'=>'Notes',
358                                         'bean_name'=>'Note',
359                                         'source'=>'non-db',
360                                                 'vname'=>'LBL_NOTES',
361                                 ),
362                         'created_by_link' =>
363                                 array (
364                                                 'name' => 'created_by_link',
365                                         'type' => 'link',
366                                         'relationship' => 'calls_created_by',
367                                         'vname' => 'LBL_CREATED_BY_USER',
368                                         'link_type' => 'one',
369                                         'module'=>'Users',
370                                         'bean_name'=>'User',
371                                         'source'=>'non-db',
372                                 ),
373                         'modified_user_link' =>
374                                 array (
375                                                 'name' => 'modified_user_link',
376                                         'type' => 'link',
377                                         'relationship' => 'calls_modified_user',
378                                         'vname' => 'LBL_MODIFIED_BY_USER',
379                                         'link_type' => 'one',
380                                         'module'=>'Users',
381                                         'bean_name'=>'User',
382                                         'source'=>'non-db',
383                                 ),
384                         'assigned_user_link' =>
385                                 array (
386                                         'name' => 'assigned_user_link',
387                                         'type' => 'link',
388                                         'relationship' => 'calls_assigned_user',
389                                         'vname' => 'LBL_ASSIGNED_TO_USER',
390                                         'link_type' => 'one',
391                                         'module'=>'Users',
392                                         'bean_name'=>'User',
393                                         'source'=>'non-db',
394                                 ),
395                         'contact_id' =>
396                                 array(
397                                         'name' => 'contact_id',
398                                         'type' => 'id',
399                                         'source' => 'non-db',
400                                         'importable' => false,
401                                 )
402                         );
403
404
405                 $returnArray = array (
406                         array(
407                                 "calls",
408                                 $fieldDefs,
409                                 array(
410                                         array(
411                                                 'name' => 'idx_call_name',
412                                                 'type' => 'index',
413                                                 'fields'=> array('name'),
414                                         ),
415                                         array(
416                                                 'name' => 'idx_status',
417                                                 'type' => 'index',
418                                                 'fields'=> array('status'),
419                                         ),
420                                         array(
421                                                 'name' => 'idx_CALLS_date_Start',
422                                                 'type' => 'index',
423                                                 'fields' => array('date_start'),
424                                         )
425                                 ),
426                                 true
427                         ),
428                         array(
429                                 "calls",
430                                 $fieldDefs,
431                                 array(
432                                         array(
433                                                 'name' => 'idx_call_name2',
434                                                 'type' => 'index',
435                                                 'fields'=> array('name'),
436                                         ),
437                                         array(
438                                                 'name' => 'idx_status',
439                                                 'type' => 'index',
440                                                 'fields'=> array('status'),
441                                         ),
442                                         array(
443                                                 'name' => 'idx_CALLS_date_Start',
444                                                 'type' => 'index',
445                                                 'fields' => array('date_start'),
446                                         )
447                                 ),
448                                 false
449                         ),
450                         array(
451                                 "calls",
452                                 $fieldDefs,
453                                 array(
454                                         array(
455                                                 'name' => 'iDX_cAll_NAMe',
456                                                 'type' => 'index',
457                                                 'fields'=> array('name'),
458                                         ),
459                                         array(
460                                                 'name' => 'idx_STAtus',
461                                                 'type' => 'index',
462                                                 'fields'=> array('status'),
463                                         ),
464                                         array(
465                                                 'name' => 'idx_CALLS_date_Start',
466                                                 'type' => 'index',
467                                                 'fields' => array('date_start'),
468                                         )
469                                 ),
470                                 true
471                         ),
472                         array(
473                                 "calls",
474                                 $fieldDefs,
475                                 array(
476                                         array(
477                                                 'name' => 'idx_call_name',
478                                                 'type' => 'index',
479                                                 'fields'=> array('name'),
480                                         ),
481                                         array(
482                                                 'name' => 'idx_status',
483                                                 'type' => 'index',
484                                                 'fields'=> array('status'),
485                                         ),
486                                         array(
487                                                 'name' => 'idx_calls_date_start2',
488                                                 'type' => 'index',
489                                                 'fields' => array('date_start'),
490                                         )
491                                 ),
492                                 false
493                         )
494
495                 );
496         return $returnArray;
497         }
498
499         static function isEmpty($result){
500                 if(trim($result) == ""){
501                         return true;
502                 }
503                 return false;
504         }
505
506         /**
507      * @dataProvider providerRepairTableParams
508      */
509
510
511     public function testRepairTableParams(
512             $tablename,
513         $fielddefs,
514         $indices,
515                 $expectedResult
516                 )
517     {
518
519                 if ( $expectedResult ) {
520             $this->assertTrue($this->isEmpty($this->_db->repairTableParams($tablename, $fielddefs, $indices, false)));
521         }
522         else {
523             $this->assertFalse($this->isEmpty($this->_db->repairTableParams($tablename, $fielddefs, $indices, false)));
524         }
525     }
526
527
528         public function providerCompareVardefs()
529     {
530         $returnArray = array(
531             array(
532                 array(
533                     'name' => 'foo',
534                     'type' => 'varchar',
535                     'len' => '255',
536                     ),
537                 array(
538                     'name' => 'foo',
539                     'type' => 'varchar',
540                     'len' => '255',
541                     ),
542                 true),
543             array(
544                 array(
545                     'name' => 'foo',
546                     'type' => 'varchar',
547                     'len' => '255',
548                     ),
549                 array(
550                     'name' => 'Foo',
551                     'type' => 'varchar',
552                     'len' => '255',
553                     ),
554                 true),
555             array(
556                 array(
557                     'name' => 'foo',
558                     'type' => 'varchar',
559                     'len' => '255',
560                     ),
561                 array(
562                     'name' => 'foo2',
563                     'type' => 'varchar',
564                     'len' => '255',
565                     ),
566                 false),
567             array(
568                 array(
569                     'name' => 'foo',
570                     'type' => 'varchar',
571                     'len' => '255',
572                     ),
573                 array(
574                     'name' => 'foo',
575                     'type' => 'varchar',
576                     'len' => '123',
577                     ),
578                 true),
579                         array(
580                 array(
581                     'name' => 'foo',
582                     'type' => 'varchar',
583                     'len' => '123',
584                     ),
585                 array(
586                     'name' => 'Foo',
587                     'type' => 'varchar',
588                     'len' => '255',
589                     ),
590                 false)
591            );
592
593         return $returnArray;
594     }
595
596     /**
597      * @dataProvider providerCompareVarDefs
598      */
599
600     public function testCompareVarDefs($fieldDef1,$fieldDef2,$expectedResult)
601     {
602         if ( $expectedResult ) {
603             $this->assertTrue($this->_db->compareVarDefs($fieldDef1,$fieldDef2));
604         }
605         else {
606             $this->assertFalse($this->_db->compareVarDefs($fieldDef1,$fieldDef2));
607         }
608     }
609 }