2 /*********************************************************************************
3 * By installing or using this file, you are confirming on behalf of the entity
4 * subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
5 * the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
6 * http://www.sugarcrm.com/master-subscription-agreement
8 * If Company is not bound by the MSA, then by installing or using this file
9 * you are agreeing unconditionally that Company will be bound by the MSA and
10 * certifying that you have authority to bind Company accordingly.
12 * Copyright (C) 2004-2013 SugarCRM Inc. All rights reserved.
13 ********************************************************************************/
16 require_once 'modules/DynamicFields/FieldCases.php';
22 class Bug56423Test extends Sugar_PHPUnit_Framework_TestCase
25 * @var TemplateRelatedTextField
27 protected $accountFieldWidget;
31 protected $accountField;
33 * @var TemplateRelatedTextField
35 protected $opportunityFieldWidget;
39 protected $opportunityField;
41 public function setUp()
43 SugarTestHelper::setUp('beanList');
44 SugarTestHelper::setUp('beanFiles');
45 SugarTestHelper::setUp('app_strings');
46 SugarTestHelper::setUp('app_list_strings');
47 SugarTestHelper::setUp('mod_strings', array('ModuleBuilder'));
48 SugarTestHelper::setUp('current_user', array(true, 1));
50 $_POST = $_REQUEST = $this->getPostData();
52 $this->accountFieldWidget = get_widget($_REQUEST['type']);
53 $this->accountFieldWidget->populateFromPost();
54 $module = $_REQUEST['view_module'];
55 $this->accountField = new DynamicField($module);
56 $class_name = $GLOBALS['beanList'][$module];
57 require_once ($GLOBALS['beanFiles'][$class_name]);
58 $mod = new $class_name();
59 $this->accountField->setup($mod);
60 $this->accountFieldWidget->save($this->accountField);
62 $_POST['view_module'] = $_REQUEST['view_module'] = 'Opportunities';
64 $this->opportunityFieldWidget = get_widget($_REQUEST['type']);
65 $this->opportunityFieldWidget->populateFromPost();
66 $module = $_REQUEST['view_module'];
67 $this->opportunityField = new DynamicField($module);
68 $class_name = $GLOBALS['beanList'][$module];
69 require_once ($GLOBALS['beanFiles'][$class_name]);
70 $mod = new $class_name();
71 $this->opportunityField->setup($mod);
72 $this->opportunityFieldWidget->save($this->opportunityField);
74 $repair = new RepairAndClear();
75 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs'),
76 array($GLOBALS['beanList']['Accounts'], $GLOBALS['beanList']['Opportunities']),
81 public function getPostData()
84 'module' => 'ModuleBuilder',
85 'action' => 'saveField',
88 'view_module' => 'Accounts',
89 'is_update' => 'true',
92 'labelValue' => 'contact',
93 'label' => 'LBL_CONTACT',
99 'dependency_display' => '',
100 'reportableCheckbox' => '1',
102 'importable' => 'true',
103 'duplicate_merge' => '0',
107 public function tearDown()
109 if ($this->accountFieldWidget)
111 $this->accountFieldWidget->delete($this->accountField);
113 if ($this->opportunityFieldWidget)
115 $this->opportunityFieldWidget->delete($this->opportunityField);
118 $repair = new RepairAndClear();
119 $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs'),
120 array($GLOBALS['beanList']['Accounts'], $GLOBALS['beanList']['Opportunities']),
124 $_REQUEST = $_POST = array();
125 SugarTestHelper::tearDown();
129 * Tests that 'create_new_list_query' creates query without duplicating
130 * $vardef[id_name] column in select statement.
132 public function testListQuery()
134 $bean = BeanFactory::getBean('Accounts');
135 $query = $bean->create_new_list_query(
137 "(accounts.name like 'A%')",
146 $this->assertEquals(1, substr_count($query['select'], 'accounts_cstm.contact_id_c'));