]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug41985Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / service / Bug41985Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37  
38 require_once 'modules/DynamicFields/FieldCases.php';
39 require_once 'service/v4/SugarWebServiceImplv4.php';
40
41 class Bug41985Test extends Sugar_PHPUnit_Framework_TestCase
42 {
43     protected $_contact;
44     protected $_account;
45
46     public function setUp()
47     {
48         $beanList = array();
49         $beanFiles = array();
50         require('include/modules.php');
51         $GLOBALS['beanList'] = $beanList;
52         $GLOBALS['beanFiles'] = $beanFiles;
53
54         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
55         $GLOBALS['current_user']->status = 'Active';
56         $GLOBALS['current_user']->is_admin = 1;
57         $GLOBALS['current_user']->save();
58
59         $this->field = get_widget('varchar');
60         $this->field->id = 'Accountstest_custom_c';
61         $this->field->name = 'test_custom_c';
62         $this->field->vanme = 'LBL_TEST_CUSTOM_C';
63         $this->field->comments = NULL;
64         $this->field->help = NULL;
65         $this->field->custom_module = 'Accounts';
66         $this->field->type = 'varchar';
67         $this->field->label = 'LBL_TEST_CUSTOM_C';
68         $this->field->len = 255;
69         $this->field->required = 0;
70         $this->field->default_value = NULL;
71         $this->field->date_modified = '2009-09-14 02:23:23';
72         $this->field->deleted = 0;
73         $this->field->audited = 0;
74         $this->field->massupdate = 0;
75         $this->field->duplicate_merge = 0;
76         $this->field->reportable = 1;
77         $this->field->importable = 'true';
78         $this->field->ext1 = NULL;
79         $this->field->ext2 = NULL;
80         $this->field->ext3 = NULL;
81         $this->field->ext4 = NULL;
82
83         $this->df = new DynamicField('Accounts');
84         $this->mod = new Account();
85         $this->df->setup($this->mod);
86         $this->df->addFieldObject($this->field);
87         $this->df->buildCache('Accounts');
88         VardefManager::clearVardef();
89         VardefManager::refreshVardefs('Accounts', 'Account');
90         $this->mod->field_defs = $GLOBALS['dictionary']['Account']['fields'];
91
92         $this->_contact = SugarTestContactUtilities::createContact();
93         $this->_account = SugarTestAccountUtilities::createAccount();
94
95         $this->_contact->load_relationship('accounts');
96         $this->_contact->accounts->add($this->_account->id);
97
98         $this->_account->test_custom_c = 'Custom Field';
99         $this->_account->save();
100
101         $GLOBALS['db']->commit(); // Making sure we commit any changes
102     }
103
104     public function tearDown()
105     {
106         $this->df->deleteField($this->field);
107
108         $account_ids = SugarTestAccountUtilities::getCreatedAccountIds();
109         $contact_ids = SugarTestContactUtilities::getCreatedContactIds();
110         $GLOBALS['db']->query('DELETE FROM accounts_contacts WHERE contact_id IN (\'' . implode("', '", $contact_ids) . '\') OR  account_id IN (\'' . implode("', '", $account_ids) . '\')');
111
112         SugarTestContactUtilities::removeAllCreatedContacts();
113         SugarTestAccountUtilities::removeAllCreatedAccounts();
114
115         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
116         unset($GLOBALS['current_user']);
117
118         unset($GLOBALS['beanFiles']);
119         unset($GLOBALS['beanList']);
120     }
121
122     public function testGetRelationshipsWithCustomFields()
123     {
124         $web_service_util = new SugarWebServiceUtilv4();
125
126         $result = $web_service_util->getRelationshipResults($this->_contact, 'accounts', array('id', 'name', 'test_custom_c'));
127
128         $this->assertTrue(isset($result['rows'][0]));
129         $this->assertTrue(isset($result['rows'][0]['test_custom_c']));
130         $this->assertEquals($result['rows'][0]['test_custom_c'], 'Custom Field');
131     }
132 }