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/ImportFieldSanitize.php');
39 require_once('modules/Import/sources/ImportFile.php');
40 require_once('tests/SugarTestLangPackCreator.php');
42 class ImportFieldSanitizeTest extends Sugar_PHPUnit_Framework_TestCase
44 public function setUp()
46 $this->_ifs = new ImportFieldSanitize();
47 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
49 require('include/modules.php');
50 $GLOBALS['beanList'] = $beanList;
51 $GLOBALS['beanFiles'] = $beanFiles;
52 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
53 $GLOBALS['timedate'] = TimeDate::getInstance();
56 public function tearDown()
58 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
59 unset($GLOBALS['current_user']);
60 unset($GLOBALS['app_list_strings']);
61 unset($GLOBALS['beanList']);
62 unset($GLOBALS['beanFiles']);
63 $GLOBALS['timedate'] = TimeDate::getInstance();
66 public function testValidBool()
68 $this->assertEquals($this->_ifs->bool(0,array()),0);
69 $this->assertEquals($this->_ifs->bool('no',array()),0);
70 $this->assertEquals($this->_ifs->bool('off',array()),0);
71 $this->assertEquals($this->_ifs->bool('n',array()),0);
72 $this->assertEquals($this->_ifs->bool('yes',array()),1);
73 $this->assertEquals($this->_ifs->bool('y',array()),1);
74 $this->assertEquals($this->_ifs->bool('on',array()),1);
75 $this->assertEquals($this->_ifs->bool(1,array()),1);
78 public function testValidBoolVarchar()
80 $vardefs = array('dbType' => 'varchar');
82 $this->assertEquals($this->_ifs->bool(0,$vardefs),'off');
83 $this->assertEquals($this->_ifs->bool('no',$vardefs),'off');
84 $this->assertEquals($this->_ifs->bool('off',$vardefs),'off');
85 $this->assertEquals($this->_ifs->bool('n',$vardefs),'off');
86 $this->assertEquals($this->_ifs->bool('yes',$vardefs),'on');
87 $this->assertEquals($this->_ifs->bool('y',$vardefs),'on');
88 $this->assertEquals($this->_ifs->bool('on',$vardefs),'on');
89 $this->assertEquals($this->_ifs->bool(1,$vardefs),'on');
92 public function testInvalidBool()
94 $this->assertFalse($this->_ifs->bool('OK',array()));
95 $this->assertFalse($this->_ifs->bool('yep',array()));
98 public function testValidCurrency()
100 $this->_ifs->dec_sep = '.';
101 $this->_ifs->currency_symbol = '$';
103 $this->assertEquals($this->_ifs->currency('$100',array()),100);
106 public function testInvalidCurrency()
108 $this->_ifs->dec_sep = '.';
109 $this->_ifs->currency_symbol = '�';
111 $this->assertNotEquals($this->_ifs->currency('$123.23',array()),123.23);
114 public function testValidDatetimeSameFormat()
116 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
118 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
119 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
120 $this->_ifs->timezone = 'America/New_York';
121 $vardef = array('name' => 'some_date');
122 $date = date($this->_ifs->dateformat . ' ' .$this->_ifs->timeformat);
125 $GLOBALS['timedate']->get_db_date_time_format(),
127 $GLOBALS['timedate']->handle_offset(
128 $date, $GLOBALS['timedate']->get_date_time_format(), false,
129 $GLOBALS['current_user'], 'America/New_York')
134 $this->_ifs->datetime(
139 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
142 public function testValidDatetimeDifferentFormat()
144 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
146 $this->_ifs->dateformat = 'm/d/Y';
147 if ( $this->_ifs->dateformat == $GLOBALS['timedate']->get_date_format() )
148 $this->_ifs->dateformat = 'Y/m/d';
149 $this->_ifs->timeformat = 'h:ia';
150 if ( $this->_ifs->timeformat == $GLOBALS['timedate']->get_time_format() )
151 $this->_ifs->timeformat = 'h.ia';
152 $this->_ifs->timezone = 'America/New_York';
153 $vardef = array('name' => 'some_date');
154 $date = date($this->_ifs->dateformat . ' ' . $this->_ifs->timeformat);
157 $GLOBALS['timedate']->get_db_date_time_format(),
159 $GLOBALS['timedate']->handle_offset(
160 $date, $GLOBALS['timedate']->get_date_time_format(), false,
161 $GLOBALS['current_user'], 'America/New_York')
165 $this->_ifs->datetime(
170 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
173 public function testValidDatetimeDifferentTimezones()
175 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
177 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
178 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
179 $format = $GLOBALS['timedate']->get_date_time_format();
180 $this->_ifs->timezone = 'America/Denver';
181 $vardef = array('name' => 'some_date');
182 $date = date($format);
184 $GLOBALS['timedate']->get_db_date_time_format(),
185 strtotime('+2 hours',strtotime(
186 $GLOBALS['timedate']->handle_offset(
187 $date, $GLOBALS['timedate']->get_date_time_format(), false,
188 $GLOBALS['current_user'], 'America/New_York')
192 $this->_ifs->datetime(
197 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
200 public function testValidDatetimeDateEntered()
202 $_SESSION[$GLOBALS['current_user']->id.'_PREFERENCES']['global']['timezone'] = 'Atlantic/Cape_Verde';
204 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
205 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
206 $format = $GLOBALS['timedate']->get_date_time_format();
207 $this->_ifs->timezone = 'Atlantic/Cape_Verde';
208 $vardef = array('name' => 'date_entered');
209 $date = date($format);
211 $GLOBALS['timedate']->get_db_date_time_format(),
212 strtotime('+1 hours',strtotime($date)));
215 $this->_ifs->datetime(
220 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
223 public function testValidDatetimeDateOnly()
225 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
227 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
228 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
229 $format = $GLOBALS['timedate']->get_date_format();
230 $this->_ifs->timezone = 'America/New_York';
231 $vardef = array('name' => 'date_entered');
232 $date = date($format);
234 $GLOBALS['timedate']->get_db_date_time_format(),
238 (bool) $this->_ifs->datetime(
242 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
245 public function testInvalidDatetime()
247 $this->_ifs->dateformat = 'm.d.Y';
248 $this->_ifs->timeformat = 'h:ia';
249 $this->_ifs->timezone = 'America/New_York';
252 $this->_ifs->datetime(
254 array('name' => 'some_date')));
257 public function testInvalidDatetimeBadDayBadHour()
259 $this->_ifs->dateformat = 'm.d.Y';
260 $this->_ifs->timeformat = 'h:ia';
261 $this->_ifs->timezone = 'America/New_York';
264 $this->_ifs->datetime(
266 array('name' => 'some_date')));
269 public function testValidDateSameFormat()
271 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
272 $date = date($this->_ifs->dateformat);
273 $focus = new stdClass;
283 public function testValidDateDifferentFormat()
285 $this->_ifs->dateformat = 'm/d/Y';
286 if ( $this->_ifs->dateformat == $GLOBALS['timedate']->get_date_format() )
287 $this->_ifs->dateformat = 'Y/m/d';
288 $date = date($this->_ifs->dateformat );
290 $GLOBALS['timedate']->get_date_format(),
292 $focus = new stdClass;
302 public function testInvalidDate()
304 $this->_ifs->dateformat = 'm/d/Y';
305 $focus = new stdClass;
314 public function testInvalidDateBadMonth()
316 $this->_ifs->dateformat = 'm/d/Y';
317 $focus = new stdClass;
326 public function testValidEmail()
330 'sugas@sugarcrm.com',array()),
331 'sugas@sugarcrm.com');
334 public function testInvalidEmail()
338 'sug$%$@as@sugarcrm.com',array()));
341 public function testValidEnum()
343 $vardefs = array('options' => 'salutation_dom');
351 public function testInvalidEnum()
353 $vardefs = array('options' => 'salutation_dom');
363 public function testEnumWithDisplayValue()
365 $langpack = new SugarTestLangPackCreator();
366 $langpack->setAppListString('checkbox_dom',array(''=>'','1'=>'Yep','2'=>'Nada'));
369 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
371 $vardefs = array('options' => 'checkbox_dom');
382 public function testEnumWithExtraSpacesAtTheEnd()
384 $langpack = new SugarTestLangPackCreator();
385 $langpack->setAppListString('checkbox_dom',array(''=>'','1'=>'Yep','2'=>'Nada'));
388 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
390 $vardefs = array('options' => 'checkbox_dom');
401 public function testEnumWithKeyInDifferentCase()
403 $langpack = new SugarTestLangPackCreator();
404 $langpack->setAppListString('gender_list',array('male' => 'Male','female' => 'Female',));
407 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
409 $vardefs = array('options' => 'gender_list');
420 public function testEnumWithValueInDifferentCase()
422 $langpack = new SugarTestLangPackCreator();
423 $langpack->setAppListString('checkbox_dom',array(''=>'','1'=>'Yep','2'=>'Nada'));
426 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
428 $vardefs = array('options' => 'checkbox_dom');
436 public function testValidId()
440 '1234567890',array()),
444 public function testInvalidId()
448 '1234567890123456789012345678901234567890',array()));
451 public function testValidInt()
453 $this->assertEquals($this->_ifs->int('100',array()),100);
455 $this->_ifs->num_grp_sep = ',';
457 $this->assertEquals($this->_ifs->int('1,123',array()),1123);
460 public function testInvalidInt()
462 $this->_ifs->num_grp_sep = '.';
463 $this->assertFalse($this->_ifs->int('123,23',array()));
464 $this->_ifs->num_grp_sep = ',';
465 $this->assertFalse($this->_ifs->int('123.23',array()));
468 public function testValidFloat()
470 $this->_ifs->dec_sep = '.';
472 $this->assertEquals($this->_ifs->currency('100',array()),100);
473 $this->assertEquals($this->_ifs->currency('123.23',array()),123.23);
475 $this->_ifs->dec_sep = ',';
477 $this->assertEquals($this->_ifs->currency('123,23',array()),123.23);
479 $this->_ifs->num_grp_sep = ',';
481 $this->assertEquals($this->_ifs->currency('1,123.23',array()),1123.23);
484 public function testInvalidFloat()
486 $this->_ifs->dec_sep = '.';
488 $this->assertNotEquals($this->_ifs->currency('123,23',array()),123.23);
491 public function testValidFullname()
493 $this->_ifs->default_locale_name_format = 'l f';
495 $focus = loadBean('Contacts');
497 $this->_ifs->fullname('Bar Foo',array(),$focus);
499 $this->assertEquals($focus->first_name,'Foo');
500 $this->assertEquals($focus->last_name,'Bar');
503 public function testInvalidFullname()
505 $this->_ifs->default_locale_name_format = 'f l';
507 $focus = loadBean('Contacts');
509 $this->_ifs->fullname('Bar Foo',array(),$focus);
511 $this->assertNotEquals($focus->first_name,'Foo');
512 $this->assertNotEquals($focus->last_name,'Bar');
515 public function testValidMultiEnum()
517 $vardefs = array('options' => 'salutation_dom');
520 $this->_ifs->multienum(
521 'Mr.,Mrs.',$vardefs),
522 encodeMultienumValue(array('Mr.', 'Mrs.')));
524 $this->_ifs->multienum(
525 '^Mr.^,^Mrs.^',$vardefs),
526 encodeMultienumValue(array('Mr.', 'Mrs.')));
532 public function testValidMultiEnumWhenSpacesExistInTheValue()
534 $vardefs = array('options' => 'salutation_dom');
537 $this->_ifs->multienum(
538 'Mr., Mrs.',$vardefs),
539 encodeMultienumValue(array('Mr.', 'Mrs.')));
542 public function testInvalidMultiEnum()
544 $vardefs = array('options' => 'salutation_dom');
547 $this->_ifs->multienum(
548 'Mr.,foo.',$vardefs));
551 public function testValidName()
555 '1234567890',array('len' => 12)),
559 public function testInvalidName()
563 '1234567890123456789012345678901234567890',array('len' => 12)),
567 public function testParent()
569 $account_name = 'test case account'.date("YmdHis");
570 $focus = loadBean('Accounts');
571 $focus->name = $account_name;
573 $account_id = $focus->id;
575 $focus = loadBean('Contacts');
578 'source' => 'non-db',
579 'name' => 'parent_name',
580 'vname' => 'LBL_FLEX_RELATE',
585 'importable' => 'false',
586 'duplicate_merge' => 'disabled',
587 'duplicate_merge_dom_value' => '0',
591 'options' => 'parent_type_display',
592 'studio' => 'visible',
593 'type_name' => 'parent_type',
594 'id_name' => 'parent_id',
595 'parent_type' => 'record_type_display',
597 $focus->parent_name = '';
598 $focus->parent_id = '';
599 $focus->parent_type = 'Accounts';
606 $this->assertEquals($focus->parent_id,$account_id);
608 $GLOBALS['db']->query("DELETE FROM accounts where id = '$account_id'");
611 public function testRelate()
613 $account_name = 'test case account'.date("YmdHis");
614 $focus = loadBean('Accounts');
615 $focus->name = $account_name;
617 $account_id = $focus->id;
619 $focus = loadBean('Contacts');
621 'name' => 'account_name',
623 'id_name' => 'account_id',
624 'vname' => 'LBL_ACCOUNT_NAME',
625 'join_name'=>'accounts',
627 'link' => 'accounts',
628 'table' => 'accounts',
630 'module' => 'Accounts',
631 'dbType' => 'varchar',
633 'source' => 'non-db',
634 'unified_search' => true,
642 $this->assertEquals($focus->account_id,$account_id);
644 $GLOBALS['db']->query("DELETE FROM accounts where id = '$account_id'");
647 public function testRelateCreateRecord()
649 $account_name = 'test case account'.date("YmdHis");
651 $focus = loadBean('Contacts');
653 'name' => 'account_name',
655 'id_name' => 'account_id',
656 'vname' => 'LBL_ACCOUNT_NAME',
657 'join_name'=>'accounts',
659 'link' => 'accounts',
660 'table' => 'accounts',
662 'module' => 'Accounts',
663 'dbType' => 'varchar',
665 'source' => 'non-db',
666 'unified_search' => true,
671 require('include/modules.php');
672 $GLOBALS['beanList'] = $beanList;
680 unset($GLOBALS['beanList']);
682 $result = $GLOBALS['db']->query(
683 "SELECT id FROM accounts where name = '$account_name'");
684 $relaterow = $focus->db->fetchByAssoc($result);
686 $this->assertEquals($focus->account_id,$relaterow['id']);
688 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
694 public function testRelateCreateRecordNoTableInVardef()
696 $account_name = 'test case account'.date("YmdHis");
698 $focus = loadBean('Contacts');
700 'name' => 'account_name',
702 'id_name' => 'account_id',
703 'vname' => 'LBL_ACCOUNT_NAME',
704 'join_name'=>'accounts',
706 'link' => 'accounts',
708 'module' => 'Accounts',
709 'dbType' => 'varchar',
711 'source' => 'non-db',
712 'unified_search' => true,
717 require('include/modules.php');
718 $GLOBALS['beanList'] = $beanList;
726 unset($GLOBALS['beanList']);
728 $result = $GLOBALS['db']->query(
729 "SELECT id FROM accounts where name = '$account_name'");
730 $relaterow = $focus->db->fetchByAssoc($result);
732 $this->assertEquals($focus->account_id,$relaterow['id']);
734 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
740 public function testRelateCreateRecordIfNoRnameParameter()
742 $account_name = 'test case account'.date("YmdHis");
744 $focus = loadBean('Contacts');
746 'name' => 'account_name',
747 'id_name' => 'account_id',
748 'vname' => 'LBL_ACCOUNT_NAME',
749 'join_name'=>'accounts',
751 'link' => 'accounts',
752 'table' => 'accounts',
754 'module' => 'Accounts',
755 'dbType' => 'varchar',
757 'source' => 'non-db',
758 'unified_search' => true,
763 require('include/modules.php');
764 $GLOBALS['beanList'] = $beanList;
772 unset($GLOBALS['beanList']);
774 $result = $GLOBALS['db']->query(
775 "SELECT id FROM accounts where name = '$account_name'");
776 $relaterow = $focus->db->fetchByAssoc($result);
778 $this->assertEquals($focus->account_id,$relaterow['id']);
780 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
786 public function testRelateCreateRecordCheckACL()
788 $account_name = 'test case account '.date("YmdHis");
790 $focus = new Import_Bug26897_Mock;
792 'name' => 'account_name',
794 'id_name' => 'account_id',
795 'vname' => 'LBL_CATEGORY_NAME',
796 'join_name'=>'accounts',
798 'link' => 'accounts_link',
799 'table' => 'accounts',
801 'module' => 'Import_Bug26897_Mock',
802 'dbType' => 'varchar',
804 'source' => 'non-db',
809 require('include/modules.php');
810 $beanList['Import_Bug26897_Mock'] = 'Import_Bug26897_Mock';
811 $beanFiles['Import_Bug26897_Mock'] = 'modules/Accounts/Account.php';
812 $GLOBALS['beanList'] = $beanList;
813 $GLOBALS['beanFiles'] = $beanFiles;
821 unset($GLOBALS['beanList']);
822 unset($GLOBALS['beanFiles']);
824 $result = $GLOBALS['db']->query(
825 "SELECT id FROM accounts where name = '$account_name'");
826 $relaterow = $focus->db->fetchByAssoc($result);
828 $this->assertTrue(empty($focus->account_id),'Category ID should not be set');
829 $this->assertFalse($relaterow,'Record should not be added to the related table');
831 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
837 public function testRelateDoNotCreateRecordIfRelatedModuleIsUsers()
839 $account_name = 'test case account'.date("YmdHis");
842 'name' => 'account_name',
844 'id_name' => 'category_id',
845 'vname' => 'LBL_CATEGORY_NAME',
846 'join_name'=>'accounts',
848 'link' => 'account_link',
852 'dbType' => 'varchar',
854 'source' => 'non-db',
863 unset($GLOBALS['beanList']);
864 unset($GLOBALS['beanFiles']);
866 $result = $GLOBALS['db']->query(
867 "SELECT id FROM accounts where name = '$account_name'");
868 $relaterow = $focus->db->fetchByAssoc($result);
870 $this->assertTrue(empty($focus->account_id),'Category ID should not be set');
871 $this->assertFalse($relaterow,'Record should not be added to the related table');
873 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
879 public function testRelateToUserNameWhenFullNameIsGiven()
883 require('include/modules.php');
884 $GLOBALS['beanList'] = $beanList;
885 $GLOBALS['beanFiles'] = $beanFiles;
887 $accountFocus = new Account;
888 $userFocus = SugarTestUserUtilities::createAnonymousUser();
890 "name" => "assigned_user_name",
891 "link" => "assigned_user_link",
892 "vname" => "LBL_ASSIGNED_TO_NAME",
893 "rname" => "user_name",
895 "reportable" => false,
896 "source" => "non-db",
898 "id_name" => "assigned_user_id",
900 "duplicate_merge" => "disabled",
904 $userFocus->user_name,
906 $userFocus->first_name.' '.$userFocus->last_name,
913 unset($GLOBALS['beanList']);
914 unset($GLOBALS['beanFiles']);
920 public function testRelateCreateRecordUsingMultipleFieldToLinkRecords()
922 $contact_name = 'testcase contact'.date("YmdHis");
924 $focus = new Import_Bug27562_Mock;
927 'name' => 'contact_name',
929 'id_name' => 'contact_id',
930 'vname' => 'LBL_CATEGORY_NAME',
931 'join_name'=>'contacts',
933 'link' => 'contact_link',
934 'table' => 'contacts',
936 'module' => 'Import_Bug27562_Mock',
937 'dbType' => 'varchar',
939 'source' => 'non-db',
944 require('include/modules.php');
945 $beanList['Import_Bug27562_Mock'] = 'Import_Bug27562_Mock';
946 $beanFiles['Import_Bug27562_Mock'] = 'modules/Contacts/Contact.php';
947 $GLOBALS['beanList'] = $beanList;
948 $GLOBALS['beanFiles'] = $beanFiles;
956 unset($GLOBALS['beanList']);
957 unset($GLOBALS['beanFiles']);
959 $nameParts = explode(' ',$contact_name);
960 $result = $GLOBALS['db']->query(
961 "SELECT id FROM contacts where first_name = '{$nameParts[0]}' and last_name = '{$nameParts[1]}'");
962 $relaterow = $focus->db->fetchByAssoc($result);
964 $this->assertEquals($focus->contact_id,$relaterow['id']);
966 $GLOBALS['db']->query("DELETE FROM contacts where id = '{$relaterow['id']}'");
969 public function testRelateDontCreateRecord()
971 $account_name = 'test case account'.date("YmdHis");
973 $focus = loadBean('Contacts');
975 'name' => 'account_name',
977 'id_name' => 'account_id',
978 'vname' => 'LBL_ACCOUNT_NAME',
979 'join_name'=>'accounts',
981 'link' => 'accounts',
982 'table' => 'accounts',
984 'module' => 'Accounts',
985 'dbType' => 'varchar',
987 'source' => 'non-db',
988 'unified_search' => true,
993 require('include/modules.php');
994 $GLOBALS['beanList'] = $beanList;
1002 'Should return false since record could not be found'
1006 unset($GLOBALS['beanList']);
1008 $result = $GLOBALS['db']->query(
1009 "SELECT id FROM accounts where name = '$account_name'");
1010 $relaterow = $focus->db->fetchByAssoc($result);
1011 $this->assertFalse($relaterow,'Record should not have been created');
1013 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
1019 public function testRelateWithInvalidDataFormatting()
1021 $langpack = new SugarTestLangPackCreator();
1022 $langpack->setAppListString('checkbox_dom',array(''=>'','1'=>'Yep','2'=>'Nada'));
1025 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
1027 $account_name = 'test case category'.date("YmdHis");
1029 $focus = new Import_Bug27046_Mock;
1031 'name' => 'account_name',
1033 'id_name' => 'account_id',
1034 'vname' => 'LBL_ACCOUNT_NAME',
1035 'join_name'=>'accounts',
1037 'link' => 'accounts_link',
1038 'table' => 'accounts',
1040 'module' => 'Import_Bug27046_Mock',
1041 'dbType' => 'varchar',
1043 'source' => 'non-db',
1048 $beanList = array();
1049 require('include/modules.php');
1050 $beanList['Import_Bug27046_Mock'] = 'Import_Bug27046_Mock';
1051 $beanFiles['Import_Bug27046_Mock'] = 'modules/Accounts/Account.php';
1052 $GLOBALS['beanList'] = $beanList;
1053 $GLOBALS['beanFiles'] = $beanFiles;
1056 $this->_ifs->relate(
1060 'Should return false since field format is invalid'
1064 unset($GLOBALS['beanList']);
1066 $result = $GLOBALS['db']->query(
1067 "SELECT id FROM accounts where name = '$account_name'");
1068 $relaterow = $focus->db->fetchByAssoc($result);
1069 $this->assertFalse($relaterow,'Record should not have been created');
1071 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
1074 public function testValidSyncToOutlookUser()
1076 $value = $GLOBALS['current_user']->id . ',' . $GLOBALS['current_user']->user_name;
1077 $bad_names = array();
1080 (bool) $this->_ifs->synctooutlook(
1085 'Test $this->_ifs->synctooutlook() not returning false');
1087 $this->assertEquals($bad_names,array());
1089 public function testInvalidSyncToOutlook()
1091 $value = "jghu8h8yhuh8hhi889898898";
1092 $bad_names = array();
1095 $this->_ifs->synctooutlook(
1100 'Test $this->_ifs->synctooutlook() should return false');
1103 public function testValidTimeSameFormat()
1105 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
1107 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
1108 $this->_ifs->timezone = 'America/New_York';
1109 $vardef = array('name' => 'some_date');
1110 $date = date($this->_ifs->timeformat);
1111 $focus = new stdClass;
1113 $this->assertEquals(
1120 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
1123 public function testValidTimeDifferentFormat()
1125 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
1127 $this->_ifs->timeformat = 'h:ia';
1128 if ( $this->_ifs->timeformat == $GLOBALS['timedate']->get_time_format() )
1129 $this->_ifs->timeformat = 'h.ia';
1130 $this->_ifs->timezone = 'America/New_York';
1131 $vardef = array('name' => 'some_date');
1133 $date = date($this->_ifs->timeformat);
1134 $comparedate = date(
1135 $GLOBALS['timedate']->get_time_format(),
1137 $focus = new stdClass;
1139 $this->assertEquals(
1146 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
1149 public function testValidTimeDifferentTimezones()
1151 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
1153 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
1154 $this->_ifs->timezone = 'America/Denver';
1155 $vardef = array('name' => 'some_date');
1156 $date = date($this->_ifs->timeformat);
1157 $comparedate = date(
1158 $GLOBALS['timedate']->get_time_format(),
1159 strtotime('+2 hours',strtotime($date)));
1160 $focus = new stdClass;
1162 $this->assertEquals(
1169 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
1172 public function testInvalidTime()
1174 $this->_ifs->timeformat = 'h:ia';
1175 $this->_ifs->timezone = 'America/New_York';
1176 $focus = new stdClass;
1181 array('name' => 'some_date'),
1185 public function testInvalidTimeBadSeconds()
1187 $this->_ifs->timeformat = 'h:ia';
1188 $this->_ifs->timezone = 'America/New_York';
1189 $focus = new stdClass;
1194 array('name' => 'some_date'),
1199 class Import_Bug26897_Mock extends Account
1201 function ACLAccess($view,$is_owner='not_set')
1206 function bean_implements($interface)
1212 class Import_Bug27562_Mock extends Contact
1216 function ACLAccess($view,$is_owner='not_set')
1222 class Import_Bug27046_Mock extends Account
1224 function ACLAccess($view,$is_owner='not_set')
1229 function bean_implements($interface)
1234 function getFieldDefintion($name)