]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/soap/Bug58138Test.php
Release 6.5.9
[Github/sugarcrm.git] / tests / soap / Bug58138Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 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 'include/nusoap/nusoap.php';
39 require_once 'modules/DynamicFields/FieldCases.php';
40
41 /**
42  * Bug #58138
43  * Web Service get_relationships doesn't work with related_module_query parameter when using custom fields
44  *
45  * @author mgusev@sugarcrm.com
46  * @ticked 58138
47  */
48 class Bug58138Test extends Sugar_PHPUnit_Framework_TestCase
49 {
50     /**
51      * @var nusoapclient
52      */
53     protected $soap = null;
54
55     /**
56      * @var DynamicField
57      */
58     protected $dynamicField = null;
59
60     /**
61      * @var TemplateText
62      */
63     protected $field = null;
64
65     /**
66      * @var Contact
67      */
68     protected $module = null;
69
70     /**
71      * @var Account
72      */
73     protected $account = null;
74
75     /**
76      * @var Contact
77      */
78     protected $contact = null;
79
80     /**
81      * Creating new field, account, contact with filled custom field, relationship between them
82      */
83     public function setUp()
84     {
85         SugarTestHelper::setUp('beanList');
86         SugarTestHelper::setUp('beanFiles');
87         SugarTestHelper::setUp('current_user', array(true, true));
88
89         $this->field = get_widget('varchar');
90         $this->field->id = 'Contactstest_c';
91         $this->field->name = 'test_c';
92         $this->field->type = 'varchar';
93         $this->field->len = 255;
94         $this->field->importable = 'true';
95
96         $this->field->label = '';
97
98         $this->module = new Contact();
99
100         $this->dynamicField = new DynamicField('Contacts');
101
102         $this->dynamicField->setup($this->module);
103         $this->dynamicField->addFieldObject($this->field);
104
105         SugarTestHelper::setUp('dictionary');
106         $GLOBALS['reload_vardefs'] = true;
107
108         $this->account = SugarTestAccountUtilities::createAccount();
109
110         $this->contact = SugarTestContactUtilities::createContact();
111         $this->contact->account_id = $this->account->id;
112         $this->contact->test_c = 'test value';
113         $this->contact->load_relationship('accounts');
114         $this->contact->accounts->add($this->account->id);
115         $this->contact->save();
116
117         $GLOBALS['db']->commit();
118     }
119
120     /**
121      * Removing field, account, contact
122      */
123     public function tearDown()
124     {
125         SugarTestContactUtilities::removeAllCreatedContacts();
126         SugarTestAccountUtilities::removeAllCreatedAccounts();
127
128         $this->dynamicField->deleteField($this->field);
129
130         SugarTestHelper::tearDown();
131     }
132
133     /**
134      * Test asserts that contact can be found by custom field
135      *
136      * @group 58138
137      */
138     public function testSoap()
139     {
140         $soap_url = $GLOBALS['sugar_config']['site_url'] . '/soap.php';
141         $this->soap = new nusoapclient($soap_url);
142
143         $result = $this->soap->call('login', array(
144                 'user_auth' => array(
145                     'user_name' => $GLOBALS['current_user']->user_name,
146                     'password' => $GLOBALS['current_user']->user_hash,
147                     'version' => '.01'
148                 ),
149                 'application_name' => 'SoapTest'
150             )
151         );
152
153         $actual = $this->soap->call('get_relationships', array(
154             'session' => $result['id'],
155             'module_name' => 'Accounts',
156             'module_id' => $this->account->id,
157             'link_field_name' => 'Contacts',
158             'related_module_query' => "contacts_cstm.test_c = 'test value' ",
159             'deleted' => '1',
160         ));
161
162         $this->assertInternalType('array', $actual, 'Incorrect response');
163
164         if (empty($actual['ids']))
165         {
166             $this->fail('Data is not present');
167         }
168
169         $actual = reset($actual['ids']);
170         $this->assertEquals($this->contact->id, $actual['id'], 'Contact is incorrect');
171     }
172
173     public static function dataProvider()
174     {
175         return array(
176             array('/service/v2/soap.php'),
177             array('/service/v2_1/soap.php'),
178             array('/service/v3/soap.php'),
179             array('/service/v3_1/soap.php'),
180             array('/service/v4/soap.php'),
181             array('/service/v4_1/soap.php')
182         );
183     }
184
185     /**
186      * Test asserts that contact can be found by custom field
187      *
188      * @group 58138
189      * @dataProvider dataProvider
190      */
191     public function testSoapVersions($url)
192     {
193         $soap_url = $GLOBALS['sugar_config']['site_url'] . $url;
194         $this->soap = new nusoapclient($soap_url);
195
196         $result = $this->soap->call('login', array(
197             'user_auth' => array(
198                 'user_name' => $GLOBALS['current_user']->user_name,
199                 'password' => $GLOBALS['current_user']->user_hash,
200                 'version' => '.01'
201             ),
202             'application_name' => 'SoapTest'
203             )
204         );
205
206         $actual = $this->soap->call('get_relationships', array(
207             'session' => $result['id'],
208             'module_name' => 'Accounts',
209             'module_id' => $this->account->id,
210             'link_field_name' => 'contacts',
211             'related_module_query' => "contacts_cstm.test_c = 'test value' ",
212             'link_module_fields' => array('id'),
213             'deleted' => '1',
214         ));
215
216         $this->assertInternalType('array', $actual, 'Incorrect response');
217
218         if (empty($actual['entry_list']))
219         {
220             $this->fail('Data is not present');
221         }
222
223         $actual = reset($actual['entry_list']);
224         $this->assertEquals($this->contact->id, $actual['id'], 'Contact is incorrect');
225     }
226 }