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/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']);
48 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
49 $GLOBALS['timedate'] = TimeDate::getInstance();
51 require('include/modules.php');
52 $GLOBALS['beanList'] = $beanList;
55 public function tearDown()
57 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
58 unset($GLOBALS['current_user']);
59 unset($GLOBALS['app_list_strings']);
60 unset($GLOBALS['beanList']);
61 $GLOBALS['timedate'] = TimeDate::getInstance();
64 public function testValidBool()
66 $this->assertEquals($this->_ifs->bool(0,array()),0);
67 $this->assertEquals($this->_ifs->bool('no',array()),0);
68 $this->assertEquals($this->_ifs->bool('off',array()),0);
69 $this->assertEquals($this->_ifs->bool('n',array()),0);
70 $this->assertEquals($this->_ifs->bool('yes',array()),1);
71 $this->assertEquals($this->_ifs->bool('y',array()),1);
72 $this->assertEquals($this->_ifs->bool('on',array()),1);
73 $this->assertEquals($this->_ifs->bool(1,array()),1);
76 public function testValidBoolVarchar()
78 $vardefs = array('dbType' => 'varchar');
80 $this->assertEquals($this->_ifs->bool(0,$vardefs),'off');
81 $this->assertEquals($this->_ifs->bool('no',$vardefs),'off');
82 $this->assertEquals($this->_ifs->bool('off',$vardefs),'off');
83 $this->assertEquals($this->_ifs->bool('n',$vardefs),'off');
84 $this->assertEquals($this->_ifs->bool('yes',$vardefs),'on');
85 $this->assertEquals($this->_ifs->bool('y',$vardefs),'on');
86 $this->assertEquals($this->_ifs->bool('on',$vardefs),'on');
87 $this->assertEquals($this->_ifs->bool(1,$vardefs),'on');
90 public function testInvalidBool()
92 $this->assertFalse($this->_ifs->bool('OK',array()));
93 $this->assertFalse($this->_ifs->bool('yep',array()));
96 public function testValidCurrency()
98 $this->_ifs->dec_sep = '.';
99 $this->_ifs->currency_symbol = '$';
101 $this->assertEquals($this->_ifs->currency('$100',array()),100);
104 public function testInvalidCurrency()
106 $this->_ifs->dec_sep = '.';
107 $this->_ifs->currency_symbol = '�';
109 $this->assertNotEquals($this->_ifs->currency('$123.23',array()),123.23);
112 public function testValidDatetimeSameFormat()
114 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
116 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
117 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
118 $this->_ifs->timezone = 'America/New_York';
119 $vardef = array('name' => 'some_date');
120 $date = date($this->_ifs->dateformat . ' ' .$this->_ifs->timeformat);
123 $GLOBALS['timedate']->get_db_date_time_format(),
125 $GLOBALS['timedate']->handle_offset(
126 $date, $GLOBALS['timedate']->get_date_time_format(), false,
127 $GLOBALS['current_user'], 'America/New_York')
132 $this->_ifs->datetime(
137 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
140 public function testValidDatetimeDifferentFormat()
142 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
144 $this->_ifs->dateformat = 'm/d/Y';
145 if ( $this->_ifs->dateformat == $GLOBALS['timedate']->get_date_format() )
146 $this->_ifs->dateformat = 'Y/m/d';
147 $this->_ifs->timeformat = 'h:ia';
148 if ( $this->_ifs->timeformat == $GLOBALS['timedate']->get_time_format() )
149 $this->_ifs->timeformat = 'h.ia';
150 $this->_ifs->timezone = 'America/New_York';
151 $vardef = array('name' => 'some_date');
152 $date = date($this->_ifs->dateformat . ' ' . $this->_ifs->timeformat);
155 $GLOBALS['timedate']->get_db_date_time_format(),
157 $GLOBALS['timedate']->handle_offset(
158 $date, $GLOBALS['timedate']->get_date_time_format(), false,
159 $GLOBALS['current_user'], 'America/New_York')
163 $this->_ifs->datetime(
168 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
171 public function testValidDatetimeDifferentTimezones()
173 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
175 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
176 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
177 $format = $GLOBALS['timedate']->get_date_time_format();
178 $this->_ifs->timezone = 'America/Denver';
179 $vardef = array('name' => 'some_date');
180 $date = date($format);
182 $GLOBALS['timedate']->get_db_date_time_format(),
183 strtotime('+2 hours',strtotime(
184 $GLOBALS['timedate']->handle_offset(
185 $date, $GLOBALS['timedate']->get_date_time_format(), false,
186 $GLOBALS['current_user'], 'America/New_York')
190 $this->_ifs->datetime(
195 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
198 public function testValidDatetimeDateEntered()
200 $_SESSION[$GLOBALS['current_user']->id.'_PREFERENCES']['global']['timezone'] = 'Atlantic/Cape_Verde';
202 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
203 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
204 $format = $GLOBALS['timedate']->get_date_time_format();
205 $this->_ifs->timezone = 'Atlantic/Cape_Verde';
206 $vardef = array('name' => 'date_entered');
207 $date = date($format);
209 $GLOBALS['timedate']->get_db_date_time_format(),
210 strtotime('+1 hours',strtotime($date)));
213 $this->_ifs->datetime(
218 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
221 public function testValidDatetimeDateOnly()
223 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
225 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
226 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
227 $format = $GLOBALS['timedate']->get_date_format();
228 $this->_ifs->timezone = 'America/New_York';
229 $vardef = array('name' => 'date_entered');
230 $date = date($format);
232 $GLOBALS['timedate']->get_db_date_time_format(),
236 (bool) $this->_ifs->datetime(
240 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
243 public function testInvalidDatetime()
245 $this->_ifs->dateformat = 'm.d.Y';
246 $this->_ifs->timeformat = 'h:ia';
247 $this->_ifs->timezone = 'America/New_York';
250 $this->_ifs->datetime(
252 array('name' => 'some_date')));
255 public function testInvalidDatetimeBadDayBadHour()
257 $this->_ifs->dateformat = 'm.d.Y';
258 $this->_ifs->timeformat = 'h:ia';
259 $this->_ifs->timezone = 'America/New_York';
262 $this->_ifs->datetime(
264 array('name' => 'some_date')));
267 public function testValidDateSameFormat()
269 $this->_ifs->dateformat = $GLOBALS['timedate']->get_date_format();
270 $date = date($this->_ifs->dateformat);
271 $focus = new stdClass;
281 public function testValidDateDifferentFormat()
283 $this->_ifs->dateformat = 'm/d/Y';
284 if ( $this->_ifs->dateformat == $GLOBALS['timedate']->get_date_format() )
285 $this->_ifs->dateformat = 'Y/m/d';
286 $date = date($this->_ifs->dateformat );
288 $GLOBALS['timedate']->get_date_format(),
290 $focus = new stdClass;
300 public function testInvalidDate()
302 $this->_ifs->dateformat = 'm/d/Y';
303 $focus = new stdClass;
312 public function testInvalidDateBadMonth()
314 $this->_ifs->dateformat = 'm/d/Y';
315 $focus = new stdClass;
324 public function testValidEmail()
328 'sugas@sugarcrm.com',array()),
329 'sugas@sugarcrm.com');
332 public function testInvalidEmail()
336 'sug$%$@as@sugarcrm.com',array()));
339 public function testValidEnum()
341 $vardefs = array('options' => 'salutation_dom');
349 public function testInvalidEnum()
351 $vardefs = array('options' => 'salutation_dom');
361 public function testEnumWithDisplayValue()
363 $langpack = new SugarTestLangPackCreator();
364 $langpack->setAppListString('checkbox_dom',array(''=>'','1'=>'Yep','2'=>'Nada'));
367 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
369 $vardefs = array('options' => 'checkbox_dom');
380 public function testEnumWithExtraSpacesAtTheEnd()
382 $langpack = new SugarTestLangPackCreator();
383 $langpack->setAppListString('checkbox_dom',array(''=>'','1'=>'Yep','2'=>'Nada'));
386 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
388 $vardefs = array('options' => 'checkbox_dom');
399 public function testEnumWithKeyInDifferentCase()
401 $langpack = new SugarTestLangPackCreator();
402 $langpack->setAppListString('gender_list',array('male' => 'Male','female' => 'Female',));
405 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
407 $vardefs = array('options' => 'gender_list');
418 public function testEnumWithValueInDifferentCase()
420 $langpack = new SugarTestLangPackCreator();
421 $langpack->setAppListString('checkbox_dom',array(''=>'','1'=>'Yep','2'=>'Nada'));
424 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
426 $vardefs = array('options' => 'checkbox_dom');
434 public function testValidId()
438 '1234567890',array()),
442 public function testInvalidId()
446 '1234567890123456789012345678901234567890',array()));
449 public function testValidInt()
451 $this->assertEquals($this->_ifs->int('100',array()),100);
453 $this->_ifs->num_grp_sep = ',';
455 $this->assertEquals($this->_ifs->int('1,123',array()),1123);
458 public function testInvalidInt()
460 $this->_ifs->num_grp_sep = '.';
461 $this->assertFalse($this->_ifs->int('123,23',array()));
462 $this->_ifs->num_grp_sep = ',';
463 $this->assertFalse($this->_ifs->int('123.23',array()));
466 public function testValidFloat()
468 $this->_ifs->dec_sep = '.';
470 $this->assertEquals($this->_ifs->currency('100',array()),100);
471 $this->assertEquals($this->_ifs->currency('123.23',array()),123.23);
473 $this->_ifs->dec_sep = ',';
475 $this->assertEquals($this->_ifs->currency('123,23',array()),123.23);
477 $this->_ifs->num_grp_sep = ',';
479 $this->assertEquals($this->_ifs->currency('1,123.23',array()),1123.23);
482 public function testInvalidFloat()
484 $this->_ifs->dec_sep = '.';
486 $this->assertNotEquals($this->_ifs->currency('123,23',array()),123.23);
489 public function testValidFullname()
491 $this->_ifs->default_locale_name_format = 'l f';
493 $focus = loadBean('Contacts');
495 $this->_ifs->fullname('Bar Foo',array(),$focus);
497 $this->assertEquals($focus->first_name,'Foo');
498 $this->assertEquals($focus->last_name,'Bar');
501 public function testInvalidFullname()
503 $this->_ifs->default_locale_name_format = 'f l';
505 $focus = loadBean('Contacts');
507 $this->_ifs->fullname('Bar Foo',array(),$focus);
509 $this->assertNotEquals($focus->first_name,'Foo');
510 $this->assertNotEquals($focus->last_name,'Bar');
513 public function testValidMultiEnum()
515 $vardefs = array('options' => 'salutation_dom');
518 $this->_ifs->multienum(
519 'Mr.,Mrs.',$vardefs),
520 encodeMultienumValue(array('Mr.', 'Mrs.')));
522 $this->_ifs->multienum(
523 '^Mr.^,^Mrs.^',$vardefs),
524 encodeMultienumValue(array('Mr.', 'Mrs.')));
530 public function testValidMultiEnumWhenSpacesExistInTheValue()
532 $vardefs = array('options' => 'salutation_dom');
535 $this->_ifs->multienum(
536 'Mr., Mrs.',$vardefs),
537 encodeMultienumValue(array('Mr.', 'Mrs.')));
540 public function testInvalidMultiEnum()
542 $vardefs = array('options' => 'salutation_dom');
545 $this->_ifs->multienum(
546 'Mr.,foo.',$vardefs));
549 public function testValidName()
553 '1234567890',array('len' => 12)),
557 public function testInvalidName()
561 '1234567890123456789012345678901234567890',array('len' => 12)),
565 public function testParent()
567 $account_name = 'test case account'.date("YmdHis");
568 $focus = loadBean('Accounts');
569 $focus->name = $account_name;
571 $account_id = $focus->id;
573 $focus = loadBean('Contacts');
576 'source' => 'non-db',
577 'name' => 'parent_name',
578 'vname' => 'LBL_FLEX_RELATE',
583 'importable' => 'false',
584 'duplicate_merge' => 'disabled',
585 'duplicate_merge_dom_value' => '0',
589 'options' => 'parent_type_display',
590 'studio' => 'visible',
591 'type_name' => 'parent_type',
592 'id_name' => 'parent_id',
593 'parent_type' => 'record_type_display',
595 $focus->parent_name = '';
596 $focus->parent_id = '';
597 $focus->parent_type = 'Accounts';
604 $this->assertEquals($focus->parent_id,$account_id);
606 $GLOBALS['db']->query("DELETE FROM accounts where id = '$account_id'");
609 public function testRelate()
611 $account_name = 'test case account'.date("YmdHis");
612 $focus = loadBean('Accounts');
613 $focus->name = $account_name;
615 $account_id = $focus->id;
617 $focus = loadBean('Contacts');
619 'name' => 'account_name',
621 'id_name' => 'account_id',
622 'vname' => 'LBL_ACCOUNT_NAME',
623 'join_name'=>'accounts',
625 'link' => 'accounts',
626 'table' => 'accounts',
628 'module' => 'Accounts',
629 'dbType' => 'varchar',
631 'source' => 'non-db',
632 'unified_search' => true,
640 $this->assertEquals($focus->account_id,$account_id);
642 $GLOBALS['db']->query("DELETE FROM accounts where id = '$account_id'");
645 public function testRelateCreateRecord()
647 $account_name = 'test case account'.date("YmdHis");
649 $focus = loadBean('Contacts');
651 'name' => 'account_name',
653 'id_name' => 'account_id',
654 'vname' => 'LBL_ACCOUNT_NAME',
655 'join_name'=>'accounts',
657 'link' => 'accounts',
658 'table' => 'accounts',
660 'module' => 'Accounts',
661 'dbType' => 'varchar',
663 'source' => 'non-db',
664 'unified_search' => true,
669 require('include/modules.php');
670 $GLOBALS['beanList'] = $beanList;
678 unset($GLOBALS['beanList']);
680 $result = $GLOBALS['db']->query(
681 "SELECT id FROM accounts where name = '$account_name'");
682 $relaterow = $focus->db->fetchByAssoc($result);
684 $this->assertEquals($focus->account_id,$relaterow['id']);
686 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
692 public function testRelateCreateRecordNoTableInVardef()
694 $account_name = 'test case account'.date("YmdHis");
696 $focus = loadBean('Contacts');
698 'name' => 'account_name',
700 'id_name' => 'account_id',
701 'vname' => 'LBL_ACCOUNT_NAME',
702 'join_name'=>'accounts',
704 'link' => 'accounts',
706 'module' => 'Accounts',
707 'dbType' => 'varchar',
709 'source' => 'non-db',
710 'unified_search' => true,
715 require('include/modules.php');
716 $GLOBALS['beanList'] = $beanList;
724 unset($GLOBALS['beanList']);
726 $result = $GLOBALS['db']->query(
727 "SELECT id FROM accounts where name = '$account_name'");
728 $relaterow = $focus->db->fetchByAssoc($result);
730 $this->assertEquals($focus->account_id,$relaterow['id']);
732 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
738 public function testRelateCreateRecordIfNoRnameParameter()
740 $account_name = 'test case account'.date("YmdHis");
742 $focus = loadBean('Contacts');
744 'name' => 'account_name',
745 'id_name' => 'account_id',
746 'vname' => 'LBL_ACCOUNT_NAME',
747 'join_name'=>'accounts',
749 'link' => 'accounts',
750 'table' => 'accounts',
752 'module' => 'Accounts',
753 'dbType' => 'varchar',
755 'source' => 'non-db',
756 'unified_search' => true,
761 require('include/modules.php');
762 $GLOBALS['beanList'] = $beanList;
770 unset($GLOBALS['beanList']);
772 $result = $GLOBALS['db']->query(
773 "SELECT id FROM accounts where name = '$account_name'");
774 $relaterow = $focus->db->fetchByAssoc($result);
776 $this->assertEquals($focus->account_id,$relaterow['id']);
778 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
784 public function testRelateCreateRecordCheckACL()
786 $account_name = 'test case account '.date("YmdHis");
788 $focus = new Import_Bug26897_Mock;
790 'name' => 'account_name',
792 'id_name' => 'account_id',
793 'vname' => 'LBL_CATEGORY_NAME',
794 'join_name'=>'accounts',
796 'link' => 'accounts_link',
797 'table' => 'accounts',
799 'module' => 'Import_Bug26897_Mock',
800 'dbType' => 'varchar',
802 'source' => 'non-db',
807 require('include/modules.php');
808 $beanList['Import_Bug26897_Mock'] = 'Import_Bug26897_Mock';
809 $beanFiles['Import_Bug26897_Mock'] = 'modules/Accounts/Account.php';
810 $GLOBALS['beanList'] = $beanList;
811 $GLOBALS['beanFiles'] = $beanFiles;
819 unset($GLOBALS['beanList']);
820 unset($GLOBALS['beanFiles']);
822 $result = $GLOBALS['db']->query(
823 "SELECT id FROM accounts where name = '$account_name'");
824 $relaterow = $focus->db->fetchByAssoc($result);
826 $this->assertTrue(empty($focus->account_id),'Category ID should not be set');
827 $this->assertNull($relaterow,'Record should not be added to the related table');
829 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
835 public function testRelateDoNotCreateRecordIfRelatedModuleIsUsers()
837 $account_name = 'test case account'.date("YmdHis");
840 'name' => 'account_name',
842 'id_name' => 'category_id',
843 'vname' => 'LBL_CATEGORY_NAME',
844 'join_name'=>'accounts',
846 'link' => 'account_link',
850 'dbType' => 'varchar',
852 'source' => 'non-db',
861 unset($GLOBALS['beanList']);
862 unset($GLOBALS['beanFiles']);
864 $result = $GLOBALS['db']->query(
865 "SELECT id FROM accounts where name = '$account_name'");
866 $relaterow = $focus->db->fetchByAssoc($result);
868 $this->assertTrue(empty($focus->account_id),'Category ID should not be set');
869 $this->assertNull($relaterow,'Record should not be added to the related table');
871 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
877 public function testRelateToUserNameWhenFullNameIsGiven()
881 require('include/modules.php');
882 $GLOBALS['beanList'] = $beanList;
883 $GLOBALS['beanFiles'] = $beanFiles;
885 $accountFocus = new Account;
886 $userFocus = SugarTestUserUtilities::createAnonymousUser();
888 "name" => "assigned_user_name",
889 "link" => "assigned_user_link",
890 "vname" => "LBL_ASSIGNED_TO_NAME",
891 "rname" => "user_name",
893 "reportable" => false,
894 "source" => "non-db",
896 "id_name" => "assigned_user_id",
898 "duplicate_merge" => "disabled",
902 $userFocus->user_name,
904 $userFocus->first_name.' '.$userFocus->last_name,
911 unset($GLOBALS['beanList']);
912 unset($GLOBALS['beanFiles']);
918 public function testRelateCreateRecordUsingMultipleFieldToLinkRecords()
920 $contact_name = 'testcase contact'.date("YmdHis");
922 $focus = new Import_Bug27562_Mock;
925 'name' => 'contact_name',
927 'id_name' => 'contact_id',
928 'vname' => 'LBL_CATEGORY_NAME',
929 'join_name'=>'contacts',
931 'link' => 'contact_link',
932 'table' => 'contacts',
934 'module' => 'Import_Bug27562_Mock',
935 'dbType' => 'varchar',
937 'source' => 'non-db',
942 require('include/modules.php');
943 $beanList['Import_Bug27562_Mock'] = 'Import_Bug27562_Mock';
944 $beanFiles['Import_Bug27562_Mock'] = 'modules/Contacts/Contact.php';
945 $GLOBALS['beanList'] = $beanList;
946 $GLOBALS['beanFiles'] = $beanFiles;
954 unset($GLOBALS['beanList']);
955 unset($GLOBALS['beanFiles']);
957 $nameParts = explode(' ',$contact_name);
958 $result = $GLOBALS['db']->query(
959 "SELECT id FROM contacts where first_name = '{$nameParts[0]}' and last_name = '{$nameParts[1]}'");
960 $relaterow = $focus->db->fetchByAssoc($result);
962 $this->assertEquals($focus->contact_id,$relaterow['id']);
964 $GLOBALS['db']->query("DELETE FROM contacts where id = '{$relaterow['id']}'");
967 public function testRelateDontCreateRecord()
969 $account_name = 'test case account'.date("YmdHis");
971 $focus = loadBean('Contacts');
973 'name' => 'account_name',
975 'id_name' => 'account_id',
976 'vname' => 'LBL_ACCOUNT_NAME',
977 'join_name'=>'accounts',
979 'link' => 'accounts',
980 'table' => 'accounts',
982 'module' => 'Accounts',
983 'dbType' => 'varchar',
985 'source' => 'non-db',
986 'unified_search' => true,
991 require('include/modules.php');
992 $GLOBALS['beanList'] = $beanList;
1000 'Should return false since record could not be found'
1004 unset($GLOBALS['beanList']);
1006 $result = $GLOBALS['db']->query(
1007 "SELECT id FROM accounts where name = '$account_name'");
1008 $relaterow = $focus->db->fetchByAssoc($result);
1009 $this->assertNull($relaterow,'Record should not have been created');
1011 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
1017 public function testRelateWithInvalidDataFormatting()
1019 $langpack = new SugarTestLangPackCreator();
1020 $langpack->setAppListString('checkbox_dom',array(''=>'','1'=>'Yep','2'=>'Nada'));
1023 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
1025 $account_name = 'test case category'.date("YmdHis");
1027 $focus = new Import_Bug27046_Mock;
1029 'name' => 'account_name',
1031 'id_name' => 'account_id',
1032 'vname' => 'LBL_ACCOUNT_NAME',
1033 'join_name'=>'accounts',
1035 'link' => 'accounts_link',
1036 'table' => 'accounts',
1038 'module' => 'Import_Bug27046_Mock',
1039 'dbType' => 'varchar',
1041 'source' => 'non-db',
1046 $beanList = array();
1047 require('include/modules.php');
1048 $beanList['Import_Bug27046_Mock'] = 'Import_Bug27046_Mock';
1049 $beanFiles['Import_Bug27046_Mock'] = 'modules/Accounts/Account.php';
1050 $GLOBALS['beanList'] = $beanList;
1051 $GLOBALS['beanFiles'] = $beanFiles;
1054 $this->_ifs->relate(
1058 'Should return false since field format is invalid'
1062 unset($GLOBALS['beanList']);
1064 $result = $GLOBALS['db']->query(
1065 "SELECT id FROM accounts where name = '$account_name'");
1066 $relaterow = $focus->db->fetchByAssoc($result);
1067 $this->assertNull($relaterow,'Record should not have been created');
1069 $GLOBALS['db']->query("DELETE FROM accounts where id = '{$relaterow['id']}'");
1072 public function testValidSyncToOutlookUser()
1074 $value = $GLOBALS['current_user']->id . ',' . $GLOBALS['current_user']->user_name;
1075 $bad_names = array();
1078 (bool) $this->_ifs->synctooutlook(
1083 'Test $this->_ifs->synctooutlook() not returning false');
1085 $this->assertEquals($bad_names,array());
1087 public function testInvalidSyncToOutlook()
1089 $value = "jghu8h8yhuh8hhi889898898";
1090 $bad_names = array();
1093 $this->_ifs->synctooutlook(
1098 'Test $this->_ifs->synctooutlook() should return false');
1101 public function testValidTimeSameFormat()
1103 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
1105 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
1106 $this->_ifs->timezone = 'America/New_York';
1107 $vardef = array('name' => 'some_date');
1108 $date = date($this->_ifs->timeformat);
1109 $focus = new stdClass;
1111 $this->assertEquals(
1118 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
1121 public function testValidTimeDifferentFormat()
1123 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
1125 $this->_ifs->timeformat = 'h:ia';
1126 if ( $this->_ifs->timeformat == $GLOBALS['timedate']->get_time_format() )
1127 $this->_ifs->timeformat = 'h.ia';
1128 $this->_ifs->timezone = 'America/New_York';
1129 $vardef = array('name' => 'some_date');
1131 $date = date($this->_ifs->timeformat);
1132 $comparedate = date(
1133 $GLOBALS['timedate']->get_time_format(),
1135 $focus = new stdClass;
1137 $this->assertEquals(
1144 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
1147 public function testValidTimeDifferentTimezones()
1149 $_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone'] = 'America/New_York';
1151 $this->_ifs->timeformat = $GLOBALS['timedate']->get_time_format();
1152 $this->_ifs->timezone = 'America/Denver';
1153 $vardef = array('name' => 'some_date');
1154 $date = date($this->_ifs->timeformat);
1155 $comparedate = date(
1156 $GLOBALS['timedate']->get_time_format(),
1157 strtotime('+2 hours',strtotime($date)));
1158 $focus = new stdClass;
1160 $this->assertEquals(
1167 unset($_SESSION[$GLOBALS['current_user']->user_name.'_PREFERENCES']['global']['timezone']);
1170 public function testInvalidTime()
1172 $this->_ifs->timeformat = 'h:ia';
1173 $this->_ifs->timezone = 'America/New_York';
1174 $focus = new stdClass;
1179 array('name' => 'some_date'),
1183 public function testInvalidTimeBadSeconds()
1185 $this->_ifs->timeformat = 'h:ia';
1186 $this->_ifs->timezone = 'America/New_York';
1187 $focus = new stdClass;
1192 array('name' => 'some_date'),
1197 class Import_Bug26897_Mock extends Account
1199 function ACLAccess($view,$is_owner='not_set')
1204 function bean_implements($interface)
1210 class Import_Bug27562_Mock extends Contact
1214 function ACLAccess($view,$is_owner='not_set')
1220 class Import_Bug27046_Mock extends Account
1222 function ACLAccess($view,$is_owner='not_set')
1227 function bean_implements($interface)
1232 function getFieldDefintion($name)