3 /*********************************************************************************
4 * By installing or using this file, you are confirming on behalf of the entity
5 * subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
6 * the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
7 * http://www.sugarcrm.com/master-subscription-agreement
9 * If Company is not bound by the MSA, then by installing or using this file
10 * you are agreeing unconditionally that Company will be bound by the MSA and
11 * certifying that you have authority to bind Company accordingly.
13 * Copyright (C) 2004-2013 SugarCRM Inc. All rights reserved.
14 ********************************************************************************/
17 require_once('data/SugarBean.php');
18 require_once("modules/Administration/QuickRepairAndRebuild.php");
19 require_once('modules/DynamicFields/FieldCases.php');
21 //This Unit test makes sure that no php fatal errors are output when merging two records that have calculated fields
22 //pointing to a related value
23 class Bug61734Test extends Sugar_PHPUnit_Framework_OutputTestCase
27 public $custFileDirPath = 'Extension/modules/Accounts/Ext/Vardefs/';
28 public $custFieldName = 'cf_61734_c';
33 public function setUp()
35 SugarTestHelper::setUp('beanList');
36 SugarTestHelper::setUp('beanFiles');
37 SugarTestHelper::setUp('current_user', array(true, 1));
38 SugarTestHelper::setUp('app_list_strings');
39 SugarTestHelper::setUp('mod_strings', array('Administration'));
40 SugarTestHelper::setUp('dictionary');
42 $this->createCustom();
44 $this->acc = SugarTestAccountUtilities::createAccount();
45 $this->acc2 = SugarTestAccountUtilities::createAccount();
50 public function tearDown()
52 $this->custField->delete($this->df);
53 $_REQUEST['repair_silent']=1;
54 $rc = new RepairAndClear();
55 $rc->repairAndClearAll(array("clearAll", "rebuildExtensions"), array("Accounts"), false, false);
56 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
57 SugarTestAccountUtilities::removeAllCreatedAccounts();
58 SugarTestHelper::tearDown();
59 $GLOBALS['reload_vardefs'] = true;
61 $GLOBALS['reload_vardefs'] = false;
64 public function createCustom(){
65 //create new varchar widget and associate with Accounts
66 $this->custField = get_widget('varchar');
67 $this->custField->id = 'Accounts'.$this->custFieldName;
68 $this->custField->name = $this->custFieldName;
69 $this->custField->type = 'varchar';
70 $this->custField->label = 'LBL_' . strtoupper($this->custFieldName);
71 $this->custField->vname = 'LBL_' . strtoupper($this->custFieldName);
72 $this->custField->len = 255;
73 $this->custField->custom_module = 'Accounts';
74 $this->custField->required = 0;
75 $this->custField->default = 'goofy';
77 $this->acc = new Account();
78 $this->df = new DynamicField('Accounts');
79 $this->df->setup($this->acc);
81 $this->df->addFieldObject($this->custField);
82 $this->df->buildCache('Accounts');
83 $this->custField->save($this->df);
85 VardefManager::clearVardef();
86 VardefManager::refreshVardefs('Accounts', 'Account');
88 //Now create the meta files to make this a Calculated Field.
89 $fn = $this->custFieldName;
90 $extensionContent = <<<EOQ
92 \$dictionary['Account']['fields']['$fn']['duplicate_merge_dom_value']=0;
93 \$dictionary['Account']['fields']['$fn']['calculated']='true';
94 \$dictionary['Account']['fields']['$fn']['formula']='related(\$assigned_user_link,"name")';
95 \$dictionary['Account']['fields']['$fn']['enforced']='true';
96 \$dictionary['Account']['fields']['$fn']['dependency']='';
97 \$dictionary['Account']['fields']['$fn']['type']='varchar';
98 \$dictionary['Account']['fields']['$fn']['name']='$fn';
102 //create custom field file
103 $this->custFileDirPath = create_custom_directory($this->custFileDirPath);
104 $fileLoc = $this->custFileDirPath.'sugarfield_'.$this->custFieldName.'.php';
105 file_put_contents($fileLoc, $extensionContent);
107 //run repair and clear to make sure the meta gets picked up
108 $_REQUEST['repair_silent']=1;
109 $rc = new RepairAndClear();
110 $rc->repairAndClearAll(array("clearAll", "rebuildExtensions"), array("Accounts"), false, false);
111 $fn = $this->custFieldName;
114 public function testMergeWithCalculatedField()
116 //recreate expected request and post superglobals for savemerge.php
117 $_REQUEST = $_POST = array(
118 'module' => 'MergeRecords',
119 'record' => $this->acc->id,
120 'merge_module' => 'Accounts',
121 'action' => 'SaveMerge',
122 'return_module' => 'Accounts',
123 'return_action' => 'index',
124 'change_parent' => 0,
126 'merged_links' => 'assigned_user_link,member_of',
127 'merged_ids' => array
130 'button' => 'Save Merge',
131 'name' => 'SugarAccount1091847479',
132 'date_entered' => '04/08/2013 03:18pm',
133 'date_modified' => '04/08/2013 03:18pm',
134 'team_name' => 'team_name',
135 'team_name_field' => 'team_name_table',
136 'team_name_collection_0' => 'Global',
137 'id_team_name_collection_0' => 1,
138 'primary_team_name_collection' => 0,
141 //call SaveMerge so the account beans can be merged
142 require_once('modules/MergeRecords/SaveMerge.php');
144 //make sure fatal error is not being output
145 $this->expectOutputNotRegex('/fatal/i', 'Failure message is appearing during merge');