2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 'tests/service/SOAPTestCase.php';
40 * This class is meant to test everything SOAP
43 class SOAPAPI1Test extends SOAPTestCase
45 public $_contact = null;
46 public $_meeting = null;
47 public $_userUtils = null;
48 public $_sessionId = '';
54 public function setUp()
56 $this->_soapURL = $GLOBALS['sugar_config']['site_url'].'/soap.php';
60 require('include/modules.php');
61 $GLOBALS['beanList'] = $beanList;
62 $GLOBALS['beanFiles'] = $beanFiles;
63 $this->_setupTestContact();
64 $this->_meeting = SugarTestMeetingUtilities::createMeeting();
68 * Remove anything that was used during this test
71 public function 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']);
86 * Ensure we can create a session on the server.
89 public function testCanLogin()
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);
96 public function testSearchContactByEmail()
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');
103 public function testSearchByModule()
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');
111 public function testSearchBy()
113 $this->markTestSkipped('SOAP call "search" is deprecated');
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");
120 public function testGetModifiedEntries()
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']);
128 public function testGetAttendeeList()
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));
140 public function testSyncGetModifiedRelationships()
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");
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();