]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug39234Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / service / Bug39234Test.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 /**
42  * @group bug39234
43  */
44 class Bug39234Test extends Sugar_PHPUnit_Framework_TestCase
45 {
46         public $_user = null;
47         public $_soapClient = null;
48         public $_session = null;
49         public $_sessionId = '';
50     public $_contactId = '';
51     var $c1 = null;
52     var $c2 = null;
53         var $a1 = null;
54         
55     /**
56      * Create test user
57      *
58      */
59         public function setUp() 
60     {
61         $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,600,600);
62         $this->_setupTestUser();
63         
64                 $beanList = array();
65                 $beanFiles = array();
66                 require('include/modules.php');
67                 $GLOBALS['beanList'] = $beanList;
68                 $GLOBALS['beanFiles'] = $beanFiles;
69         
70         $unid = uniqid();
71                 $time = date('Y-m-d H:i:s');
72
73                 $contact = new Contact();
74                 $contact->id = 'c_'.$unid;
75         $contact->first_name = 'testfirst';
76         $contact->last_name = 'testlast';
77         $contact->email1 = 'fred@rogers.com';
78         $contact->new_with_id = true;
79         $contact->disable_custom_fields = true;
80         $contact->save();
81                 $this->c1 = $contact;
82                 
83                 $account = new Account();
84                 $account->id = 'a_'.$unid;
85         $account->name = 'acctfirst';
86         $account->assigned_user_id = 'SugarUser';
87         $account->new_with_id = true;
88         $account->disable_custom_fields = true;
89         $account->save();
90         $this->a1 = $account;
91         
92        $this->c1->load_relationship('accounts');
93        $this->c1->accounts->add($this->a1->id);
94        
95        $contact2 = new Contact();
96                 $contact2->id = 'c2_'.$unid;
97        $contact2->first_name = 'testfirst';
98         $contact2->last_name = 'testlast';
99         $contact2->email1 = 'fred@rogers.com';
100         $contact2->new_with_id = true;
101         $contact2->disable_custom_fields = true;
102         $contact2->save();
103                 $this->c2 = $contact2;
104     }
105
106     /**
107      * Remove anything that was used during this test
108      *
109      */
110     public function tearDown() {
111         global $soap_version_test_accountId, $soap_version_test_opportunityId, $soap_version_test_contactId;
112         $this->_tearDownTestUser();
113         $this->_user = null;
114         $this->_sessionId = '';
115         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->c1->id}'");
116         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->c2->id}'");
117         $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->c1->id}'");
118         $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->c2->id}'");
119         $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$this->a1->id}'");
120         $GLOBALS['db']->query("DELETE FROM accounts WHERE name = 'joe pizza'");
121         unset($this->c1);
122         unset($this->c2);
123         unset($this->a1);
124         unset($soap_version_test_accountId);
125         unset($soap_version_test_opportunityId);
126         unset($soap_version_test_contactId);
127
128                 unset($GLOBALS['beanList']);
129                 unset($GLOBALS['beanFiles']);
130     }   
131     
132     public function testSetEntries() {
133         $this->_login();
134                 $result = $this->_soapClient->call('set_entries',array('session'=>$this->_sessionId,'module_name' => 'Contacts','name_value_lists' => array(array(array('name'=>'last_name' , 'value'=>$this->c1->last_name), array('name'=>'email1' , 'value'=>$this->c1->email1), array('name'=>'first_name' , 'value'=>$this->c1->first_name), array('name'=>'account_name' , 'value'=>$this->a1->name)))));
135                 $this->assertTrue(isset($result['ids']));
136                 $this->assertEquals($result['ids'][0],$this->c1->id);
137     } // fn
138     
139      public function testSetEntries2() {
140         $this->_login();
141                 $result = $this->_soapClient->call('set_entries',array('session'=>$this->_sessionId,'module_name' => 'Contacts','name_value_lists' => array(array(array('name'=>'last_name' , 'value'=>$this->c2->last_name), array('name'=>'email1' , 'value'=>$this->c2->email1), array('name'=>'first_name' , 'value'=>$this->c2->first_name), array('name'=>'account_name' , 'value'=>'joe pizza')))));
142                 $this->assertTrue(isset($result['ids']));
143                 $this->assertNotEquals($result['ids'][0],$this->c1->id);
144     } // fn
145     
146         /**********************************
147      * HELPER PUBLIC FUNCTIONS
148      **********************************/
149     
150     /**
151      * Attempt to login to the soap server
152      *
153      * @return $set_entry_result - this should contain an id and error.  The id corresponds
154      * to the session_id.
155      */
156     public function _login(){
157                 global $current_user;   
158         $GLOBALS['db']->commit(); // Making sure we commit any changes before logging in
159         $result = $this->_soapClient->call('login',
160             array('user_auth' => 
161                 array('user_name' => $current_user->user_name,
162                     'password' => $current_user->user_hash, 
163                     'version' => '.01'), 
164                 'application_name' => 'SoapTest')
165             );
166         $this->_sessionId = $result['id'];
167                 return $result;
168     }
169     
170  /**
171      * Create a test user
172      *
173      */
174         public function _setupTestUser() {
175         $this->_user = SugarTestUserUtilities::createAnonymousUser();
176         $this->_user->status = 'Active';
177         $this->_user->is_admin = 1;
178         $this->_user->save();
179         $GLOBALS['current_user'] = $this->_user;
180     }
181         
182     /**
183      * Remove user created for test
184      *
185      */
186         public function _tearDownTestUser() {
187        SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
188        unset($GLOBALS['current_user']);
189     }
190         
191 }
192 ?>