]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug43196Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / service / Bug43196Test.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('include/nusoap/nusoap.php');
39
40 /**
41  * @group bug43196
42  */
43 class Bug43196Test extends Sugar_PHPUnit_Framework_TestCase
44 {
45         public $_soapClient = null;
46         
47         public function setUp() 
48     {
49         $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,600,600);
50         
51         $beanList = array();
52         $beanFiles = array();
53         require('include/modules.php');
54         $GLOBALS['beanList'] = $beanList;
55         $GLOBALS['beanFiles'] = $beanFiles;
56         
57         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
58         $GLOBALS['current_user']->status = 'Active';
59         $GLOBALS['current_user']->is_admin = 1;
60         $GLOBALS['current_user']->save();
61     }
62
63     public function tearDown() 
64     {
65         foreach ( SugarTestContactUtilities::getCreatedContactIds() as $id ) {
66             $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id = '{$id}'");
67         }
68         SugarTestContactUtilities::removeAllCreatedContacts();
69         SugarTestAccountUtilities::removeAllCreatedAccounts();
70         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
71         unset($GLOBALS['current_user']);
72         
73         unset($GLOBALS['beanList']);
74         unset($GLOBALS['beanFiles']);
75     }   
76     
77     public function testGetEntryWhenContactHasMultipleAccountRelationshipsWorks() 
78     {
79         $contact = SugarTestContactUtilities::createContact();
80         $account1 = SugarTestAccountUtilities::createAccount();
81         $account2 = SugarTestAccountUtilities::createAccount();
82         
83         $contact->load_relationship('accounts');
84         $contact->accounts->add($account1->id);
85         $contact->accounts->add($account2->id);
86         
87         $this->_login();
88         
89         $parameters = array(
90             'session' => $this->_sessionId,
91             'module_name' => 'Contacts',
92             'query' => "contacts.id = '{$contact->id}'",
93             'order_by' => '',
94             'offset' => 0,
95             'select_fields' => array('id', 'account_id', 'account_name'),
96             'max_results' => 250,
97             'deleted' => 0,
98             );
99             
100         $result = $this->_soapClient->call('get_entry_list',$parameters);
101         
102         $account_names = array($account1->name, $account2->name);
103         $account_ids = array($account1->id, $account2->id);
104         /*
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);
109         */
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));
114     }
115     
116     /**
117      * Attempt to login to the soap server
118      *
119      * @return $set_entry_result - this should contain an id and error.  The id corresponds
120      * to the session_id.
121      */
122     public function _login()
123     {
124                 global $current_user;   
125         
126         $GLOBALS['db']->commit(); // Making sure we commit any changes before logging in
127                 $result = $this->_soapClient->call(
128                     'login',
129             array('user_auth' => 
130                 array('user_name' => $current_user->user_name,
131                     'password' => $current_user->user_hash, 
132                     'version' => '.01'), 
133                 'application_name' => 'SoapTest')
134             );
135         $this->_sessionId = $result['id'];
136                 
137         return $result;
138     }
139 }