]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/SOAPAPI1Test.php
Release 6.4.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         $this->_login(); // Logging in just before the SOAP call as this will also commit any pending DB changes
59                 $this->_setupTestContact();
60         $this->_meeting = SugarTestMeetingUtilities::createMeeting();
61     }
62
63     /**
64      * Remove anything that was used during this test
65      *
66      */
67     public function tearDown()
68     {
69         SugarTestContactUtilities::removeCreatedContactsUsersRelationships();
70         $this->_contact = null;
71         SugarTestMeetingUtilities::removeAllCreatedMeetings();
72         SugarTestMeetingUtilities::removeMeetingContacts();
73         $this->_meeting = null;
74         parent::tearDown();
75     }
76
77         /**
78          * Ensure we can create a session on the server.
79          *
80          */
81     public function testCanLogin()
82     {
83                 $result = $this->_login();
84         $this->assertTrue(!empty($result['id']) && $result['id'] != -1,
85             'SOAP Session not created. Error ('.$result['error']['number'].'): '.$result['error']['name'].': '.$result['error']['description'].'. HTTP Response: '.$this->_soapClient->response);
86     }
87
88     public function testSearchContactByEmail()
89     {
90         $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));
91         $this->assertTrue(!empty($result) && count($result) > 0, 'Incorrect number of results returned. HTTP Response: '.$this->_soapClient->response);
92         $this->assertEquals($result[0]['name1'], $this->_contact->first_name, 'Incorrect result found');
93     }
94
95         public function testSearchByModule()
96     {
97                 $modules = array('Contacts');
98         $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));
99         $this->assertTrue(!empty($result) && count($result['entry_list']) > 0, 'Incorrect number of results returned. HTTP Response: '.$this->_soapClient->response);
100         $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');
101     }
102
103         public function testSearchBy()
104     {
105         $this->markTestSkipped('SOAP call "search" is deprecated');
106
107                 $result = $this->_soapClient->call('search', array('user_name' => $GLOBALS['current_user']->user_name, 'password' => $GLOBALS['current_user']->user_hash, 'name' => $this->_contact->first_name));
108         $this->assertTrue(!empty($result) && count($result) > 0, "Incorrect number of results returned - Returned $result results. HTTP Response: ".$this->_soapClient->response);
109         $this->assertEquals($result[0]['name1'], $this->_contact->first_name, "Contact First name does not match data returnd from SOAP_test");
110     }
111
112         public function testGetModifiedEntries()
113     {
114                 $ids = array($this->_contact->id);
115         $result = $this->_soapClient->call('get_modified_entries', array('session' => $this->_sessionId, 'module_name' => 'Contacts', 'ids' => $ids, 'select_fields' => array()));
116         $decoded = base64_decode($result['result']);
117     }
118
119         public function testGetAttendeeList()
120     {
121         $this->_meeting->load_relationship('contacts');
122         $this->_meeting->contacts->add($this->_contact->id);
123         $GLOBALS['db']->commit();
124                 $result = $this->_soapClient->call('get_attendee_list', array('session' => $this->_sessionId, 'module_name' => 'Meetings', 'id' => $this->_meeting->id));
125         $decoded = base64_decode($result['result']);
126         $decoded = simplexml_load_string($decoded);
127         $this->assertTrue(!empty($result['result']), 'Results not returned. HTTP Response: '.$this->_soapClient->response);
128                 $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));
129         }
130
131     public function testSyncGetModifiedRelationships()
132     {
133         $ids = array($this->_contact->id);
134         $yesterday = date('Y-m-d', strtotime('last year'));
135         $tomorrow = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") + 1, date("Y")));
136         $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));
137         $this->assertTrue(!empty($result['entry_list']), 'Results not returned. HTTP Response: '.$this->_soapClient->response);
138         $decoded = base64_decode($result['entry_list']);
139         $decoded = simplexml_load_string($decoded);
140         if (isset($decoded->item[0]) ) {
141             $this->assertEquals(urlencode($decoded->item->name_value_list->name_value[1]->name), 'contact_id', "testSyncGetModifiedRelationships - could not retrieve contact_id column name");
142             $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");
143         }
144     }
145
146     /**********************************
147      * HELPER PUBLIC FUNCTIONS
148      **********************************/
149         private function _setupTestContact() {
150         $this->_contact = SugarTestContactUtilities::createContact();
151         $this->_contact->contacts_users_id = $GLOBALS['current_user']->id;
152         $this->_contact->save();
153         $GLOBALS['db']->commit(); // Making sure these changes are committed to the database
154     }
155
156 }