2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once 'include/nusoap/nusoap.php';
39 require_once 'modules/DynamicFields/FieldCases.php';
43 * Web Service get_relationships doesn't work with related_module_query parameter when using custom fields
45 * @author mgusev@sugarcrm.com
48 class Bug58138Test extends Sugar_PHPUnit_Framework_TestCase
53 protected $soap = null;
58 protected $dynamicField = null;
63 protected $field = null;
68 protected $module = null;
73 protected $account = null;
78 protected $contact = null;
81 * Creating new field, account, contact with filled custom field, relationship between them
83 public function setUp()
85 SugarTestHelper::setUp('beanList');
86 SugarTestHelper::setUp('beanFiles');
87 SugarTestHelper::setUp('current_user', array(true, true));
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';
96 $this->field->label = '';
98 $this->module = new Contact();
100 $this->dynamicField = new DynamicField('Contacts');
102 $this->dynamicField->setup($this->module);
103 $this->dynamicField->addFieldObject($this->field);
105 SugarTestHelper::setUp('dictionary');
106 $GLOBALS['reload_vardefs'] = true;
108 $this->account = SugarTestAccountUtilities::createAccount();
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();
117 $GLOBALS['db']->commit();
121 * Removing field, account, contact
123 public function tearDown()
125 SugarTestContactUtilities::removeAllCreatedContacts();
126 SugarTestAccountUtilities::removeAllCreatedAccounts();
128 $this->dynamicField->deleteField($this->field);
130 SugarTestHelper::tearDown();
134 * Test asserts that contact can be found by custom field
138 public function testSoap()
140 $soap_url = $GLOBALS['sugar_config']['site_url'] . '/soap.php';
141 $this->soap = new nusoapclient($soap_url);
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,
149 'application_name' => 'SoapTest'
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' ",
162 $this->assertInternalType('array', $actual, 'Incorrect response');
164 if (empty($actual['ids']))
166 $this->fail('Data is not present');
169 $actual = reset($actual['ids']);
170 $this->assertEquals($this->contact->id, $actual['id'], 'Contact is incorrect');
173 public static function dataProvider()
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')
186 * Test asserts that contact can be found by custom field
189 * @dataProvider dataProvider
191 public function testSoapVersions($url)
193 $soap_url = $GLOBALS['sugar_config']['site_url'] . $url;
194 $this->soap = new nusoapclient($soap_url);
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,
202 'application_name' => 'SoapTest'
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'),
216 $this->assertInternalType('array', $actual, 'Incorrect response');
218 if (empty($actual['entry_list']))
220 $this->fail('Data is not present');
223 $actual = reset($actual['entry_list']);
224 $this->assertEquals($this->contact->id, $actual['id'], 'Contact is incorrect');