2 require_once('include/nusoap/nusoap.php');
4 * This class is meant to test everything SOAP
7 class SOAPAPI1Test extends Sugar_PHPUnit_Framework_TestCase
10 public $_contact = null;
11 public $_meeting = null;
12 public $_soapClient = null;
13 public $_session = null;
14 public $_userUtils = null;
15 public $_sessionId = '';
21 public function setUp()
23 $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,60,60);
24 $this->_setupTestUser();
25 $this->_setupTestContact();
26 $this->_meeting = SugarTestMeetingUtilities::createMeeting();
30 * Remove anything that was used during this test
33 public function tearDown()
35 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
37 SugarTestContactUtilities::removeAllCreatedContacts();
38 SugarTestContactUtilities::removeCreatedContactsUsersRelationships();
39 $this->_contact = null;
40 SugarTestMeetingUtilities::removeAllCreatedMeetings();
41 SugarTestMeetingUtilities::removeMeetingContacts();
42 $this->_meeting = null;
46 * Ensure we can create a session on the server.
49 public function testCanLogin()
51 $result = $this->_login();
52 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,
53 'SOAP Session not created. Error ('.$result['error']['number'].'): '.$result['error']['name'].': '.$result['error']['description'].'. HTTP Response: '.$this->_soapClient->response);
56 public function testSearchContactByEmail()
58 $result = $this->_soapClient->call('contact_by_email', array('user_name' => $this->_user->user_name, 'password' => $this->_user->user_hash, 'email_address' => $this->_contact->email1));
59 $this->assertTrue(!empty($result) && count($result) > 0, 'Incorrect number of results returned. HTTP Response: '.$this->_soapClient->response);
60 $this->assertEquals($result[0]['name1'], $this->_contact->first_name, 'Incorrect result found');
63 public function testSearchByModule()
65 $modules = array('Contacts');
66 $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));
67 $this->assertTrue(!empty($result) && count($result['entry_list']) > 0, 'Incorrect number of results returned. HTTP Response: '.$this->_soapClient->response);
68 $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');
71 public function testSearchBy()
73 $this->markTestSkipped('SOAP call "search" is deprecated');
75 $result = $this->_soapClient->call('search', array('user_name' => $this->_user->user_name, 'password' => $this->_user->user_hash, 'name' => $this->_contact->first_name));
76 $this->assertTrue(!empty($result) && count($result) > 0, "Incorrect number of results returned - Returned $result results. HTTP Response: ".$this->_soapClient->response);
77 $this->assertEquals($result[0]['name1'], $this->_contact->first_name, "Contact First name does not match data returnd from SOAP_test");
80 public function testGetModifiedEntries()
83 $ids = array($this->_contact->id);
84 $result = $this->_soapClient->call('get_modified_entries', array('session' => $this->_sessionId, 'module_name' => 'Contacts', 'ids' => $ids, 'select_fields' => array()));
85 $decoded = base64_decode($result['result']);
88 public function testGetAttendeeList()
91 $this->_meeting->load_relationship('contacts');
92 $this->_meeting->contacts->add($this->_contact->id);
93 $result = $this->_soapClient->call('get_attendee_list', array('session' => $this->_sessionId, 'module_name' => 'Meetings', 'id' => $this->_meeting->id));
94 $decoded = base64_decode($result['result']);
95 $decoded = simplexml_load_string($decoded);
96 $this->assertTrue(!empty($result['result']), 'Results not returned. HTTP Response: '.$this->_soapClient->response);
97 $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));
100 public function testSyncGetModifiedRelationships()
103 $ids = array($this->_contact->id);
104 $yesterday = date('Y-m-d', strtotime('last year'));
105 $tomorrow = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") + 1, date("Y")));
106 $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));
107 $this->assertTrue(!empty($result['entry_list']), 'Results not returned. HTTP Response: '.$this->_soapClient->response);
108 $decoded = base64_decode($result['entry_list']);
109 $decoded = simplexml_load_string($decoded);
110 if (isset($decoded->item[0]) ) {
111 $this->assertEquals(urlencode($decoded->item->name_value_list->name_value[1]->name), 'contact_id', "testSyncGetModifiedRelationships - could not retrieve contact_id column name");
112 $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");
116 /**********************************
117 * HELPER PUBLIC FUNCTIONS
118 **********************************/
121 * Attempt to login to the soap server
123 * @return $set_entry_result - this should contain an id and error. The id corresponds
126 private function _login(){
127 $result = $this->_soapClient->call('login',
129 array('user_name' => $this->_user->user_name,
130 'password' => $this->_user->user_hash,
132 'application_name' => 'SoapTest')
134 $this->_sessionId = $result['id'];
142 private function _setupTestUser() {
143 $this->_user = SugarTestUserUtilities::createAnonymousUser();
144 $this->_user->status = 'Active';
145 $this->_user->is_admin = 1;
146 $this->_user->save();
147 $GLOBALS['current_user'] = $this->_user;
150 private function _setupTestContact() {
151 $this->_contact = SugarTestContactUtilities::createContact();
152 $this->_contact->contacts_users_id = $this->_user->id;
153 $this->_contact->save();