2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 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');
43 class Bug43196Test extends Sugar_PHPUnit_Framework_TestCase
45 public $_soapClient = null;
47 public function setUp()
49 $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,600,600);
53 require('include/modules.php');
54 $GLOBALS['beanList'] = $beanList;
55 $GLOBALS['beanFiles'] = $beanFiles;
57 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
58 $GLOBALS['current_user']->status = 'Active';
59 $GLOBALS['current_user']->is_admin = 1;
60 $GLOBALS['current_user']->save();
63 public function tearDown()
65 foreach ( SugarTestContactUtilities::getCreatedContactIds() as $id ) {
66 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id = '{$id}'");
68 SugarTestContactUtilities::removeAllCreatedContacts();
69 SugarTestAccountUtilities::removeAllCreatedAccounts();
70 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
71 unset($GLOBALS['current_user']);
73 unset($GLOBALS['beanList']);
74 unset($GLOBALS['beanFiles']);
77 public function testGetEntryWhenContactHasMultipleAccountRelationshipsWorks()
79 $contact = SugarTestContactUtilities::createContact();
80 $account1 = SugarTestAccountUtilities::createAccount();
81 $account2 = SugarTestAccountUtilities::createAccount();
83 $contact->load_relationship('accounts');
84 $contact->accounts->add($account1->id);
85 $contact->accounts->add($account2->id);
90 'session' => $this->_sessionId,
91 'module_name' => 'Contacts',
92 'query' => "contacts.id = '{$contact->id}'",
95 'select_fields' => array('id', 'account_id', 'account_name'),
100 $result = $this->_soapClient->call('get_entry_list',$parameters);
102 $account_names = array($account1->name, $account2->name);
103 $account_ids = array($account1->id, $account2->id);
105 $this->assertEquals($result['entry_list'][0]['name_value_list'][1]['value'],$account1->name);
106 $this->assertEquals($result['entry_list'][0]['name_value_list'][2]['value'],$account1->id);
107 $this->assertEquals($result['entry_list'][1]['name_value_list'][1]['value'],$account2->name);
108 $this->assertEquals($result['entry_list'][1]['name_value_list'][2]['value'],$account2->id);
110 $this->assertTrue(in_array($result['entry_list'][0]['name_value_list'][1]['value'], $account_names));
111 $this->assertTrue(in_array($result['entry_list'][1]['name_value_list'][1]['value'], $account_names));
112 $this->assertTrue(in_array($result['entry_list'][0]['name_value_list'][2]['value'], $account_ids));
113 $this->assertTrue(in_array($result['entry_list'][1]['name_value_list'][2]['value'], $account_ids));
117 * Attempt to login to the soap server
119 * @return $set_entry_result - this should contain an id and error. The id corresponds
122 public function _login()
124 global $current_user;
126 $GLOBALS['db']->commit(); // Making sure we commit any changes before logging in
127 $result = $this->_soapClient->call(
130 array('user_name' => $current_user->user_name,
131 'password' => $current_user->user_hash,
133 'application_name' => 'SoapTest')
135 $this->_sessionId = $result['id'];