]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/ListView/Bug49385Test.php
Release 6.4.1
[Github/sugarcrm.git] / tests / include / ListView / Bug49385Test.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 require_once('data/SugarBean.php');
40
41 /**
42  * Bug49385Test.php
43  *
44  * This test handles verifying that the SQL string or array returned from the create_new_list_query call can properly
45  * processing the alter_many_to_many_query flag in SugarBean.
46  *
47  * @author Collin Lee
48  *
49  */
50 class Bug49385Test extends Sugar_PHPUnit_Framework_OutputTestCase
51 {
52
53     static $call_id = null;
54     static $meeting_id = null;
55     static $contact_id = null;
56
57     static public function setUpBeforeClass()
58     {
59         global $current_user;
60         $current_user = SugarTestUserUtilities::createAnonymousUser();
61
62         global $beanList, $beanFiles;
63         require('include/modules.php');
64
65         $GLOBALS['db']->query("DELETE FROM meetings WHERE name = 'Bug49385Test'");
66         $GLOBALS['db']->query("DELETE FROM calls WHERE name = 'Bug49385Test'");
67
68         $contact1 = SugarTestContactUtilities::createContact();
69         Bug49385Test::$contact_id = $contact1->id;
70
71         $contact2 = SugarTestContactUtilities::createContact();
72         $contact3 = SugarTestContactUtilities::createContact();
73
74         $meeting = SugarTestMeetingUtilities::createMeeting();
75         Bug49385Test::$meeting_id = $meeting->id;
76         $meeting->name = 'Bug49385Test';
77         $meeting->save();
78
79         $data_values = array('accept_status'=>'none');
80
81         $relate_values = array('contact_id'=>$contact1->id,'meeting_id'=>$meeting->id);
82         $meeting->set_relationship($meeting->rel_contacts_table, $relate_values, true, true, $data_values);
83
84         $relate_values = array('contact_id'=>$contact2->id,'meeting_id'=>$meeting->id);
85         $meeting->set_relationship($meeting->rel_contacts_table, $relate_values, true, true, $data_values);
86
87         $relate_values = array('contact_id'=>$contact3->id,'meeting_id'=>$meeting->id);
88         $meeting->set_relationship($meeting->rel_contacts_table, $relate_values, true, true, $data_values);
89
90         $call = SugarTestCallUtilities::createCall();
91         Bug49385Test::$call_id = $call->id;
92         $call->name = 'Bug49385Test';
93         $call->save();
94
95         $relate_values = array('contact_id'=>$contact1->id,'call_id'=>$call->id);
96         $call->set_relationship($call->rel_contacts_table, $relate_values, true, true, $data_values);
97
98         $relate_values = array('contact_id'=>$contact2->id,'call_id'=>$call->id);
99         $call->set_relationship($call->rel_contacts_table, $relate_values, true, true, $data_values);
100
101         $relate_values = array('contact_id'=>$contact3->id,'call_id'=>$call->id);
102         $call->set_relationship($call->rel_contacts_table, $relate_values, true, true, $data_values);
103
104     }
105
106     static public function tearDownAfterClass()
107     {
108         SugarTestContactUtilities::removeAllCreatedContacts();
109         SugarTestMeetingUtilities::removeAllCreatedMeetings();
110         SugarTestCallUtilities::removeAllCreatedCalls();
111         $GLOBALS['db']->query("DELETE FROM meetings_contacts WHERE meeting_id = '" . Bug49385Test::$meeting_id . "'");
112         $GLOBALS['db']->query("DELETE FROM calls_contacts WHERE call_id = '" . Bug49385Test::$call_id . "'");
113         unset($GLOBALS['current_user']);
114     }
115
116
117     /**
118      * testMeetingsController
119      *
120      * This tests the controller code added to make sure we get contacts displayed for the popup window
121      */
122     public function testMeetingsController()
123     {
124         require_once('modules/Meetings/controller.php');
125         $controller = new MeetingsController();
126         $_REQUEST['bean_id'] = Bug49385Test::$meeting_id;
127         $_REQUEST['related_id'] = Bug49385Test::$contact_id;
128         $controller->action_DisplayInline();
129         $this->expectOutputRegex('/SugarContact/');
130     }
131
132
133     /**
134      * testCallsController
135      *
136      * This tests the controller code to make sure we get contacts displayed for the popup window
137      */
138     public function testCallsController()
139     {
140         require_once('modules/Calls/controller.php');
141         $controller = new CallsController();
142         $_REQUEST['bean_id'] = Bug49385Test::$call_id;
143         $_REQUEST['related_id'] = Bug49385Test::$contact_id;
144         $controller->action_DisplayInline();
145         $this->expectOutputRegex('/SugarContact/');
146     }
147
148
149     /**
150      * testMeetingsCreateNewListQuery
151      *
152      * This tests the create_new_list_query function of Meetings module
153      */
154     public function testMeetingsCreateNewListQuery()
155     {
156         $meeting = new Meeting();
157         $order_by = 'name ASC';
158         $where = "(meetings.name like 'Bug49385Test%')";
159         $filter = array
160         (
161             'set_complete' => 1,
162             'status' => 1,
163             'join_meeting' => 1,
164             'join_url' => 1,
165             'host_url' => 1,
166             'name' => 1,
167             'contact_name' => 1,
168             'first_name' => 1,
169             'last_name' => 1,
170             'parent_name' => 1,
171             'parent_id' => 1,
172             'parent_type' => 1,
173             'date_start' => 1,
174             'time_start' => 1,
175             'assigned_user_name' => 1,
176             'date_entered' => 1,
177             'favorites_only' => 1
178         );
179
180         $params = array(
181             'massupdate' => 1,
182             'favorties' => 1
183         );
184
185         $ret_array = $meeting->create_new_list_query($order_by, $where, $filter, $params, 0, '', true, $meeting);
186         $ret_array['inner_join'] = '';
187         if (!empty($meeting->listview_inner_join)) {
188             $ret_array['inner_join'] = ' ' . implode(' ', $meeting->listview_inner_join) . ' ';
189         }
190         $sql =  $ret_array['select'] . $ret_array['from'] . $ret_array['inner_join'] . $ret_array['where'] . $ret_array['order_by'];
191         $sql = $ret_array['select'] . $ret_array['from'] . $ret_array['where'] . $ret_array['order_by'];
192
193         $result = $GLOBALS['db']->query($sql);
194         $count = 0;
195         while($row = $GLOBALS['db']->fetchByAssoc($result))
196         {
197             $count++;
198         }
199
200         $this->assertEquals(1, $count, 'Assert that the query returned 1 rows');
201
202         $params = array(
203             'massupdate' => 1,
204             'favorties' => 1,
205             'collection_list' => array()
206         );
207
208         $meeting = new Meeting();
209         $ret_array = $meeting->create_new_list_query($order_by, $where, $filter, $params, 0, '', true, $meeting);
210         $ret_array['inner_join'] = '';
211         if (!empty($meeting->listview_inner_join)) {
212             $ret_array['inner_join'] = ' ' . implode(' ', $meeting->listview_inner_join) . ' ';
213         }
214         $sql =  $ret_array['select'] . $ret_array['from'] . $ret_array['inner_join'] . $ret_array['where'] . $ret_array['order_by'];
215
216         $result = $GLOBALS['db']->query($sql);
217         $count = 0;
218         while($row = $GLOBALS['db']->fetchByAssoc($result))
219         {
220             $count++;
221         }
222
223         $this->assertEquals(3, $count, 'Assert that the query returned 3 rows');
224     }
225
226
227     /**
228       * testCallsCreateNewListQuery
229      *
230       * This tests the create_new_list_query function of Calls module
231       */
232      public function testCallsCreateNewListQuery()
233      {
234          $call = new Call();
235          $order_by = 'name ASC';
236          $where = "(calls.name like 'Bug49385Test%')";
237          $filter = array
238          (
239              'set_complete' => 1,
240              'status' => 1,
241              'join_call' => 1,
242              'join_url' => 1,
243              'host_url' => 1,
244              'name' => 1,
245              'contact_name' => 1,
246              'first_name' => 1,
247              'last_name' => 1,
248              'parent_name' => 1,
249              'parent_id' => 1,
250              'parent_type' => 1,
251              'date_start' => 1,
252              'time_start' => 1,
253              'assigned_user_name' => 1,
254              'date_entered' => 1,
255              'favorites_only' => 1
256          );
257
258          $params = array(
259              'massupdate' => 1,
260              'favorties' => 1
261          );
262
263          $ret_array = $call->create_new_list_query($order_by, $where, $filter, $params, 0, '', true, $call);
264          $ret_array['inner_join'] = '';
265          if (!empty($call->listview_inner_join)) {
266              $ret_array['inner_join'] = ' ' . implode(' ', $call->listview_inner_join) . ' ';
267          }
268          $sql =  $ret_array['select'] . $ret_array['from'] . $ret_array['inner_join'] . $ret_array['where'] . $ret_array['order_by'];
269
270          $result = $GLOBALS['db']->query($sql);
271          $count = 0;
272          while($row = $GLOBALS['db']->fetchByAssoc($result))
273          {
274              $count++;
275          }
276
277          $this->assertEquals(1, $count, 'Assert that the query returned 1 row');
278
279          $params = array(
280              'massupdate' => 1,
281              'favorties' => 1,
282              'collection_list' => array()
283          );
284
285          $call = new Call();
286          $ret_array = $call->create_new_list_query($order_by, $where, $filter, $params, 0, '', true, $call);
287          $ret_array['inner_join'] = '';
288          if (!empty($call->listview_inner_join)) {
289              $ret_array['inner_join'] = ' ' . implode(' ', $call->listview_inner_join) . ' ';
290          }
291          $sql =  $ret_array['select'] . $ret_array['from'] . $ret_array['inner_join'] . $ret_array['where'] . $ret_array['order_by'];
292
293          $result = $GLOBALS['db']->query($sql);
294          $count = 0;
295          while($row = $GLOBALS['db']->fetchByAssoc($result))
296          {
297              $count++;
298          }
299
300          $this->assertEquals(3, $count, 'Assert that the query returned 3 rows');
301      }
302
303
304 }
305
306 class Bug49385SugarBeanMock extends SugarBean
307 {
308     public function create_many_to_many_query($ret_array=array())
309     {
310         return parent::create_many_to_many_query($ret_array);
311     }
312 }
313
314 ?>