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('dictionary');
41 $this->createCustom();
43 $this->acc = SugarTestAccountUtilities::createAccount();
44 $this->acc2 = SugarTestAccountUtilities::createAccount();
49 public function tearDown()
51 $this->custField->delete($this->df);
52 $_REQUEST['repair_silent']=1;
53 $rc = new RepairAndClear();
54 $rc->repairAndClearAll(array("clearAll", "rebuildExtensions"), array("Accounts"), false, false);
55 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
56 SugarTestAccountUtilities::removeAllCreatedAccounts();
57 SugarTestHelper::tearDown();
58 $GLOBALS['reload_vardefs'] = true;
60 $GLOBALS['reload_vardefs'] = false;
63 public function createCustom(){
64 //create new varchar widget and associate with Accounts
65 $this->custField = get_widget('varchar');
66 $this->custField->id = 'Accounts'.$this->custFieldName;
67 $this->custField->name = $this->custFieldName;
68 $this->custField->type = 'varchar';
69 $this->custField->label = 'LBL_' . strtoupper($this->custFieldName);
70 $this->custField->vname = 'LBL_' . strtoupper($this->custFieldName);
71 $this->custField->len = 255;
72 $this->custField->custom_module = 'Accounts';
73 $this->custField->required = 0;
74 $this->custField->default = 'goofy';
76 $this->acc = new Account();
77 $this->df = new DynamicField('Accounts');
78 $this->df->setup($this->acc);
80 $this->df->addFieldObject($this->custField);
81 $this->df->buildCache('Accounts');
82 $this->custField->save($this->df);
84 VardefManager::clearVardef();
85 VardefManager::refreshVardefs('Accounts', 'Account');
87 //Now create the meta files to make this a Calculated Field.
88 $fn = $this->custFieldName;
89 $extensionContent = <<<EOQ
91 \$dictionary['Account']['fields']['$fn']['duplicate_merge_dom_value']=0;
92 \$dictionary['Account']['fields']['$fn']['calculated']='true';
93 \$dictionary['Account']['fields']['$fn']['formula']='related(\$assigned_user_link,"name")';
94 \$dictionary['Account']['fields']['$fn']['enforced']='true';
95 \$dictionary['Account']['fields']['$fn']['dependency']='';
96 \$dictionary['Account']['fields']['$fn']['type']='varchar';
97 \$dictionary['Account']['fields']['$fn']['name']='$fn';
101 //create custom field file
102 $this->custFileDirPath = create_custom_directory($this->custFileDirPath);
103 $fileLoc = $this->custFileDirPath.'sugarfield_'.$this->custFieldName.'.php';
104 file_put_contents($fileLoc, $extensionContent);
106 //run repair and clear to make sure the meta gets picked up
107 $_REQUEST['repair_silent']=1;
108 $rc = new RepairAndClear();
109 $rc->repairAndClearAll(array("clearAll", "rebuildExtensions"), array("Accounts"), false, false);
110 $fn = $this->custFieldName;
113 public function testMergeWithCalculatedField()
115 //recreate expected request and post superglobals for savemerge.php
116 $_REQUEST = $_POST = array(
117 'module' => 'MergeRecords',
118 'record' => $this->acc->id,
119 'merge_module' => 'Accounts',
120 'action' => 'SaveMerge',
121 'return_module' => 'Accounts',
122 'return_action' => 'index',
123 'change_parent' => 0,
125 'merged_links' => 'assigned_user_link,member_of',
126 'merged_ids' => array
129 'button' => 'Save Merge',
130 'name' => 'SugarAccount1091847479',
131 'date_entered' => '04/08/2013 03:18pm',
132 'date_modified' => '04/08/2013 03:18pm',
133 'team_name' => 'team_name',
134 'team_name_field' => 'team_name_table',
135 'team_name_collection_0' => 'Global',
136 'id_team_name_collection_0' => 1,
137 'primary_team_name_collection' => 0,
140 //call SaveMerge so the account beans can be merged
141 require_once('modules/MergeRecords/SaveMerge.php');
143 //make sure fatal error is not being output
144 $this->expectOutputNotRegex('/fatal/i', 'Failure message is appearing during merge');