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 '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';
58 $this->_login(); // Logging in just before the SOAP call as this will also commit any pending DB changes
59 $this->_contact = SugarTestContactUtilities::createContact();
60 $this->_contact->contacts_users_id = $GLOBALS['current_user']->id;
61 $this->_contact->save();
62 $this->_meeting = SugarTestMeetingUtilities::createMeeting();
63 $GLOBALS['db']->commit(); // Making sure these changes are committed to the database
67 * Remove anything that was used during this test
70 public function tearDown()
72 SugarTestContactUtilities::removeAllCreatedContacts();
73 SugarTestContactUtilities::removeCreatedContactsUsersRelationships();
74 SugarTestMeetingUtilities::removeAllCreatedMeetings();
75 SugarTestMeetingUtilities::removeMeetingContacts();
76 $this->_meeting = null;
77 $this->_contact = null;
82 * Ensure we can create a session on the server.
86 public function testCanLogin()
88 $result = $this->_login();
89 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,
90 'SOAP Session not created. Error ('.$result['error']['number'].'): '.$result['error']['name'].': '.$result['error']['description'].'. HTTP Response: '.$this->_soapClient->response);
93 public function testSearchContactByEmail()
95 $result = $this->_soapClient->call('contact_by_email', array('user_name' => $GLOBALS['current_user']->user_name, 'password' => $GLOBALS['current_user']->user_hash, 'email_address' => $this->_contact->email1));
96 $this->assertTrue(!empty($result) && count($result) > 0, 'Incorrect number of results returned. HTTP Response: '.$this->_soapClient->response);
97 $this->assertEquals($result[0]['name1'], $this->_contact->first_name, 'Incorrect result found');
100 public function testSearchByModule()
102 $modules = array('Contacts');
103 $result = $this->_soapClient->call('search_by_module', array('user_name' => $GLOBALS['current_user']->user_name, 'password' => $GLOBALS['current_user']->user_hash, 'search_string' => $this->_contact->email1, 'modules' => $modules, 'offset' => 0, 'max_results' => 10));
104 $this->assertTrue(!empty($result) && count($result['entry_list']) > 0, 'Incorrect number of results returned. HTTP Response: '.$this->_soapClient->response);
105 $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');
108 public function testSearchBy()
110 $this->markTestIncomplete('SOAP call "search" is deprecated');
112 $result = $this->_soapClient->call('search', array('user_name' => $GLOBALS['current_user']->user_name, 'password' => $GLOBALS['current_user']->user_hash, 'name' => $this->_contact->first_name));
113 $this->assertTrue(!empty($result) && count($result) > 0, "Incorrect number of results returned - Returned $result results. HTTP Response: ".$this->_soapClient->response);
114 $this->assertEquals($result[0]['name1'], $this->_contact->first_name, "Contact First name does not match data returnd from SOAP_test");
117 public function testGetModifiedEntries()
119 $ids = array($this->_contact->id);
120 $result = $this->_soapClient->call('get_modified_entries', array('session' => $this->_sessionId, 'module_name' => 'Contacts', 'ids' => $ids, 'select_fields' => array()));
121 $decoded = base64_decode($result['result']);
125 public function testGetEntryList()
127 $result = $this->_soapClient->call('get_entry_list', array('session'=>$this->_sessionId,'module_name'=>'Contacts','query'=>" contacts.id = '{$this->_contact->id}' AND contacts.last_name = '{$this->_contact->last_name}' ", 'last_name', '0', 'select_field'=>array('last_name'),10000,0));
129 foreach($result['entry_list'][0]['name_value_list'] as $entry)
131 if($entry['name'] == 'last_name')
133 $last_name = $entry['value'];
137 $this->assertEquals($this->_contact->last_name, $last_name);
141 public function testGetAttendeeList()
143 $this->_meeting->load_relationship('contacts');
144 $this->_meeting->contacts->add($this->_contact->id);
145 $GLOBALS['db']->commit();
146 $result = $this->_soapClient->call('get_attendee_list', array('session' => $this->_sessionId, 'module_name' => 'Meetings', 'id' => $this->_meeting->id));
147 $decoded = base64_decode($result['result']);
148 $decoded = simplexml_load_string($decoded);
149 $this->assertTrue(!empty($result['result']), 'Results not returned. HTTP Response: '.$this->_soapClient->response);
150 $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));
153 public function testSyncGetModifiedRelationships()
155 $ids = array($this->_contact->id);
156 $yesterday = date('Y-m-d', strtotime('last year'));
157 $tomorrow = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") + 1, date("Y")));
158 $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' => $GLOBALS['current_user']->id, 'select_fields'=> array(), 'ids' => $ids, 'relationship_name' => 'contacts_users', 'deletion_date' => $yesterday, 'php_serialize' => 0));
159 $this->assertTrue(!empty($result['entry_list']), 'Results not returned. HTTP Response: '.$this->_soapClient->response);
160 $decoded = base64_decode($result['entry_list']);
161 $decoded = simplexml_load_string($decoded);
162 if (isset($decoded->item[0]) ) {
163 $this->assertEquals(urlencode($decoded->item->name_value_list->name_value[1]->name), 'contact_id', "testSyncGetModifiedRelationships - could not retrieve contact_id column name");
164 $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");