]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Expressions/Expression/Generic/Bug61734Test.php
Release 6.5.14
[Github/sugarcrm.git] / tests / include / Expressions / Expression / Generic / Bug61734Test.php
1 <?php
2
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
8  *
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.
12  *
13  * Copyright (C) 2004-2013 SugarCRM Inc.  All rights reserved.
14  ********************************************************************************/
15
16
17 require_once('data/SugarBean.php');
18 require_once("modules/Administration/QuickRepairAndRebuild.php");
19 require_once('modules/DynamicFields/FieldCases.php');
20
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
24 {
25     public $acc;
26     public $acc2;
27     public $custFileDirPath = 'Extension/modules/Accounts/Ext/Vardefs/';
28     public $custFieldName = 'cf_61734_c';
29     public $custField;
30     public $df;
31
32
33     public function setUp()
34     {
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');
41         parent::setUp();
42         $this->createCustom();
43
44         $this->acc = SugarTestAccountUtilities::createAccount();
45         $this->acc2 = SugarTestAccountUtilities::createAccount();
46
47
48     }
49
50         public function tearDown()
51         {
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;
60         $o = new Account();
61         $GLOBALS['reload_vardefs'] = false;
62         }
63
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';
76
77         $this->acc = new Account();
78         $this->df = new DynamicField('Accounts');
79         $this->df->setup($this->acc);
80
81         $this->df->addFieldObject($this->custField);
82         $this->df->buildCache('Accounts');
83         $this->custField->save($this->df);
84
85         VardefManager::clearVardef();
86         VardefManager::refreshVardefs('Accounts', 'Account');
87
88         //Now create the meta files to make this a Calculated Field.
89         $fn = $this->custFieldName;
90         $extensionContent = <<<EOQ
91 <?php
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';
99
100
101 EOQ;
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);
106
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;
112     }
113
114     public function testMergeWithCalculatedField()
115     {
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,
125             'remove' => 0,
126             'merged_links' => 'assigned_user_link,member_of',
127             'merged_ids' => array
128                 ($this->acc2->id),
129
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,
139             'noRedirect' => 1,
140         );
141         //call SaveMerge so the account beans can be merged
142         require_once('modules/MergeRecords/SaveMerge.php');
143
144         //make sure fatal error is not being output
145         $this->expectOutputNotRegex('/fatal/i', 'Failure message is appearing during merge');
146
147
148     }
149 }