]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/SOAPAPI1Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / service / SOAPAPI1Test.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 'tests/service/SOAPTestCase.php';
39 /**
40  * This class is meant to test everything SOAP
41  *
42  */
43 class SOAPAPI1Test extends SOAPTestCase
44 {
45         public $_contact = null;
46         public $_meeting = null;
47         public $_userUtils = null;
48         public $_sessionId = '';
49
50     /**
51      * Create test user
52      *
53      */
54         public function setUp()
55     {
56         $this->_soapURL = $GLOBALS['sugar_config']['site_url'].'/soap.php';
57                 parent::setUp();
58                 $beanList = array();
59                 $beanFiles = array();
60                 require('include/modules.php');
61                 $GLOBALS['beanList'] = $beanList;
62                 $GLOBALS['beanFiles'] = $beanFiles;
63         $this->_setupTestContact();
64         $this->_meeting = SugarTestMeetingUtilities::createMeeting();
65     }
66
67     /**
68      * Remove anything that was used during this test
69      *
70      */
71     public function tearDown()
72     {
73         parent::tearDown();
74         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
75         SugarTestContactUtilities::removeAllCreatedContacts();
76         SugarTestContactUtilities::removeCreatedContactsUsersRelationships();
77         $this->_contact = null;
78         SugarTestMeetingUtilities::removeAllCreatedMeetings();
79          SugarTestMeetingUtilities::removeMeetingContacts();
80         $this->_meeting = null;
81                 unset($GLOBALS['beanList']);
82                 unset($GLOBALS['beanFiles']);
83     }
84
85         /**
86          * Ensure we can create a session on the server.
87          *
88          */
89     public function testCanLogin()
90     {
91                 $result = $this->_login();
92         $this->assertTrue(!empty($result['id']) && $result['id'] != -1,
93             'SOAP Session not created. Error ('.$result['error']['number'].'): '.$result['error']['name'].': '.$result['error']['description'].'. HTTP Response: '.$this->_soapClient->response);
94     }
95
96     public function testSearchContactByEmail()
97     {
98         $result = $this->_soapClient->call('contact_by_email', array('user_name' => $this->_user->user_name, 'password' => $this->_user->user_hash, 'email_address' => $this->_contact->email1));
99         $this->assertTrue(!empty($result) && count($result) > 0, 'Incorrect number of results returned. HTTP Response: '.$this->_soapClient->response);
100         $this->assertEquals($result[0]['name1'], $this->_contact->first_name, 'Incorrect result found');
101     }
102
103         public function testSearchByModule()
104     {
105                 $modules = array('Contacts');
106         $result = $this->_soapClient->call('search_by_module', array('user_name' => $this->_user->user_name, 'password' => $this->_user->user_hash, 'search_string' => $this->_contact->email1, 'modules' => $modules, 'offset' => 0, 'max_results' => 10));
107         $this->assertTrue(!empty($result) && count($result['entry_list']) > 0, 'Incorrect number of results returned. HTTP Response: '.$this->_soapClient->response);
108         $this->assertEquals($result['entry_list'][0]['name_value_list'][1]['name'], 'first_name' && $result['entry_list'][0]['name_value_list'][1]['value'] == $this->_contact->first_name, 'Incorrect result returned');
109     }
110
111         public function testSearchBy()
112     {
113         $this->markTestSkipped('SOAP call "search" is deprecated');
114
115                 $result = $this->_soapClient->call('search', array('user_name' => $this->_user->user_name, 'password' => $this->_user->user_hash, 'name' => $this->_contact->first_name));
116         $this->assertTrue(!empty($result) && count($result) > 0, "Incorrect number of results returned - Returned $result results. HTTP Response: ".$this->_soapClient->response);
117         $this->assertEquals($result[0]['name1'], $this->_contact->first_name, "Contact First name does not match data returnd from SOAP_test");
118     }
119
120         public function testGetModifiedEntries()
121     {
122                 $this->_login();
123                 $ids = array($this->_contact->id);
124         $result = $this->_soapClient->call('get_modified_entries', array('session' => $this->_sessionId, 'module_name' => 'Contacts', 'ids' => $ids, 'select_fields' => array()));
125         $decoded = base64_decode($result['result']);
126     }
127
128         public function testGetAttendeeList()
129     {
130         $this->_login();
131         $this->_meeting->load_relationship('contacts');
132         $this->_meeting->contacts->add($this->_contact->id);
133                 $result = $this->_soapClient->call('get_attendee_list', array('session' => $this->_sessionId, 'module_name' => 'Meetings', 'id' => $this->_meeting->id));
134         $decoded = base64_decode($result['result']);
135         $decoded = simplexml_load_string($decoded);
136         $this->assertTrue(!empty($result['result']), 'Results not returned. HTTP Response: '.$this->_soapClient->response);
137                 $this->assertEquals(urldecode($decoded->attendee->first_name), $this->_contact->first_name, 'Incorrect Result returned expected: '.$this->_contact->first_name.' Found: '.urldecode($decoded->attendee->first_name));
138         }
139
140     public function testSyncGetModifiedRelationships()
141     {
142         $this->_login();
143         $ids = array($this->_contact->id);
144         $yesterday = date('Y-m-d', strtotime('last year'));
145         $tomorrow = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") + 1, date("Y")));
146         $result = $this->_soapClient->call('sync_get_modified_relationships', array('session' => $this->_sessionId, 'module_name' => 'Users', 'related_module' => 'Contacts', 'from_date' => $yesterday, 'to_date' => $tomorrow, 'offset' => 0, 'max_results' => 10, 'deleted' => 0, 'module_id' => $this->_user->id, 'select_fields'=> array(), 'ids' => $ids, 'relationship_name' => 'contacts_users', 'deletion_date' => $yesterday, 'php_serialize' => 0));
147         $this->assertTrue(!empty($result['entry_list']), 'Results not returned. HTTP Response: '.$this->_soapClient->response);
148         $decoded = base64_decode($result['entry_list']);
149         $decoded = simplexml_load_string($decoded);
150         if (isset($decoded->item[0]) ) {
151             $this->assertEquals(urlencode($decoded->item->name_value_list->name_value[1]->name), 'contact_id', "testSyncGetModifiedRelationships - could not retrieve contact_id column name");
152             $this->assertEquals(urlencode($decoded->item->name_value_list->name_value[1]->value), $this->_contact->id, "vlue of contact id is not same as returned via SOAP");
153         }
154     }
155
156     /**********************************
157      * HELPER PUBLIC FUNCTIONS
158      **********************************/
159         private function _setupTestContact() {
160         $this->_contact = SugarTestContactUtilities::createContact();
161         $this->_contact->contacts_users_id = $this->_user->id;
162         $this->_contact->save();
163     }
164
165 }