]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/data/Bug56423Test.php
Release 6.5.15
[Github/sugarcrm.git] / tests / data / Bug56423Test.php
1 <?php
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
7  *
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.
11  *
12  * Copyright (C) 2004-2013 SugarCRM Inc.  All rights reserved.
13  ********************************************************************************/
14
15
16 require_once 'modules/DynamicFields/FieldCases.php';
17
18 /**
19  * Bug #56423
20  * @ticket 56423
21  */
22 class Bug56423Test extends Sugar_PHPUnit_Framework_TestCase
23 {
24     /**
25      * @var TemplateRelatedTextField
26      */
27     protected $accountFieldWidget;
28     /**
29      * @var DynamicField
30      */
31     protected $accountField;
32     /**
33      * @var TemplateRelatedTextField
34      */
35     protected $opportunityFieldWidget;
36     /**
37      * @var DynamicField
38      */
39     protected $opportunityField;
40
41     public function setUp()
42     {
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));
49
50         $_POST = $_REQUEST = $this->getPostData();
51
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);
61
62         $_POST['view_module'] = $_REQUEST['view_module'] = 'Opportunities';
63
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);
73
74         $repair = new RepairAndClear();
75         $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs'),
76                                    array($GLOBALS['beanList']['Accounts'], $GLOBALS['beanList']['Opportunities']),
77                                    true,
78                                    false);
79     }
80
81     public function getPostData()
82     {
83         return array (
84             'module' => 'ModuleBuilder',
85             'action' => 'saveField',
86             'new_dropdown' => '',
87             'to_pdf' => 'true',
88             'view_module' => 'Accounts',
89             'is_update' => 'true',
90             'type' => 'relate',
91             'name' => 'contact',
92             'labelValue' => 'contact',
93             'label' => 'LBL_CONTACT',
94             'help' => '',
95             'comments' => '',
96             'ext2' => 'Contacts',
97             'ext3' => '',
98             'dependency' => '',
99             'dependency_display' => '',
100             'reportableCheckbox' => '1',
101             'reportable' => '1',
102             'importable' => 'true',
103             'duplicate_merge' => '0',
104         );
105     } 
106
107     public function tearDown()
108     {
109         if ($this->accountFieldWidget)
110         {
111             $this->accountFieldWidget->delete($this->accountField);
112         }
113         if ($this->opportunityFieldWidget)
114         {
115             $this->opportunityFieldWidget->delete($this->opportunityField);
116         }
117
118         $repair = new RepairAndClear();
119         $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs'),
120                                    array($GLOBALS['beanList']['Accounts'], $GLOBALS['beanList']['Opportunities']),
121                                    true,
122                                    false);
123
124         $_REQUEST = $_POST = array();
125         SugarTestHelper::tearDown();
126     }
127
128     /**
129      * Tests that 'create_new_list_query' creates query without duplicating
130      * $vardef[id_name] column in select statement.
131      */
132     public function testListQuery()
133     {
134         $bean = BeanFactory::getBean('Accounts');
135         $query = $bean->create_new_list_query(
136             "accounts.name",
137             "(accounts.name like 'A%')",
138             array(),
139             array(),
140             0,
141             "",
142             true,
143             NULL,
144             false
145         );
146         $this->assertEquals(1, substr_count($query['select'], 'accounts_cstm.contact_id_c'));
147     } 
148
149 }