]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug50780Test.php
Release 6.4.1
[Github/sugarcrm.git] / tests / service / Bug50780Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 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 /**
39  * Bug50780 - Due to the recent security fixes for the web services, subqueries on tables no longer work as expected.
40  * This has presented a problem to some of our partner's since they were relying on the subqueries to return
41  * relationship information on records. We could resolve this by adding back more tables to the allowed list of tables
42  * to be queried in a subquery, but this has been voted against from most of the engineering staff. Another approach
43  * would be to add enhancements to our API to allow for querying limited result sets for relationship data. Adding
44  * offset and limit support to the get_relationships call is one such approach.
45  */
46
47 require_once('include/nusoap/nusoap.php');
48 require_once 'tests/service/SOAPTestCase.php';
49
50 class Bug50780Test extends SOAPTestCase
51 {
52     public function setUp()
53     {
54         $this->_soapURL = $GLOBALS['sugar_config']['site_url'] . '/service/v4_1/soap.php';
55         parent::setUp();
56         $this->_login(); // Logging in just before the SOAP call as this will also commit any pending DB changes
57
58
59         for ($x = 0; $x < 4; $x++) {
60             $mid = SugarTestMeetingUtilities::createMeeting();
61             SugarTestMeetingUtilities::addMeetingUserRelation($mid->id, self::$_user->id);
62         }
63
64         $GLOBALS['db']->commit();
65     }
66
67     public function tearDown()
68     {
69         SugarTestMeetingUtilities::removeAllCreatedMeetings();
70         SugarTestMeetingUtilities::removeMeetingUsers();
71
72         parent::tearDown();
73     }
74
75     public function testGetRelationshipReturnAllMeetings()
76     {
77         $result = $this->_soapClient->call('get_relationships', array(
78                 'session' => $this->_sessionId,
79                 'module_name' => 'Users',
80                 'module_id' => self::$_user->id,
81                 'link_field_name' => 'meetings',
82                 'related_module_query' => '',
83                 'related_fields' => array('id', 'name'),
84                 'related_module_link_name_to_fields_array' => '',
85                 'deleted' => 0,
86                 'order_by' => 'date_entered',
87                 'offset' => 0,
88                 'limit' => false)
89         );
90
91         $this->assertEquals(4, count($result['entry_list']));
92     }
93
94     public function testGetRelationshipReturnNothingWithOffsetSetHigh()
95     {
96         $result = $this->_soapClient->call('get_relationships', array(
97                 'session' => $this->_sessionId,
98                 'module_name' => 'Users',
99                 'module_id' => self::$_user->id,
100                 'link_field_name' => 'meetings',
101                 'related_module_query' => '',
102                 'related_fields' => array('id', 'name'),
103                 'related_module_link_name_to_fields_array' => '',
104                 'deleted' => 0,
105                 'order_by' => 'date_entered',
106                 'offset' => 5,
107                 'limit' => false)
108         );
109
110         $this->assertEquals(0, count($result['entry_list']));
111     }
112
113     public function testGetRelationshipReturnThirdMeeting()
114     {
115         $result = $this->_soapClient->call('get_relationships', array(
116                 'session' => $this->_sessionId,
117                 'module_name' => 'Users',
118                 'module_id' => self::$_user->id,
119                 'link_field_name' => 'meetings',
120                 'related_module_query' => '',
121                 'related_fields' => array('id', 'name'),
122                 'related_module_link_name_to_fields_array' => '',
123                 'deleted' => 0,
124                 'order_by' => 'date_entered',
125                 'offset' => 2,
126                 'limit' => 1)
127         );
128
129         $this->assertEquals(1, count($result['entry_list']));
130     }
131
132     public function testGetRelationshipOffsetDoesntReturnSameRecords()
133     {
134         $result1 = $this->_soapClient->call('get_relationships', array(
135                 'session' => $this->_sessionId,
136                 'module_name' => 'Users',
137                 'module_id' => self::$_user->id,
138                 'link_field_name' => 'meetings',
139                 'related_module_query' => '',
140                 'related_fields' => array('id', 'name', 'date_entered'),
141                 'related_module_link_name_to_fields_array' => '',
142                 'deleted' => 0,
143                 'order_by' => 'date_entered',
144                 'offset' => 0,
145                 'limit' => 2)
146         );
147
148         $this->assertEquals(2, count($result1['entry_list']));
149
150         $result2 = $this->_soapClient->call('get_relationships', array(
151                 'session' => $this->_sessionId,
152                 'module_name' => 'Users',
153                 'module_id' => self::$_user->id,
154                 'link_field_name' => 'meetings',
155                 'related_module_query' => '',
156                 'related_fields' => array('id', 'name', 'date_entered'),
157                 'related_module_link_name_to_fields_array' => '',
158                 'deleted' => 0,
159                 'order_by' => 'date_entered',
160                 'offset' => 2,
161                 'limit' => 2)
162         );
163
164         $this->assertEquals(2, count($result2['entry_list']));
165     }
166 }